From 1a7fe4a394e4bfd716f4c64377c8710102e71609 Mon Sep 17 00:00:00 2001 From: unexplrd Date: Sun, 29 Mar 2026 16:12:12 +0300 Subject: [PATCH] add unexplrd-mise template --- template/{ => default}/bibl.yml | 0 template/{ => default}/coursework.typ | 0 template/{ => default}/lab.typ | 0 template/{ => default}/utils.typ | 0 template/unexplrd-mise/README.md | 67 +++++++++++++ template/unexplrd-mise/mise.lock | 35 +++++++ template/unexplrd-mise/mise.toml | 66 +++++++++++++ template/unexplrd-mise/src/appendices.typ | 4 + template/unexplrd-mise/src/doc.toml | 19 ++++ template/unexplrd-mise/src/main.typ | 23 +++++ template/unexplrd-mise/src/utils.typ | 112 ++++++++++++++++++++++ typst.toml | 2 +- 12 files changed, 327 insertions(+), 1 deletion(-) rename template/{ => default}/bibl.yml (100%) rename template/{ => default}/coursework.typ (100%) rename template/{ => default}/lab.typ (100%) rename template/{ => default}/utils.typ (100%) create mode 100644 template/unexplrd-mise/README.md create mode 100644 template/unexplrd-mise/mise.lock create mode 100644 template/unexplrd-mise/mise.toml create mode 100644 template/unexplrd-mise/src/appendices.typ create mode 100644 template/unexplrd-mise/src/doc.toml create mode 100644 template/unexplrd-mise/src/main.typ create mode 100644 template/unexplrd-mise/src/utils.typ diff --git a/template/bibl.yml b/template/default/bibl.yml similarity index 100% rename from template/bibl.yml rename to template/default/bibl.yml diff --git a/template/coursework.typ b/template/default/coursework.typ similarity index 100% rename from template/coursework.typ rename to template/default/coursework.typ diff --git a/template/lab.typ b/template/default/lab.typ similarity index 100% rename from template/lab.typ rename to template/default/lab.typ diff --git a/template/utils.typ b/template/default/utils.typ similarity index 100% rename from template/utils.typ rename to template/default/utils.typ diff --git a/template/unexplrd-mise/README.md b/template/unexplrd-mise/README.md new file mode 100644 index 0000000..c9d5b81 --- /dev/null +++ b/template/unexplrd-mise/README.md @@ -0,0 +1,67 @@ +# unexplrd's example setup with mise + +This example has the following structure: +``` +. +├── mise.lock +├── mise.toml +├── vendor/ +│ └── typst-packages/ +│ └── ... +└── src/ + ├── assets/ + │ ├── foo.csv + │ ├── bar.c + │ └── ... + ├── figures/ + │ ├── clojure-logo.png + │ ├── error-log.jpg + │ └── ... + ├── doc.toml + ├── appendices.typ + ├── main.typ + └── utils.typ +``` + +## Advantages +- Declarative approach +- Fixed dependencies: locked Typst version, `nure` package fetched from a specific commit +- Customizable: it's just a `.toml` file, modify it according to your needs + +## Mise tasks +- `compile`: Execute `typst compile` on `src/main.typ` +- `watch`: Execute `typst watch` on `src/main.typ` +- `fetch-nure-package`: clone package git repository to a directory specified in `[vars]` +- `update-package-rev`: updates `vars.nure_package_rev` with the last commit id from the specified branch (`vars.nure_package_ref`) + +## Examples +- A patch to add new subjects to the package: + ```diff + diff --git a/src/config/universities.yaml b/src/config/universities.yaml + index 8855a07..1aefc96 100644 + --- a/src/config/universities.yaml + +++ b/src/config/universities.yaml + @@ -60,7 +60,6 @@ + ПЕСЕ: Психологія екстремальних стосунків та ефективної адаптації + ПНП: Програмування на платформі .NЕТ + ПП: Проектний практикум + - ПРОГ: Програмування + ПарП: Параллельне програмування + СА: Системний аналіз + СМП: Скриптові мови програмування + @@ -76,3 +75,10 @@ + ФІЛ: Філософія + ФВС: Фізичне виховання та спорт + ХТ: Хмарні технології + + АКС: Архітектура комп'ютерних систем + + ІКС: Інформаційно-комунікаційні системи + + МБ: Мережна безпека + + МКр: Мережна криміналістика + + ОКЗІ: Основи криптографічного захисту інформації + + Прог: Програмування + + ТІК: Теорія інформаціі та кодування + ``` + To apply it, add the following command to the `fetch_nure_package` task: + ```sh + git -C {{vars.nure_package_path}} apply --check --apply --quiet $MISE_PROJECT_ROOT/custom-subjects.patch || exit 0 + ``` diff --git a/template/unexplrd-mise/mise.lock b/template/unexplrd-mise/mise.lock new file mode 100644 index 0000000..2881ce0 --- /dev/null +++ b/template/unexplrd-mise/mise.lock @@ -0,0 +1,35 @@ +[[tools.tinymist]] +version = "0.14.14" +backend = "aqua:Myriad-Dreamin/tinymist" +"platforms.linux-arm64" = { checksum = "sha256:39eb99d290fd1aa0e4508e5d5bbbf5a49648cf26da8e7bc3ff49f75c5fd0dc6c", url = "https://github.com/Myriad-Dreamin/tinymist/releases/download/v0.14.14/tinymist-linux-arm64"} +"platforms.linux-x64" = { checksum = "sha256:cda2ba76a455f3577cf2a1bd6340b75491f0c673770f631cf4d3232663860776", url = "https://github.com/Myriad-Dreamin/tinymist/releases/download/v0.14.14/tinymist-linux-x64"} +"platforms.macos-arm64" = { checksum = "sha256:ea7a22af0d54a71fbd1ee6c8c9f8434b521549926ae0f53a82391adeea741aba", url = "https://github.com/Myriad-Dreamin/tinymist/releases/download/v0.14.14/tinymist-darwin-arm64"} +"platforms.macos-x64" = { checksum = "sha256:f640889414d5030de1f03b966ccb10a84941bc1176980ff956d66714508ccd85", url = "https://github.com/Myriad-Dreamin/tinymist/releases/download/v0.14.14/tinymist-darwin-x64"} +"platforms.windows-x64" = { checksum = "sha256:3d39c7b417287d8689c69159b65fbc62427e141b9489500ad81039ee783f2549", url = "https://github.com/Myriad-Dreamin/tinymist/releases/download/v0.14.14/tinymist-win32-x64.exe"} + +[[tools.typst]] +version = "0.14.2" +backend = "aqua:typst/typst" +"platforms.linux-arm64" = { checksum = "sha256:491b101aa40a3a7ea82a3f8a6232cabb4e6a7e233810082e5ac812d43fdcd47a", url = "https://github.com/typst/typst/releases/download/v0.14.2/typst-aarch64-unknown-linux-musl.tar.xz"} +"platforms.linux-x64" = { checksum = "sha256:a6044cbad2a954deb921167e257e120ac0a16b20339ec01121194ff9d394996d", url = "https://github.com/typst/typst/releases/download/v0.14.2/typst-x86_64-unknown-linux-musl.tar.xz"} +"platforms.macos-arm64" = { checksum = "sha256:470aa49a2298d20b65c119a10e4ff8808550453e0cb4d85625b89caf0cedf048", url = "https://github.com/typst/typst/releases/download/v0.14.2/typst-aarch64-apple-darwin.tar.xz"} +"platforms.macos-x64" = { checksum = "sha256:4e91d8e1e33ab164f949c5762e01ee3faa585c8615a2a6bd5e3677fa8506b249", url = "https://github.com/typst/typst/releases/download/v0.14.2/typst-x86_64-apple-darwin.tar.xz"} +"platforms.windows-x64" = { checksum = "sha256:51353994ac83218c3497052e89b2c432c53b9d4439cdc1b361e2ea4798ebfc13", url = "https://github.com/typst/typst/releases/download/v0.14.2/typst-x86_64-pc-windows-msvc.zip"} + +[[tools.typstyle]] +version = "0.14.4" +backend = "aqua:Enter-tainer/typstyle" +"platforms.linux-arm64" = { checksum = "sha256:b8c220c0d940d7690fb15ef10415de35fdc115465a7534d8102459c68aeec74d", url = "https://github.com/typstyle-rs/typstyle/releases/download/v0.14.4/typstyle-aarch64-unknown-linux-gnu"} +"platforms.linux-x64" = { checksum = "sha256:48d9a9a3885855f1b4f6c2b8ea9739623bc458b99c015b77c4f50a1f342ea091", url = "https://github.com/typstyle-rs/typstyle/releases/download/v0.14.4/typstyle-x86_64-unknown-linux-musl"} +"platforms.macos-arm64" = { checksum = "sha256:dda3a162f2457a40570c3552cc9c01004138b33f2f921112b117d72f48bd6d56", url = "https://github.com/typstyle-rs/typstyle/releases/download/v0.14.4/typstyle-aarch64-apple-darwin"} +"platforms.macos-x64" = { checksum = "sha256:2343f7a4801d9bbda5d7441e8fea95f98b590d6aa3083da5c4e4ca3de885350f", url = "https://github.com/typstyle-rs/typstyle/releases/download/v0.14.4/typstyle-x86_64-apple-darwin"} +"platforms.windows-x64" = { checksum = "sha256:b16aebaed0aa296ef3e055d611f1e917f5849d3eb0f953bbcaa6f09f0503fb5b", url = "https://github.com/typstyle-rs/typstyle/releases/download/v0.14.4/typstyle-x86_64-pc-windows-msvc.exe"} + +[[tools.yq]] +version = "4.52.2" +backend = "aqua:mikefarah/yq" +"platforms.linux-arm64" = { checksum = "sha256:c82856ac30da522f50dcdd4f53065487b5a2927e9b87ff637956900986f1f7c2", url = "https://github.com/mikefarah/yq/releases/download/v4.52.2/yq_linux_arm64"} +"platforms.linux-x64" = { checksum = "sha256:a74bd266990339e0c48a2103534aef692abf99f19390d12c2b0ce6830385c459", url = "https://github.com/mikefarah/yq/releases/download/v4.52.2/yq_linux_amd64"} +"platforms.macos-arm64" = { checksum = "sha256:34613ea97c4c77e1894a8978dbf72588d187a69a6292c10dab396c767a1ecde7", url = "https://github.com/mikefarah/yq/releases/download/v4.52.2/yq_darwin_arm64"} +"platforms.macos-x64" = { checksum = "sha256:54a63555210e73abed09108097072e28bf82a6bb20439a72b55509c4dd42378d", url = "https://github.com/mikefarah/yq/releases/download/v4.52.2/yq_darwin_amd64"} +"platforms.windows-x64" = { checksum = "sha256:2b6cd8974004fa0511f6b6b359d2698214fadeb4599f0b00e8d85ae62b3922d4", url = "https://github.com/mikefarah/yq/releases/download/v4.52.2/yq_windows_amd64.exe"} diff --git a/template/unexplrd-mise/mise.toml b/template/unexplrd-mise/mise.toml new file mode 100644 index 0000000..d7d536c --- /dev/null +++ b/template/unexplrd-mise/mise.toml @@ -0,0 +1,66 @@ +[settings] +quiet = true +env_shell_expand = true +lockfile = true + +[tools] +typst = "latest" +typstyle = "latest" +tinymist = "latest" +yq = "latest" + +[vars] +vendor_dir = "{{config_root}}/vendor" + +work_doc_config = "src/doc.toml" +work_input_file = "src/main.typ" +work_output_file = "{{config_root}}/main.pdf" + +nure_package_repo = "https://gitea.linerds.us/pencelheimer/typst_nure_template.git" +nure_package_ref = "0.1.1" +nure_package_rev = "af2ba45a16f94b37cae9db0f8fdb915db545498d" +nure_package_path = "{{env.TYPST_PACKAGE_DIR}}/{{vars.nure_package_name}}/{{vars.nure_package_ver}}" + +nure_package_name = "vendor/nure" +nure_package_ver = "{{vars.nure_package_ref}}" + +[env] +TYPST_PACKAGE_DIR = "{{vars.vendor_dir}}/typst-packages" +TYPST_PACKAGE_PATH = "$TYPST_PACKAGE_DIR" + +[tasks.watch] +depends = ["fetch-nure-package"] +run = "mise exec -- typst watch {{vars.work_input_file}} {{vars.work_output_file}}" + +[tasks.compile] +depends = ["fetch-nure-package"] +run = "mise exec -- typst compile {{vars.work_input_file}} {{vars.work_output_file}}" + +[tasks.clean] +run = "rm -rvif *.pdf" + +[tasks.update-package-rev] +run = "mise config set vars.nure_package_rev $(git ls-remote {{vars.nure_package_repo}} refs/heads/{{vars.nure_package_ref}} | cut -f1)" + +[tasks.fetch-nure-package] +silent = "stdout" +run = """ + #!/usr/bin/env bash + + if [ ! -d {{vars.nure_package_path}}/.git ]; then + git clone --depth 1 --revision {{vars.nure_package_rev}} {{vars.nure_package_repo}} {{vars.nure_package_path}} + else + git -C {{vars.nure_package_path}} fetch --depth 1 origin {{vars.nure_package_rev}} + git -C {{vars.nure_package_path}} checkout {{vars.nure_package_rev}} + fi +""" + +[tasks.copy] +depends = ["compile"] +run = """ + #!/usr/bin/env bash + + final_name=$(mise exec -- yq '.type + (.number | tostring) + "_" + (.authors[0].name | split(" "))[0] + "_" + (.authors[0].edu-program + "-" + .authors[0].group) + "_" + .subject + ".pdf"' "{{vars.work_doc_config}}"); + + cp -v "{{vars.work_output_file}}" "$final_name" +""" diff --git a/template/unexplrd-mise/src/appendices.typ b/template/unexplrd-mise/src/appendices.typ new file mode 100644 index 0000000..e6b064b --- /dev/null +++ b/template/unexplrd-mise/src/appendices.typ @@ -0,0 +1,4 @@ +#import "utils.typ": code + +// = Код програми sample.c +// #code(read("/assets/sample.c")) diff --git a/template/unexplrd-mise/src/doc.toml b/template/unexplrd-mise/src/doc.toml new file mode 100644 index 0000000..244643a --- /dev/null +++ b/template/unexplrd-mise/src/doc.toml @@ -0,0 +1,19 @@ +university = "ХНУРЕ" +subject = "АКС" +type = "ЛБ" +number = 1 + +[[mentors]] +name = "" +degree = "" +gender = "" + +[[authors]] +name = "" +edu-program = "КУІБ" +group = "24-1" +gender = "m" +variant = 6 +full-name-gen = "" +course = 2 +semester = 4 diff --git a/template/unexplrd-mise/src/main.typ b/template/unexplrd-mise/src/main.typ new file mode 100644 index 0000000..b09e6ba --- /dev/null +++ b/template/unexplrd-mise/src/main.typ @@ -0,0 +1,23 @@ +#import "@vendor/nure:0.1.1": * +#import "utils.typ": * + +#import style: spacing + +// Apply custom rule from utils.typ +// #show: correctly-indent-list-and-enum-items + +// #show: style.dstu +#show: pz-lb.with(..toml("doc.toml"), title: "") // set title to none if empty + +// Useful snippets + +// #figure( +// caption: [], +// table( +// columns: 4, +// table.header([], [], [], []), +// ..csv("assets/table.csv").flatten(), +// ), +// ) + +// #style.appendices(include "appendices.typ") diff --git a/template/unexplrd-mise/src/utils.typ b/template/unexplrd-mise/src/utils.typ new file mode 100644 index 0000000..1fd6991 --- /dev/null +++ b/template/unexplrd-mise/src/utils.typ @@ -0,0 +1,112 @@ +#import "@local/nure:0.1.1": utils + +/// captioned image with auto-generated label from path +/// Usage: img("path/to/image.png", "Caption")(optional: "source") +#let img(path, caption, ..sink) = { + let source = sink.pos().at(0, default: ()) + [ #figure(image(path, ..sink.named()), caption: utils.img-caption(caption, source)) #utils.img-label(path) ] +} + +/// takes in a string of code, e.g. #code(read("foo.c")) +#let code(content) = raw(block: true, theme: none, content) + +/// read path as bytes +#let b(path) = bytes(read(path, encoding: none)) + +/// include chapters by file names from /chapters +#let chapters(ch) = ( + array(ch).map(chapter => include str(chapter) + ".typ").join() +) + +/// https://forum.typst.app/t/how-to-make-bullet-list-item-bodies-flow-like-paragraphs/3756/3?u=andrew +/// Spacing doesn't work the same way as native solution if par leading and +/// spacing are different. +#let correctly-indent-list-and-enum-items(doc) = { + let first-line-indent() = if type(par.first-line-indent) == dictionary { + par.first-line-indent.amount + } else { + par.first-line-indent + } + + show list: li => { + for (i, it) in li.children.enumerate() { + let nesting = state("list-nesting", 0) + let indent = context h((nesting.get() + 1) * li.indent) + let get-nesting() = calc.div-euclid(nesting.get(), 10) + let marker = context { + let n = get-nesting() + if type(li.marker) == array { + li.marker.at(calc.rem-euclid(n, li.marker.len())) + } else if type(li.marker) == content { + li.marker + } else { + li.marker(n) + } + } + let parents = state("enum-parents", ()) // Support enum nesting. + let body = { + parents.update(arr => arr + (-1,)) + nesting.update(x => x + 10) + it.body + parbreak() + nesting.update(x => x - 10) + parents.update(arr => arr.slice(0, -1)) + } + let content = { + marker + h(li.body-indent) + body + } + context pad(left: int(nesting.get() != 0) * li.indent, content) + } + } + + show enum: en => { + let start = if en.start == auto { + if en.children.first().has("number") { + if en.reversed { en.children.first().number } else { 1 } + } else { + if en.reversed { en.children.len() } else { 1 } + } + } else { + en.start + } + let number = start + for (i, it) in en.children.enumerate() { + number = if it.number != auto { it.number } else { number } + if en.reversed { number = start - i } + let parents = state("enum-parents", ()) + let get-parents() = parents.get().filter(x => x >= 0) + let indent = context h((get-parents().len() + 1) * en.indent) + let num = if en.full { + context numbering(en.numbering, ..get-parents(), number) + } else { + numbering(en.numbering, number) + } + let max-num = if en.full { + context numbering(en.numbering, ..get-parents(), en.children.len()) + } else { + numbering(en.numbering, en.children.len()) + } + num = context box( + width: measure(max-num).width, + align(right, text(overhang: false, num)), + ) + let list-nesting = state("list-nesting", 0) // Support list nesting. + let body = { + parents.update(arr => arr + (number,)) + list-nesting.update(x => x + 1) + it.body + parbreak() + list-nesting.update(x => x - 1) + parents.update(arr => arr.slice(0, -1)) + } + if not en.reversed { number += 1 } + let content = { + num + h(en.body-indent) + body + } + context pad(left: int(parents.get().len() != 0) * en.indent, content) + } + } + doc +} diff --git a/typst.toml b/typst.toml index 81aa0e0..f240ba9 100644 --- a/typst.toml +++ b/typst.toml @@ -7,5 +7,5 @@ license = "GPL-3.0" description = "Typst NURE package" [template] -path = "template" +path = "template/default" entrypoint = "lab.typ"