diff --git a/template/coursework.typ b/template/coursework.typ index bf678e6..6a445f2 100644 --- a/template/coursework.typ +++ b/template/coursework.typ @@ -1,7 +1,7 @@ #import "@local/nure:0.1.0": * #import style: spacing -// #import "utils.typ": * +#import "utils.typ": img #let authors = ( ( diff --git a/template/lab.typ b/template/lab.typ index 53f05e9..e45825d 100644 --- a/template/lab.typ +++ b/template/lab.typ @@ -1,5 +1,5 @@ #import "@local/nure:0.1.0": * -// #import "utils.typ": * +#import "utils.typ": img #import style: spacing diff --git a/template/utils.typ b/template/utils.typ new file mode 100644 index 0000000..4041d2a --- /dev/null +++ b/template/utils.typ @@ -0,0 +1,36 @@ +/// captioned image with label derived from path: +/// - "image.png" = @image +/// - "img/image.png" = @image +/// - "img/foo/image.png" = @foo_image +/// - "img/foo/foo_image.png" = @foo_image +/// the caption will be modified based on a conditional positional value: +/// - `none`: no change +/// - some value: "`caption` (за даними `value`)" +/// - no value: "`caption` (рисунок виконано самостійно)" +/// additional named arguments will be passed to original `image` function +#let img(path, caption, ..sink) = { + let parts = path.split(".").first().split("/") + + let label_string = if ( + parts.len() <= 2 or parts.at(-1).starts-with(parts.at(-2)) + ) { + // ("image",), (_, "image") and (.., "img", "img_image") + parts.last() + } else { + // (.., "img", "image") = "img_image" + parts.at(-2) + "_" + parts.at(-1) + }.replace(" ", "_") + + let caption = if sink.pos().len() == 0 { + caption + } else if sink.pos().first() == none { + caption + " (рисунок виконано самостійно)" + } else { + [#caption (за даними #sink.pos().first())] + } + + [#figure( + image(path, ..sink.named()), + caption: caption, + ) #label(label_string)] +}