From ce96deba3e0b8e9e4183ff2f80fc988d2f68c045 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 19 Aug 2025 18:00:54 +0300 Subject: [PATCH] add attachments --- main.typ | 31 +++++++++++++++++++++++---- template.typ | 59 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 76 insertions(+), 14 deletions(-) diff --git a/main.typ b/main.typ index 4aea8fd..edebb47 100644 --- a/main.typ +++ b/main.typ @@ -108,8 +108,9 @@ They can span multiple lines. any rate, that what I do not know I do not think I know either. ] -== Links -Here is a #link("https://typst.app")[Typst website]. +== Links +Here is a https://typst.app and +here is a with a label -- #link("https://typst.app")[Typst website]. == Table Here’s a simple table: @@ -132,16 +133,38 @@ Here’s a simple table: caption: [An example image with caption.], ) <image-1> #figure( - image("example.png", width: 60%), + image("example.png"), caption: [An example image with caption.], ) <image-2> +- @image-1[] +- @image-2 +- @table-1 +- @table-1[tabulu] +- @title +- @code[pielikumu] + A reference to an image (see @image-1[] and @image-2 and @table-1) + == Footnotes This is a sentence with a footnote. #footnote("This is the footnote text.") == References -We can reference @typst in text. +// We can reference @typst in text. +#figure( + caption: "Some caption", + kind: "attachment", + supplement: "pielikums", + ```rust + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + #[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] + #[cfg_attr(feature = "bevy", derive(Component))] + #[cfg_attr(feature = "bevy", reflect(Component))] + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + pub struct Walls(u8); + ```, +)<code> + diff --git a/template.typ b/template.typ index 9fea1bb..79b2e0e 100644 --- a/template.typ +++ b/template.typ @@ -168,6 +168,8 @@ // Tables & figures set figure(numbering: dependent-numbering("1.1.")) + show figure: set figure.caption(position: top, separator: " ") + show figure.caption: set align(end) show figure.where(kind: image): set figure(supplement: "att") show figure.caption.where(kind: image): set align(start) @@ -178,31 +180,68 @@ show heading: reset-counter(counter(figure.where(kind: image))) show figure.where(kind: table): set figure(supplement: "tabula") - show figure.caption.where(kind: table): set align(end) - show figure.where(kind: table): set figure.caption( - position: top, - separator: " ", - ) show heading: reset-counter(counter(figure.where(kind: table))) - show figure.where(kind: raw): set figure.caption(position: top) - - show figure.where(kind: "attachment"): set figure.caption(position: top) + show figure.where(kind: "attachment"): set figure(numbering: "1.1.") + show figure.where(kind: "attachment"): set figure.caption(separator: ". ") // Adapt supplement in caption independently from supplement used for references. show figure: fig => { - let prefix = fig.supplement let numbers = numbering(fig.numbering, ..fig.counter.at(fig.location())) // Wrap figure captions in block to prevent the creation of paragraphs. In // particular, this means `par.first-line-indent` does not apply. // See https://github.com/typst/templates/pull/73#discussion_r2112947947. show figure.caption: it => block[ - #emph([#numbers~#prefix#it.separator])*#it.body* + #emph([#numbers~#fig.supplement#it.separator])*#it.body* + ] + show figure.caption.where(kind: "attachment"): it => block[ + #numbers~#fig.supplement#it.separator#it.body ] fig } + // disable default reference suppliments + set ref(supplement: it => {}) + + // Custom show rule for references + show ref: it => { + let el = it.element + if el == none { + return it + } + + + let numbers = numbering( + el.numbering, + ..counter(el.func()).at(el.location()), + ) + + if el.func() == heading { + return link( + el.location(), + [#numbers #el.body], + ) + } + + + let supplement = if type(it.supplement) == content { + if it.supplement == [] { + "" + } else { + [~#it.supplement] + } + } else { + [~#it.supplement] + } + + if el.func() == figure { + return link(el.location(), [#numbers#supplement]) + } + it + } + + // Code blocks show raw: set text( font: (