From 7aabfcf1f904addb84616f0ba00c19f290ea6205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mekina?= Date: Tue, 23 Sep 2025 18:40:51 +0200 Subject: [PATCH] add classic template styling --- Makefile | 4 ++- example.typ | 8 +++-- template/abbreviations.typ | 23 +++++++++++++ template/template.typ | 22 ++++++++----- template/template_classic.typ | 62 ++++++++++++++++++++++++++++++++++- 5 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 template/abbreviations.typ diff --git a/Makefile b/Makefile index 3f94b68..1b03eab 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ .PHONY: example example: example.pdf -%.pdf: %.typ +TEMPLATE_SRCS := $(shell find template -type f) + +%.pdf: %.typ $(TEMPLATE_SRCS) typst compile --font-path template/fonts $< diff --git a/example.typ b/example.typ index 8d86086..899e23c 100644 --- a/example.typ +++ b/example.typ @@ -1,7 +1,11 @@ -#import "template/template.typ": tultemplate +#import "template/template.typ": * -#tultemplate( +#show: tultemplate.with( "classic", "fm", "cs", title: "Návod na použití Typst TUL šablony", author: "Ondřej Mekina", ) + += Todo + +WIP diff --git a/template/abbreviations.typ b/template/abbreviations.typ new file mode 100644 index 0000000..70c8963 --- /dev/null +++ b/template/abbreviations.typ @@ -0,0 +1,23 @@ +#let abbreviations = state("abbrs", "()"); + +#let abbr(abbreviation, text) = { + abbreviations.update(abbrs => { + let abbrs = if abbrs.len() == 2 { eval(abbrs).to-dict() } else { eval(abbrs) }; + if abbreviation not in abbrs { + if type(text) == type(none) { + panic( + "abbreviation '" + abbreviation + + "' has no definition yet, please specify it on the first call" + ); + } + abbrs.insert(abbreviation, text); + } + "(" + abbrs.pairs().map((v) => { v.at(0) + ":\"" + v.at(1) + "\"" }).join(",") + ")" + }); + abbreviation; +} + +#let abbrlist() = { + let abbreviations = abbreviations.final(); + return if abbreviations.len() == 2 { ().to-dict() } else { eval(abbreviations) } +} diff --git a/template/template.typ b/template/template.typ index a53297c..57de910 100644 --- a/template/template.typ +++ b/template/template.typ @@ -1,20 +1,26 @@ -#import "template_classic.typ": template_classic -#import "utils.typ": assert_in_dict - -#let templates = ( - classic: template_classic, -); - #let tultemplate( template_id, faculty_abbreviation, language, document_type: none, title: none, author: none, supervisor: none, study_programme: none, + content, ) = { + import "template_classic.typ": template_classic + import "utils.typ": assert_in_dict + let templates = ( + classic: template_classic, + ); assert_in_dict(template_id, templates, "template name"); + templates.at(template_id)( faculty_abbreviation, language, document_type, - title, author, supervisor, study_programme + title, author, supervisor, study_programme, + content ); } + +#let abbr(abbreviation, ..text) = { + import "abbreviations.typ": abbr + return abbr(abbreviation, if text.pos().len() == 0 { none } else { text.pos().at(0) }); +} diff --git a/template/template_classic.typ b/template/template_classic.typ index ce1e7a2..fa172e7 100644 --- a/template/template_classic.typ +++ b/template/template_classic.typ @@ -71,12 +71,32 @@ } } +#let abbrlist(language) = { + import "abbreviations.typ": abbrlist + context { + let abbrs = abbrlist(); + let max_abbr_width = if abbrs.len() > 0 { + calc.max(abbrs.keys().map((v) => measure(v).width)).at(0) + } else { return }; + pagebreak(weak: true); + heading(("Seznam zkratek", "List of abbreviations").at(language), numbering: none); + align(center, grid( + columns: 2, + ..abbrs.pairs().map((v) => { + (block(text(v.at(0), weight: "bold"), width: max_abbr_width + 1em), text(v.at(1))) + }).flatten() + )); + } +} + #let template_classic( faculty_id, language, document_type, - title, author, supervisor, study_programme + title, author, supervisor, study_programme, + content, ) = { + // intro page page({ classic_header(faculty_id, language); align({ @@ -84,4 +104,44 @@ v(5em); }, bottom); }, margin: 2cm); + + // styling + let faculty_color = faculty_color(faculty_id); + set par(justify: true); + set text(lang: "cs"); + set heading(numbering: "1.1.1 "); + set page(margin: (outside: 4cm, top: 3cm, bottom: 3cm), numbering: "1", footer: { + context { + let page = counter(page).get().at(0); + align(str(page), if calc.rem(page, 2) == 0 { right } else { left }) + } + }); + show heading: it => { + block( + above: 2em, + below: 2em, + text(it, faculty_color, font: "TUL Mono", size: 1.2em) + ); + }; + show heading.where(level: 1): it => { + pagebreak(); + v(2cm); + it + }; + + let language = lang_id(language); + + // toc + show outline.entry.where(level: 1): it => { + show repeat: none; + block(text(it, weight: "bold", size: 1.2em), above: 1.5em); + }; + outline(title: ("Obsah", "Contents").at(language)); + + // abbreviation list + abbrlist(language); + + // content + pagebreak(to: "even", weak: true); + content }