From c39b9e305610667b0006a20f83c514c1e9da3b24 Mon Sep 17 00:00:00 2001 From: Anton Bilous Date: Wed, 12 Feb 2025 22:54:29 +0200 Subject: [PATCH] improve img references --- template.typ | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/template.typ b/template.typ index c91b086..1359632 100644 --- a/template.typ +++ b/template.typ @@ -15,13 +15,27 @@ /// bold text #let bold(content) = text(weight: "bold")[#content] -/// captioned image with label derived from path +/// 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 #let img(path, caption) = [ + #let parts = path.split(".").first().split("/") + #figure( image(path), caption: caption, ) - #label(path.split("/").last().split(".").first()) + #label( + 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(" ", "_"), + ) ] /// subjects list