Package Information
- Last Updated
- Minimum Typst Version
- 0.14.0
- Authors
- lucifer1004
- Categories
- utility
1. Get the package
Download the package using the TPIX CLI:
tpix get @preview/citrus:0.2.12. Import in your Typst file
Add this to your .typ file:
#import "@preview/citrus:0.2.1": *citrus đ
Fresh citations for Typst
A CSL (Citation Style Language) processor implemented in pure Typst.
Use standard CSL style files â the same format used by Zotero, Mendeley, and thousands of citation managers â to format your citations and bibliographies. Squeeze the zest out of your references!
Installation
#import "@preview/citrus:0.2.1": init-csl, csl-bibliography
Quick Start
#import "@preview/citrus:0.2.1": init-csl, csl-bibliography
#show: init-csl.with(
read("references.bib"),
read("style.csl"),
)
As demonstrated by @smith2020, this approach works well.
#csl-bibliography()
Features
- Standard CSL support â Parse and render using CSL 1.0.2 style files
- CSL-M extensions â Multilingual layouts, institutional authors, legal citations
- BibTeX input â Use your existing
.bibfiles via citegeist - CSL-JSON input â Native CSL-JSON format for lossless data transfer
- Bilingual support â Automatic language detection for mixed Chinese/English bibliographies
- Citation styles â Numeric, author-date, and note styles (footnotes auto-generated)
- Year disambiguation â Automatic a/b/c suffixes for same-author-same-year entries
- Citation collapsing â Numeric ranges
[1-4], year-suffix(Smith, 2020a, b) - Multiple citations â Combine citations with
multicite() - Uncited entries â Include bibliography entries without citing via
nocite() - Full formatting â Italics, bold, small-caps, text-case, and more
- Bibliography linking â Auto-link DOI, URL, PMID, PMCID in bibliography
Documentation
- English Documentation â Chicago style example
- ä¸ćć楣 â GB/T 7714-2025 style example
API Reference
init-csl
Initialize the CSL processor with BibTeX bibliography data and style.
#show: init-csl.with(
bib-content, // BibTeX file content (string)
csl-content, // CSL style file content (string)
locales: (:), // Optional: external locale files
auto-links: true, // Optional: auto-link DOI/URL/PMID/PMCID
)
init-csl-json
Initialize the CSL processor with CSL-JSON bibliography data. CSL-JSON is the native format for CSL processors â properties map directly to CSL variables, avoiding translation losses from BibTeX.
#import "@preview/citrus:0.2.1": init-csl-json, csl-bibliography
#show: init-csl-json.with(
read("references.json"), // CSL-JSON file content
read("style.csl"), // CSL style file content
locales: (:), // Optional: external locale files
auto-links: true, // Optional: auto-link DOI/URL/PMID/PMCID
)
As shown by @smith2023...
#csl-bibliography()
CSL-JSON format example:
[
{
"id": "smith2023",
"type": "article-journal",
"title": "Example Article",
"author": [{ "family": "Smith", "given": "John" }],
"container-title": "Journal of Examples",
"volume": "42",
"page": "1-10",
"issued": { "date-parts": [[2023, 5, 15]] },
"DOI": "10.1234/example"
}
]
Advantages of CSL-JSON over BibTeX:
- Properties map 1:1 to CSL variables (no translation needed)
- Names are pre-structured (
{"family": "...", "given": "..."}) - Dates use standard CSL format (
{"date-parts": [[2023, 5, 15]]}) - All CSL types supported directly
- Better for CSL-M extensions (
original-author,container-author, etc.)
csl-bibliography
Render the bibliography.
#csl-bibliography()
// Custom title:
#csl-bibliography(title: heading(level: 2)[References])
// Full custom rendering:
#csl-bibliography(full-control: entries => {
for e in entries [
[#e.order] #e.rendered-body #e.ref-label
#parbreak()
]
})
get-cited-entries
Low-level API for complete control over bibliography rendering.
context {
let entries = get-cited-entries()
for e in entries {
// Each entry provides:
// - key, order, year-suffix, lang, entry-type
// - fields, parsed-names
// - rendered (full), rendered-body (without number)
// - ref-label, labeled-rendered
}
}
multicite
Combine multiple citations.
// Using @key syntax (recommended â supports auto-completion):
#multicite[@smith2020 @jones2021 @wang2022]
// With page numbers:
#multicite[@smith2020[p. 42] @jones2021]
// Using string arguments:
#multicite("smith2020", "jones2021", "wang2022")
// With page numbers (string form):
#multicite(
(key: "smith2020", supplement: [p. 42]),
"jones2021",
)
nocite
Include bibliography entries without citing them in-text.
// Using @key syntax (recommended):
#nocite[@smith2020 @jones2021]
// Using string arguments:
#nocite("smith2020", "jones2021")
// Include all entries:
#nocite("*")
Supported CSL Elements
| Element | Status | Element | Status |
|---|---|---|---|
<text> |
â | <group> |
â |
<choose> |
â | <names> |
â |
<name> |
â | <date> |
â |
<number> |
â | <label> |
â |
<sort> |
â | <substitute> |
â |
CSL-M Support
This library includes support for key CSL-M (CSL Multilingual) extensions:
| Feature | Description |
|---|---|
| Multiple layouts | <layout locale="en es de"> for language-specific formatting |
| cs:institution | Institutional author handling with subunit parsing |
| cs:conditions | Nested condition groups with match="any/all/nand" |
| Legal types | legal_case, legislation, regulation, hearing, treaty |
| Legal variables | authority, jurisdiction, country, hereinafter |
| Date conditions | has-day, has-year-only, has-to-month-or-season |
| Context condition | context="citation" or context="bibliography" |
| Locale matching | Prefix matching: en matches en-US, en-GB, etc. |
| suppress-min/max | Suppress names by count, or separate personal/institutional |
| require/reject | require="comma-safe" for locator punctuation safety |
Built-in Locales
10 languages with automatic fallback:
en-US, zh-CN, zh-TW, de-DE, fr-FR, es-ES, ja-JP, ko-KR, pt-BR, ru-RU
Entry Type Handling
This library uses citegeist to parse BibTeX files. Most standard entry types are supported, but some extended types are not recognized by citegeist.
Supported Types (auto-detected)
article, book, booklet, inbook, incollection, inproceedings, conference, manual, mastersthesis, phdthesis, proceedings, techreport, unpublished, misc, online, patent, thesis, report, dataset, software, periodical, collection
Unsupported Types (require mark field)
For types not recognized by citegeist, use @misc with a mark field:
| Type | Mark | Notes |
|---|---|---|
| Standard | S |
@standard not recognized |
| Newspaper | N |
@newspaper not recognized |
| Legislation | LEGISLATION |
CSL-M legal type |
| Legal case | LEGAL_CASE |
CSL-M legal type |
| Regulation | REGULATION |
CSL-M legal type |
Note: Use @online instead of @webpage â citegeist supports @online but not @webpage.
Example:
@misc{gb7714,
mark = {S},
title = {Information and documentation â Rules for bibliographic references},
number = {GB/T 7714â2015},
publisher = {Standards Press of China},
year = {2015},
}
The mark field follows GB/T 7714 document type codes:
Mâ Book,Câ Conference,Nâ Newspaper,Jâ JournalDâ Thesis,Râ Report,Sâ Standard,Pâ PatentGâ Collection,EBâ Electronic resource,DBâ DatabaseAâ Analytic (chapter),Zâ Other
CSL 1.0.2 Specification Coverage
This library implements the full CSL 1.0.2 specification. Key features include:
Rendering Elements
| Element | Status | Notes |
|---|---|---|
cs:text |
â | Variables, macros, terms, values |
cs:number |
â | Numeric, ordinal, long-ordinal, roman forms |
cs:date |
â | Localized and non-localized date formatting |
cs:names |
â | Full name formatting with et-al, delimiter |
cs:name |
â | Name order, form, delimiter-precedes-* |
cs:name-part |
â | Per-part formatting (family/given) |
cs:label |
â | Variable labels with plural detection |
cs:group |
â | Conditional groups with delimiter |
cs:choose |
â | if/else-if/else conditions |
cs:substitute |
â | Fallback rendering for empty names |
Style Structure
| Element | Status | Notes |
|---|---|---|
cs:style |
â | Style metadata, class, locale |
cs:info |
â | Style information (parsed but not used) |
cs:locale |
â | Inline locale overrides |
cs:macro |
â | Reusable formatting macros |
cs:citation |
â | Citation formatting with layout |
cs:bibliography |
â | Bibliography formatting with layout |
cs:sort |
â | Sorting by variable or macro |
Disambiguation
| Feature | Status | Notes |
|---|---|---|
| Year suffixes (a, b, c) | â | Automatic for same-author-year |
| Add names | â | Expand truncated name lists |
| Add givenname | â | Show initials or full given names |
disambiguate condition |
â | CSL disambiguate="true" condition |
Bibliography Features
| Feature | Status | Notes |
|---|---|---|
subsequent-author-substitute |
â | Em-dash for repeated authors |
complete-all rule |
â | Substitute entire name list |
complete-each rule |
â | Per-name substitution |
partial-each rule |
â | Partial name matching |
partial-first rule |
â | First-name-only matching |
| Bibliography linking | â | Auto-link DOI/URL/PMID/PMCID |
| Hanging indent | â | Via hanging-indent attribute |
| Second-field-align | â | Label alignment modes |
Formatting & Affixes
| Feature | Status | Notes |
|---|---|---|
font-style |
â | italic, oblique, normal |
font-weight |
â | bold, light, normal |
font-variant |
â | small-caps, normal |
text-decoration |
â | underline, none |
text-case |
â | lowercase, uppercase, capitalize-*, title |
vertical-align |
â | sup, sub, baseline |
prefix/suffix |
â | Affixes on all elements |
delimiter |
â | Element and group delimiters |
quotes |
â | Locale-aware quotation marks |
strip-periods |
â | Remove periods from abbreviations |
Localization
| Feature | Status | Notes |
|---|---|---|
| Built-in locales | â | 10 languages with automatic fallback |
| External locales | â | Load via locales parameter |
| Ordinal suffixes | â | Full ordinal-00 to ordinal-99 support |
| Long ordinals | â | "first" through "tenth" with fallback |
| Term forms | â | long, short, verb, verb-short, symbol |
limit-day-ordinals |
â | Locale option for day ordinals |
Known Limitations
Bilingual Styles (CSL-M original-* variables)
Some Chinese citation styles (e.g., "ĺĺć ¸çŠçčŻčŽş") require bilingual output with both Chinese and English metadata. These styles use CSL-M extension variables like original-author, original-title which map to BibTeX fields with -en suffix (author-en, title-en, etc.).
Current status:
| Variable | CSL-JSON | BibTeX |
|---|---|---|
original-title, original-container-title, original-publisher, original-publisher-place |
â | â |
original-author, original-editor |
â | â |
display="block" attribute |
â | â |
BibTeX limitation: original-author and original-editor require citegeist to parse author-en/editor-en fields into parsed_names. Use CSL-JSON input for full bilingual name support.
CSL-M Extensions Not Implemented
The following CSL-M (Juris-M/Multilingual Zotero) extensions are not supported:
| Feature | Description |
|---|---|
parallel-first / parallel-last |
Parallel citation suppression for legal documents |
form="imperial" |
Japanese Imperial calendar date format |
commenter / contributor |
Additional name variables |
cs:court-class |
Court classification element |
track-containers / consolidate-containers |
Container tracking for legal citations |
subgroup-delimiter |
Publisher/publisher-place grouping |
year-range-format |
Separate year range collapsing format |
These features are primarily used for legal citation styles (Jurism). Standard academic CSL styles work correctly.
Related Projects
- citegeist â BibTeX parser for Typst
- CSL Styles Repository â Thousands of CSL styles
- Zotero Chinese Styles â Chinese CSL styles
License
MIT