From e0811afaaea9cad5a4d73051bcdf84068ab585d6 Mon Sep 17 00:00:00 2001 From: Anton Bilous Date: Sun, 20 Apr 2025 21:20:38 +0300 Subject: [PATCH] fix: move appendix styling out of the coursework template It is now possible to style headings as appendices in the pz-lb template via `#show: appendices_style`. --- README.md | 20 ++++++-- lib.typ | 106 +++++++++++++++++++--------------------- template/coursework.typ | 2 +- template/lab.typ | 22 +++++++++ 4 files changed, 90 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index a4a1076..bac2dfd 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This project contains two template functions and some utilities for writing NURE ### Templates -#### `pz-lb` - For Practical and Laboratory Works +#### `pz-lb` - For Practice and Laboratory Works This template: - Sets up document styles; - Formats the title page according to NURE/DSTU guidelines. @@ -50,9 +50,9 @@ Copy `lib.typ` to your project's root directory. // 1. Setup the document // by setting values directly... #show: pz-lb.with( - title: "Some title", - // etc: "and so on", - // ... + title: "Some title", + // etc: "and so on", + // ... ) // ...or using a config/doc.yaml file #show: pz-lb.with(..yaml("config/doc.yaml")) @@ -70,6 +70,18 @@ Some text #include "src/chapter2.typ" // NOTE: if you want to use variables or utils provided by the package, // you have to import the package or a lib.typ inside a module. + + +// If you ever need appendices in pz-lb template use the show rule +// WARNING: when using coursework template use its own argument, +// so it can put bibliography before appendices +#show: appendices_style + += Quote +#link("https://youtu.be/bJQj1uKtnus")[ + The art isn't the art, the art is never the art, + the art is the thing that happens inside you when you make it and the feeling in the heart of the beholder. +] ``` ### Notes: diff --git a/lib.typ b/lib.typ index d249d65..22bc681 100644 --- a/lib.typ +++ b/lib.typ @@ -87,6 +87,7 @@ // spacing between lines #let spacing = 0.95em +// main {{{2 #let style(it) = { set page( paper: "a4", @@ -113,7 +114,7 @@ set par(spacing: spacing) set par(leading: spacing) - // enums and lists {{{2 + // enums and lists {{{3 set enum( numbering: i => { ua_alpha_numbering.at(i) + ")" }, indent: 1.25cm, @@ -126,7 +127,7 @@ set list(indent: 1.35cm, body-indent: 0.5cm, marker: [--]) - // figures {{{2 + // figures {{{3 show figure: it => { v(spacing * 2, weak: true) it @@ -160,7 +161,7 @@ ), ) - // appearance of references to images and tables {{{2 + // appearance of references to images and tables {{{3 set ref( supplement: it => { if it == none or not it.has("kind") { @@ -187,7 +188,7 @@ [(#it)] } - // headings {{{2 + // headings {{{3 set heading(numbering: "1.1") show heading.where(level: 1): it => { @@ -222,7 +223,7 @@ v(spacing * 2, weak: true) } - // listings {{{2 + // listings {{{3 show raw: it => { let new_spacing = 0.5em set block(spacing: new_spacing) @@ -244,6 +245,45 @@ it } +// appendices {{{2 +#let appendices_style(it) = { + counter(heading).update(0) + + set heading( + numbering: (i, ..nums) => { + let char = upper(ua_alpha_numbering.at(i)) + if nums.pos().len() == 0 { char } else { + char + "." + nums.pos().map(str).join(".") + } + }, + ) + + show heading.where(level: 1): it => { + set align(center) + set text(size: 14pt, weight: "regular") + + pagebreak(weak: true) + bold[ДОДАТОК #counter(heading).display(it.numbering)] + linebreak() + it.body + v(spacing * 2, weak: true) + } + + show heading.where(level: 2): it => { + set text(size: 14pt, weight: "regular") + + v(spacing * 2, weak: true) + block(width: 100%, spacing: 0em)[ + #h(1.25cm) + #counter(heading).display(it.numbering) + #it.body + ] + v(spacing * 2, weak: true) + } + + it +} + // Coursework template {{{1 /// DSTU 3008:2015 Template for NURE @@ -504,21 +544,17 @@ #{ let keywords = abstract.keywords.map(upper) - let is_cyrillic = word => word - .split("") - .any(char => ("А" <= char and char <= "я")) + let is_cyrillic = word => word.split("").any(char => ("А" <= char and char <= "я")) let n = keywords.len() for i in range(n) { for j in range(0, n - i - 1) { if ( ( - not is_cyrillic(keywords.at(j)) - and is_cyrillic(keywords.at(j + 1)) + not is_cyrillic(keywords.at(j)) and is_cyrillic(keywords.at(j + 1)) ) or ( - is_cyrillic(keywords.at(j)) == is_cyrillic(keywords.at(j + 1)) - and keywords.at(j) > keywords.at(j + 1) + is_cyrillic(keywords.at(j)) == is_cyrillic(keywords.at(j + 1)) and keywords.at(j) > keywords.at(j + 1) ) ) { (keywords.at(j), keywords.at(j + 1)) = ( @@ -595,10 +631,7 @@ } context { - for (i, citation) in query(ref.where(element: none)) - .map(r => str(r.target)) - .dedup() - .enumerate() { + for (i, citation) in query(ref.where(element: none)).map(r => str(r.target)).dedup().enumerate() { enum.item( i + 1, format-entry(bib_data.at(citation)), @@ -607,47 +640,10 @@ } } - // appendices {{{2 - { - counter(heading).update(0) - - set heading( - numbering: (i, ..nums) => { - let char = upper(ua_alpha_numbering.at(i)) - if nums.pos().len() == 0 { char } else { - char + "." + nums.pos().map(str).join(".") - } - }, - ) - - show heading.where(level: 1): it => { - set align(center) - set text(size: 14pt, weight: "regular") - - pagebreak(weak: true) - bold[ДОДАТОК #counter(heading).display(it.numbering)] - linebreak() - it.body - v(spacing * 2, weak: true) - } - - show heading.where(level: 2): it => { - set text(size: 14pt, weight: "regular") - - v(spacing * 2, weak: true) - block(width: 100%, spacing: 0em)[ - #h(1.25cm) - #counter(heading).display(it.numbering) - #it.body - ] - v(spacing * 2, weak: true) - } - - appendices - } + appendices_style(appendices) } -// Laboratory work template {{{1 +// Practice and Laboratory works template {{{1 /// DSTU 3008:2015 Template for NURE /// -> content diff --git a/template/coursework.typ b/template/coursework.typ index 60ed7a1..c769191 100644 --- a/template/coursework.typ +++ b/template/coursework.typ @@ -106,7 +106,7 @@ task_list: task_list, calendar_plan: calendar_plan, abstract: abstract, - bib_path: "bibl.yml", + bib_path: bytes("bibl.yml"), // NOTE: use `bytes` as typst looks in template dir when using just filename appendices: appendices, ) diff --git a/template/lab.typ b/template/lab.typ index 66bb355..958e3ee 100644 --- a/template/lab.typ +++ b/template/lab.typ @@ -29,3 +29,25 @@ - #lorem(25); - #lorem(42); - #lorem(27). + +#show: appendices_style + += Quote +#link("https://youtu.be/bJQj1uKtnus")[ + The art isn't the art, the art is never the art, + the art is the thing that happens inside you when you make it and the feeling in the heart of the beholder. +] + + += Приклад звіту 1 +#v(-spacing) +== Частина 1 +#lorem(100) +== Частина2 +#lorem(200) + += Приклад звіту 2 +#lorem(200) + += Приклад звіту 3 +#lorem(200)