forked from pencelheimer/typst_nure_template
add img to utils.typ
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#import "@local/nure:0.1.0": *
|
#import "@local/nure:0.1.0": *
|
||||||
#import style: spacing
|
#import style: spacing
|
||||||
|
|
||||||
// #import "utils.typ": *
|
#import "utils.typ": img
|
||||||
|
|
||||||
#let authors = (
|
#let authors = (
|
||||||
(
|
(
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#import "@local/nure:0.1.0": *
|
#import "@local/nure:0.1.0": *
|
||||||
// #import "utils.typ": *
|
#import "utils.typ": img
|
||||||
|
|
||||||
#import style: spacing
|
#import style: spacing
|
||||||
|
|
||||||
|
|||||||
@@ -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)]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user