add source to img function

This commit is contained in:
2025-02-13 19:32:38 +02:00
parent eab40dfbfb
commit c9e56a75b1
3 changed files with 19 additions and 18 deletions

Binary file not shown.

Binary file not shown.

View File

@ -20,23 +20,23 @@
/// - `img/image.png` = @image /// - `img/image.png` = @image
/// - `img/foo/image.png` = @foo_image /// - `img/foo/image.png` = @foo_image
/// - `img/foo/foo_image.png` = @foo_image /// - `img/foo/foo_image.png` = @foo_image
#let img(path, caption) = [ /// if source is specified, it will be appended to the caption as " (за даними `source`)"
#let parts = path.split(".").first().split("/") /// otherwise " (рисунок виконано самостійно)" will be appended to the caption
#let img(path, caption, source: none) = {
let parts = path.split(".").first().split("/")
#figure( let label_string = if parts.len() <= 2 or parts.at(-1).starts-with(parts.at(-2)) {
image(path),
caption: caption,
)
#label(
if parts.len() <= 2 or parts.at(-1).starts-with(parts.at(-2)) {
// ("image",), (_, "image") and (.., "img", "img_image") // ("image",), (_, "image") and (.., "img", "img_image")
parts.last() parts.last()
} else { } else {
// (.., "img", "image") = "img_image" // (.., "img", "image") = "img_image"
parts.at(-2) + "_" + parts.at(-1) parts.at(-2) + "_" + parts.at(-1)
}.replace(" ", "_"), }.replace(" ", "_")
)
] caption = [#caption #if source != none [(за даними #source)] else [(рисунок виконано самостійно)]]
[#figure(image(path), caption: caption) #label(label_string)]
}
/// subjects list /// subjects list
#let subjects = ( #let subjects = (
@ -451,8 +451,9 @@
#context [ #context [
#let pages = counter(page).final().at(0) #let pages = counter(page).final().at(0)
#let tables = counter("table").final().at(0) #let tables = counter(figure.where(kind: table)).final().at(0)
#let images = counter("image").final().at(0) // alternative: query(figure.where(kind: image)).len()
#let images = counter(figure.where(kind: image)).final().at(0)
#let bibs = bib-count.final().dedup().len() #let bibs = bib-count.final().dedup().len()
#let counters = () #let counters = ()