forked from pencelheimer/typst_nure_template
feat: add custom CSL for bibliography
This commit is contained in:
@@ -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/
|
||||
|
||||
@@ -0,0 +1,358 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<style
|
||||
xmlns="http://purl.org/net/xbiblio/csl"
|
||||
class="in-text"
|
||||
version="1.0"
|
||||
demote-non-dropping-particle="display-and-sort"
|
||||
default-locale="uk-UA"
|
||||
>
|
||||
<info>
|
||||
<title>ДСТУ 3008:2015 (DSTU 3008:2015)</title>
|
||||
<title-short>ДСТУ 3008:2015</title-short>
|
||||
<id>http://www.zotero.org/styles/dstu-3008-2015</id>
|
||||
<link href="http://www.zotero.org/styles/dstu-3008-2015" rel="self" />
|
||||
<link
|
||||
href="https://uk.wikipedia.org/wiki/ДСТУ_3008:2015"
|
||||
rel="documentation"
|
||||
/>
|
||||
<author>
|
||||
<name>Automated</name>
|
||||
</author>
|
||||
<category citation-format="numeric" />
|
||||
<category field="generic-base" />
|
||||
<summary
|
||||
>Український стандарт бібліографічного опису ДСТУ 3008:2015</summary>
|
||||
<updated>2024-01-01T00:00:00+00:00</updated>
|
||||
<rights
|
||||
license="http://creativecommons.org/licenses/by-sa/3.0/"
|
||||
>This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
|
||||
</info>
|
||||
|
||||
<!-- Locale definitions -->
|
||||
<locale xml:lang="uk">
|
||||
<terms>
|
||||
<term name="accessed">дата звернення</term>
|
||||
<term name="available at">URL</term>
|
||||
<term name="page" form="short">с</term>
|
||||
<term name="page" form="symbol">с</term>
|
||||
<term name="et-al">та ін.</term>
|
||||
<term name="and">,</term>
|
||||
<term name="editor" form="short">ред.</term>
|
||||
<term name="translator" form="short">пер.</term>
|
||||
<term name="edition" form="short">вид.</term>
|
||||
<term name="volume" form="short">т.</term>
|
||||
<term name="issue" form="short">вип.</term>
|
||||
<term name="number" form="short">№</term>
|
||||
</terms>
|
||||
</locale>
|
||||
|
||||
<!-- Macros -->
|
||||
|
||||
<!-- Authors/Editors macro -->
|
||||
<macro name="author">
|
||||
<names variable="author">
|
||||
<name initialize-with=". " delimiter=", " delimiter-precedes-last="never">
|
||||
<name-part name="family" text-case="capitalize-first" />
|
||||
<name-part name="given" />
|
||||
</name>
|
||||
<substitute>
|
||||
<names variable="editor">
|
||||
<name
|
||||
initialize-with=". "
|
||||
delimiter=", "
|
||||
delimiter-precedes-last="never"
|
||||
>
|
||||
<name-part name="family" text-case="capitalize-first" />
|
||||
<name-part name="given" />
|
||||
</name>
|
||||
<label form="short" prefix=" (" suffix=")" />
|
||||
</names>
|
||||
<names variable="translator">
|
||||
<name
|
||||
initialize-with=". "
|
||||
delimiter=", "
|
||||
delimiter-precedes-last="never"
|
||||
>
|
||||
<name-part name="family" text-case="capitalize-first" />
|
||||
<name-part name="given" />
|
||||
</name>
|
||||
<label form="short" prefix=" (" suffix=")" />
|
||||
</names>
|
||||
<text macro="title" />
|
||||
</substitute>
|
||||
</names>
|
||||
</macro>
|
||||
|
||||
<!-- Title macro -->
|
||||
<macro name="title">
|
||||
<choose>
|
||||
<if type="book thesis report" match="any">
|
||||
<text variable="title" font-style="italic" />
|
||||
</if>
|
||||
<else-if type="webpage post post-weblog" match="any">
|
||||
<text variable="title" />
|
||||
</else-if>
|
||||
<else>
|
||||
<text variable="title" />
|
||||
</else>
|
||||
</choose>
|
||||
</macro>
|
||||
|
||||
<!-- Publisher info -->
|
||||
<macro name="publisher">
|
||||
<group delimiter=": ">
|
||||
<text variable="publisher-place" />
|
||||
<text variable="publisher" />
|
||||
</group>
|
||||
</macro>
|
||||
|
||||
<!-- Year -->
|
||||
<macro name="year">
|
||||
<date variable="issued">
|
||||
<date-part name="year" />
|
||||
</date>
|
||||
</macro>
|
||||
|
||||
<!-- Pages -->
|
||||
<macro name="pages">
|
||||
<choose>
|
||||
<if type="book thesis report" match="any">
|
||||
<text variable="number-of-pages" />
|
||||
<text term="page" form="symbol" />
|
||||
</if>
|
||||
<else>
|
||||
<group delimiter=" ">
|
||||
<text term="page" form="short" />
|
||||
<text variable="page" />
|
||||
</group>
|
||||
</else>
|
||||
</choose>
|
||||
</macro>
|
||||
|
||||
<!-- Access date and URL for web resources -->
|
||||
<macro name="access">
|
||||
<choose>
|
||||
<if type="webpage post post-weblog" match="any">
|
||||
<group delimiter=" " prefix=". ">
|
||||
<text term="available at" suffix=":" />
|
||||
<text variable="URL" />
|
||||
<group delimiter=": " prefix="(" suffix=")">
|
||||
<text term="accessed" />
|
||||
<date variable="accessed">
|
||||
<date-part name="day" form="numeric-leading-zeros" suffix="." />
|
||||
<date-part name="month" form="numeric-leading-zeros" suffix="." />
|
||||
<date-part name="year" />
|
||||
</date>
|
||||
</group>
|
||||
</group>
|
||||
</if>
|
||||
</choose>
|
||||
</macro>
|
||||
|
||||
<!-- Volume/Issue -->
|
||||
<macro name="volume-issue">
|
||||
<group delimiter=". ">
|
||||
<group delimiter=" ">
|
||||
<text term="volume" form="short" />
|
||||
<text variable="volume" />
|
||||
</group>
|
||||
<group delimiter=" ">
|
||||
<text term="issue" form="short" />
|
||||
<text variable="issue" />
|
||||
</group>
|
||||
</group>
|
||||
</macro>
|
||||
|
||||
<!-- Main citation format (numeric) -->
|
||||
<citation collapse="citation-number">
|
||||
<sort>
|
||||
<key variable="citation-number" />
|
||||
</sort>
|
||||
<layout delimiter=", " prefix="[" suffix="]">
|
||||
<text variable="citation-number" />
|
||||
</layout>
|
||||
</citation>
|
||||
|
||||
<!-- Bibliography format -->
|
||||
<bibliography hanging-indent="false">
|
||||
<sort>
|
||||
<key variable="citation-number" />
|
||||
</sort>
|
||||
<layout>
|
||||
<group display="block">
|
||||
<text display="left-margin" variable="citation-number" suffix=". " />
|
||||
|
||||
<!-- Book -->
|
||||
<choose>
|
||||
<if type="book">
|
||||
<group delimiter=". " suffix=".">
|
||||
<text macro="author" />
|
||||
<text macro="title" />
|
||||
<text macro="publisher" />
|
||||
<text macro="year" />
|
||||
<text macro="pages" />
|
||||
</group>
|
||||
</if>
|
||||
|
||||
<!-- Thesis -->
|
||||
<else-if type="thesis">
|
||||
<group delimiter=". ">
|
||||
<text macro="author" />
|
||||
<text macro="title" />
|
||||
<text variable="genre" />
|
||||
<text macro="publisher" />
|
||||
<text macro="year" />
|
||||
<text macro="pages" />
|
||||
</group>
|
||||
</else-if>
|
||||
|
||||
<!-- Report -->
|
||||
<else-if type="report">
|
||||
<group delimiter=". ">
|
||||
<text macro="author" />
|
||||
<text macro="title" />
|
||||
<text variable="genre" />
|
||||
<text macro="publisher" />
|
||||
<text macro="year" />
|
||||
<text macro="pages" />
|
||||
</group>
|
||||
</else-if>
|
||||
|
||||
<!-- Article in journal -->
|
||||
<else-if type="article-journal">
|
||||
<group delimiter=". ">
|
||||
<text macro="author" />
|
||||
<group delimiter=" // ">
|
||||
<text variable="title" />
|
||||
<text variable="container-title" font-style="italic" />
|
||||
</group>
|
||||
<group delimiter=". ">
|
||||
<text macro="year" />
|
||||
<text macro="volume-issue" />
|
||||
<text macro="pages" />
|
||||
</group>
|
||||
</group>
|
||||
</else-if>
|
||||
|
||||
<!-- Article in newspaper -->
|
||||
<else-if type="article-newspaper">
|
||||
<group delimiter=". ">
|
||||
<text macro="author" />
|
||||
<group delimiter=" // ">
|
||||
<text variable="title" />
|
||||
<text variable="container-title" />
|
||||
</group>
|
||||
<group delimiter=". ">
|
||||
<date variable="issued">
|
||||
<date-part name="day" suffix="." />
|
||||
<date-part name="month" suffix="." />
|
||||
<date-part name="year" />
|
||||
</date>
|
||||
<text macro="pages" />
|
||||
</group>
|
||||
</group>
|
||||
</else-if>
|
||||
|
||||
<!-- Conference paper -->
|
||||
<else-if type="paper-conference">
|
||||
<group delimiter=". ">
|
||||
<text macro="author" />
|
||||
<text variable="title" />
|
||||
<group delimiter=" // ">
|
||||
<text term="in" />
|
||||
<text variable="container-title" />
|
||||
</group>
|
||||
<group delimiter=". ">
|
||||
<text macro="publisher" />
|
||||
<text macro="year" />
|
||||
<text macro="pages" />
|
||||
</group>
|
||||
</group>
|
||||
</else-if>
|
||||
|
||||
<!-- Chapter in book -->
|
||||
<else-if type="chapter">
|
||||
<group delimiter=". ">
|
||||
<text macro="author" />
|
||||
<text variable="title" />
|
||||
<group delimiter=" // ">
|
||||
<text term="in" />
|
||||
<names variable="editor">
|
||||
<name
|
||||
initialize-with=". "
|
||||
delimiter=", "
|
||||
delimiter-precedes-last="never"
|
||||
>
|
||||
<name-part name="family" text-case="capitalize-first" />
|
||||
<name-part name="given" />
|
||||
</name>
|
||||
<label form="short" prefix=" (" suffix=")" />
|
||||
</names>
|
||||
<text variable="container-title" font-style="italic" />
|
||||
</group>
|
||||
<group delimiter=". ">
|
||||
<text macro="publisher" />
|
||||
<text macro="year" />
|
||||
<text macro="pages" />
|
||||
</group>
|
||||
</group>
|
||||
</else-if>
|
||||
|
||||
<!-- Webpage/Online -->
|
||||
<else-if type="webpage post post-weblog" match="any">
|
||||
<group delimiter=". ">
|
||||
<text variable="title" />
|
||||
<text macro="author" />
|
||||
<text variable="container-title" />
|
||||
<date variable="issued">
|
||||
<date-part name="day" suffix="." />
|
||||
<date-part name="month" suffix="." />
|
||||
<date-part name="year" />
|
||||
</date>
|
||||
</group>
|
||||
<text macro="access" suffix="." />
|
||||
</else-if>
|
||||
|
||||
<!-- Patent -->
|
||||
<else-if type="patent">
|
||||
<group delimiter=". ">
|
||||
<text macro="author" />
|
||||
<text variable="title" />
|
||||
<text variable="number" />
|
||||
<date variable="issued">
|
||||
<date-part name="day" suffix="." />
|
||||
<date-part name="month" suffix="." />
|
||||
<date-part name="year" />
|
||||
</date>
|
||||
</group>
|
||||
</else-if>
|
||||
|
||||
<!-- Legislation -->
|
||||
<else-if type="legislation">
|
||||
<group delimiter=". ">
|
||||
<text variable="title" />
|
||||
<date variable="issued">
|
||||
<date-part name="day" suffix="." />
|
||||
<date-part name="month" suffix="." />
|
||||
<date-part name="year" />
|
||||
</date>
|
||||
<text variable="number" />
|
||||
</group>
|
||||
</else-if>
|
||||
|
||||
<!-- Generic fallback -->
|
||||
<else>
|
||||
<group delimiter=". ">
|
||||
<text macro="author" />
|
||||
<text macro="title" />
|
||||
<text variable="container-title" />
|
||||
<text macro="publisher" />
|
||||
<text macro="year" />
|
||||
<text macro="pages" />
|
||||
</group>
|
||||
</else>
|
||||
</choose>
|
||||
</group>
|
||||
</layout>
|
||||
</bibliography>
|
||||
</style>
|
||||
+4
-35
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user