From a77366239b7d48955116c1941907dee0a03fb738 Mon Sep 17 00:00:00 2001 From: unexplrd Date: Wed, 28 Jan 2026 14:37:33 +0200 Subject: [PATCH] feat: add custom CSL for bibliography --- README.md | 32 +- src/csl/dstu-3008-2015.csl | 358 ++++++++++++++++++++++ src/lib.typ | 39 +-- src/title-pages/coursework/coursework.typ | 4 - 4 files changed, 393 insertions(+), 40 deletions(-) create mode 100644 src/csl/dstu-3008-2015.csl diff --git a/README.md b/README.md index 11ac474..edc7680 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,9 @@ This template: This template: - Sets up document styles; - Formats the title, task, calendar plan, and abstract pages; -- Typesets the bibliography, outline, and appendices according to standard requirements. +- Typesets the bibliography according to ДСТУ 3008:2015 using custom CSL style; +- Typesets the outline and appendices according to standard requirements. + ### Utilities - `nheading` - For unnumbered headings, such as "Introduction" and "Conclusion". @@ -122,6 +124,34 @@ semester = 4 1. Use `#v(-spacing)` to remove vertical spacing between titles (this cannot be automatically handled by the template). Variable `spacing` used here is imported from the template. 2. When importing `@local/nure:0.1.0` and specifying file paths in functions handled by the package, the path will relative to package's root directory, e.g. setting `#show: coursework.with(bib_path: "bibl.yml")` will evaluate to `~/.local/share/typst/packages/local/nure/0.1.0/bibl.yml`, the same is for `#img` function, which makes it quite annoying and forces one to import `lib.typ` file. Please open an issue or contact us in any other way if you have any advice. +### Bibliography Format +The template uses a custom CSL (Citation Style Language) file located at `src/csl/dstu-3008-2015.csl` to format bibliography entries. + +Supported bibliography entry types in `bibl.yml`: +- **Book**: Books with author, title, publisher, year, and page count +- **Web**: Web resources with title, author/organization, URL, and access date + +**Warning:** Other types were added by Kimi K2.5 without any additional checks for compliance. + +Example `bibl.yml`: +```yaml +mysql: + type: Book + title: MySQL Language Reference + author: Ab M. + publisher: MySQL Press + date: 2004 + page-total: 600 + +go: + type: Web + title: The Go Programming Language + author: The Go Programming Language + url: + value: https://go.dev/ + date: 2024-12-10 +``` + ### Example Project Structure ``` project/ diff --git a/src/csl/dstu-3008-2015.csl b/src/csl/dstu-3008-2015.csl new file mode 100644 index 0000000..dbff876 --- /dev/null +++ b/src/csl/dstu-3008-2015.csl @@ -0,0 +1,358 @@ + + diff --git a/src/lib.typ b/src/lib.typ index 2f09e07..88b81cc 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -52,41 +52,10 @@ // bibliography {{{2 { - heading(depth: 1, numbering: none)[Перелік джерел посилання] - - bibliography( - bib_path, - style: "ieee", - full: true, - title: none, - ) - - let bib_data = yaml(bib_path) - - let format-entry(c) = { - ( - "Web": c => { - let date_array = c.url.date.split("-") - let date = datetime(year: int(date_array.at(0)), month: int(date_array.at(1)), day: int(date_array.at(2))) - [#c.title. #c.author. URL: #c.url.value (дата звернення: #date.display("[day].[month].[year]")).] - }, - "Book": c => [#c.author #c.title. #c.publisher, #c.date. #c.page-total c.], - ).at(c.type, default: panic("Unsupported bibliography entry type"))(c) - } - - show enum.item: it => { - set par(first-line-indent: 0pt) - box(width: 1.25cm) - box(width: 1em + 0.5cm)[#it.number.] - it.body - linebreak() - } - - context { - 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))) - } - } + // shall CSL descend to hell for it's a horrid standard + show regex("^\\d+\\."): it => [#it#h(0.5cm)] + show block: it => [#it.body#parbreak()] + bibliography(bib_path, title: [Перелік джерел посилання], style: "csl/dstu-3008-2015.csl", full: true) } style.appendices(appendices) diff --git a/src/title-pages/coursework/coursework.typ b/src/title-pages/coursework/coursework.typ index afbfaf8..8234767 100644 --- a/src/title-pages/coursework/coursework.typ +++ b/src/title-pages/coursework/coursework.typ @@ -19,10 +19,6 @@ it bib-count.update(((..c)) => (..c, it.key)) } - show bibliography: it => { - set text(size: 0pt) - it - } let author = authors.first() let head_mentor = mentors.first()