From a04e64482218aab94848551b0da7b14806731da5 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 26 Aug 2025 16:46:01 +0300 Subject: [PATCH] feat: add attachments --- examples/qualification-thesis/main.typ | 19 ++++++++++++- src/lib.typ | 38 ++++++++++++++++++++------ src/utils.typ | 28 +++++++++++++++++++ 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/examples/qualification-thesis/main.typ b/examples/qualification-thesis/main.typ index d9a62bd..df60798 100644 --- a/examples/qualification-thesis/main.typ +++ b/examples/qualification-thesis/main.typ @@ -1,6 +1,6 @@ #import "@preview/fletcher:0.5.8" as fletcher: diagram, edge, node #import fletcher.shapes: cylinder, ellipse -#import "@preview/solo-lu-df:0.0.1": ludf +#import "@preview/solo-lu-df:0.0.1": * #import "utils/tables.typ": function-table #import "utils/diagrams.typ": data-store, dpd-database, dpd-edge, process @@ -67,6 +67,23 @@ ), ), ), + attachments: ( + attachment( + caption: "foo", + label: , + table( + columns: (1fr, 1fr), + [foo], [bar], + ), + ), + attachment( + caption: "bar", + table( + columns: (1fr, 1fr), + [foo], [bar], + ), + ), + ), ) diff --git a/src/lib.typ b/src/lib.typ index 3c1e990..60630ad 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -1,7 +1,17 @@ -#import "utils.typ": make-abstract, make-documentary-page, make-title +#import "utils.typ": ( + make-abstract, make-attachments, make-documentary-page, make-title, +) #let indent = 1cm +#let attachment(caption: none, label: none, body) = { + ( + content: body, + caption: caption, + label: label, + ) +} + // This function gets your whole document as its `body` and formats // it as an article in the style of the IEEE. #let ludf( @@ -36,8 +46,9 @@ date: datetime.today(), place: none, logo: none, - outline-title: "SATURS", - attachments: none, + outline-title: "Saturs", + attachments: (), + attachment-title: "Pielikumi", body, ) = { // Set document metadata. @@ -134,7 +145,7 @@ show figure.where(kind: table): set figure(supplement: "tabula") - show figure.where(kind: "attachment"): set figure(numbering: "1.1.") + show figure.where(kind: "attachment"): set figure(numbering: "1.") show figure.where(kind: "attachment"): set figure.caption(separator: ". ") @@ -153,6 +164,7 @@ fig } + // Custom show rule for references show ref: it => { let el = it.element @@ -198,7 +210,11 @@ let fig_num = counter(figure.where(kind: el.kind)) .at(el.location()) .first() - let numbers = numbering("1.1.", chap, fig_num) + let numbers = if el.kind == "attachment" { + numbering("1.", fig_num) + } else { + numbering("1.1.", chap, fig_num) + } let supplement = get-supplement(el.supplement) @@ -247,11 +263,14 @@ // Table of contents. // Uppercase 1st level headings in ToC - show outline.entry.where(level: 1): it => { - upper(it) - } + show outline.entry.where(level: 1): it => { upper(it) } - outline(depth: 3, indent: indent, title: text(size: 14pt, outline-title)) + outline( + depth: 3, + indent: indent, + title: text(size: 14pt, outline-title), + target: heading.where().or(figure.where(kind: "attachment")), + ) // Display the paper's contents. body @@ -259,6 +278,7 @@ // Display bibliography. bibliography + make-attachments(attachment-title, attachments) make-documentary-page( title, diff --git a/src/utils.typ b/src/utils.typ index bfe2a8c..6f27b74 100644 --- a/src/utils.typ +++ b/src/utils.typ @@ -157,3 +157,31 @@ v(vspace) } } + +#let make-attachments(title, attachments) = { + if attachments == () { + return + } + heading(level: 1, title, numbering: none) + + for (i, att) in attachments.enumerate() { + let content = att.content + let caption = att.caption + let user-label = att.label + + let final-label = if user-label != none { + user-label + } else { + label("attachment-" + str(i + 1)) + } + + [#figure( + content, + caption: caption, + kind: "attachment", + supplement: "pielikums", + ) + #final-label + ] + } +}