Path: blob/main/llm-docs/pandoc-quarto-typst-templates.md
6446 views
Pandoc and Quarto Typst Templates
This document describes how Quarto integrates Pandoc's typst templates and transforms them into a more modular structure suitable for Quarto's extended functionality.
1. How Pandoc Templates Are Copied into Quarto
The writePandocTemplates function in package/src/common/update-pandoc.ts handles copying Pandoc's templates into Quarto's resources during the Pandoc update process.
Source and Destination
Source: Pandoc templates are downloaded from the Pandoc GitHub repository's
data/templates/directoryDestination:
src/resources/formats/typst/pandoc/
Files Copied
Two files are copied from Pandoc for typst support:
| Pandoc Source | Quarto Destination |
|---|---|
default.typst | typst.template |
template.typst | template.typst (unchanged name) |
Purpose of Each Pandoc File
default.typst (becomes typst.template): The main Pandoc template that orchestrates the document structure. It:
Defines a horizontal rule helper
Sets up term list rendering with indented descriptions
Configures table styling with no strokes
Sets figure caption positions for tables (top) and images (bottom)
Optionally includes syntax highlighting definitions
Either imports a user-provided template or inlines the
template.typstcontent via$template.typst()$Disables smart quotes if not enabled
Processes header-includes
Invokes the
conf()function with all document metadataRenders include-before content, TOC, body, bibliography, and include-after content
template.typst: Defines the conf() document function and helpers. It:
Provides a
content-to-stringhelper to extract text from content nodesDefines
conf()which accepts all document metadata parametersSets document metadata (title, keywords, author) for PDF accessibility
Configures page, paragraph, text, and heading settings
Applies link, reference, and file colors
Renders the title block with optional thanks footnote
Returns the document content
2. Quarto's Modular Template Structure
Quarto breaks the Pandoc templates into a modular structure in src/resources/formats/typst/pandoc/quarto/. This allows for:
Better separation of concerns
Easier customization and extension
Support for Quarto-specific features (brand typography, callouts, subfloats)
Template Files
The typstFormat function in src/format/typst/format-typst.ts configures the template context, specifying template.typ as the main template with these partials: definitions.typ, typst-template.typ, page.typ, typst-show.typ, notes.typ, and biblio.typ.
template.typ - The Orchestrator
Assembles the document by including all partials in order:
definitions.typ()- utility definitionstypst-template.typ()- the article functionHeader-includes loop
page.typ()- page configurationtypst-show.typ()- applies the article functionInclude-before loop
Body
notes.typ()- endnotes handlingbiblio.typ()- bibliographyInclude-after loop
definitions.typ - Utility Definitions
Combines Pandoc definitions with Quarto-specific functionality:
From Pandoc:
content-to-stringhelper to extract text from content nodes (used for PDF metadata and link colors)horizontalruledefinition for horizontal rulesTerm list show rule with indented descriptions
Code highlighting definitions (conditionally included)
Quarto additions:
endnotehelper for endnote renderingCode block styling (gray background, padding, rounded corners)
block_with_new_contenthelper for reconstructing blocks with modified contentemptyfunction to check if content is empty (handles strings and content nodes)Subfloat support via
quartosubfloatcounterandquarto_superfunction for nested figures with sub-numberingCallout figure show rule that transforms callout figures with proper titles and cross-reference numbering
calloutfunction for rendering callout boxes with customizable colors, icons, and styling
typst-template.typ - The Article Function
Corresponds to conf() in Pandoc's template.typst. Defines the article() function with these parameters:
Document Metadata (from Pandoc):
title,subtitle,authors,keywords,dateabstract-title,abstract,thanks
Layout (from Pandoc):
cols,lang,region
Typography (from Pandoc):
font,fontsize,mathfont,codefont,linestretch,sectionnumberinglinkcolor,citecolor,filecolor
Quarto Extensions:
title-size,subtitle-sizefor customizable title sizingheading-family,heading-weight,heading-style,heading-color,heading-line-heightfor brand typographytoc,toc_title,toc_depth,toc_indentfor integrated table of contents
Functionality:
Sets
document()metadata (title, keywords, author string) for PDF accessibilityConfigures paragraph justification and leading from
linestretchApplies conditional font settings using
set ... ifpattern (Typst 0.14+)Applies link colors using
content-to-stringhelperRenders the title block with thanks footnote, author grid, date, and abstract
Optionally renders table of contents
Handles single or multi-column layout
page.typ - Page Configuration
Extracted from Pandoc's conf() function to allow independent page setup:
Sets paper size (defaults to "us-letter")
Sets margins (defaults to x: 1.25in, y: 1.25in)
Sets page numbering
Sets column count
Optionally sets a background logo image with configurable location, inset, width, and alt text (Quarto extension)
typst-show.typ - Parameter Mapping
Applies the article() function via a show rule, mapping Pandoc metadata and brand.yaml values to parameters. Follows precedence rules where Pandoc metadata takes priority and brand.yaml provides fallbacks.
Pandoc Metadata Mappings:
title,subtitle,date,abstract→ direct pass-throughby-author→authors(uses Quarto's author normalization withit.name.literalandit.affiliations)labels.abstract→abstract-title(localized)mainfont→fontfontsize→fontsizemathfont→mathfontcodefont→codefontlinestretch→linestretchsection-numbering→sectionnumberingthanks→thankslinkcolor,citecolor,filecolor→ link color parameterskeywords→keywordstoc,toc-title,toc-depth,toc-indent→ TOC parameterscolumns→cols
Brand.yaml Fallbacks (used when Pandoc metadata not set):
brand.typography.base.family→fontbrand.typography.base.size→fontsizebrand.typography.monospace.family→codefontbrand.typography.headings.family→heading-familybrand.typography.headings.weight→heading-weightbrand.typography.headings.style→heading-stylebrand.typography.headings.color→heading-colorbrand.typography.headings.line-height→heading-line-height
notes.typ - Endnotes Section
Renders endnotes when present:
Adds vertical space and a horizontal rule
Sets smaller text size (0.88em)
Renders the notes content
biblio.typ - Bibliography
Handles bibliography rendering:
Sets bibliography style from CSL file or bibliography style option
Renders bibliography from specified files
typst.template - Reference Copy
This is the copy of Pandoc's default.typst, kept for reference. It is used when rendering without Quarto's template context (e.g., when a user provides a custom template).
3. Parameter Summary Table
| Pandoc Parameter | Quarto Parameter | Brand.yaml Fallback | Notes |
|---|---|---|---|
title | title | - | |
subtitle | subtitle | - | |
author | authors | - | Normalized via by-author |
keywords | keywords | - | Array of quoted strings |
date | date | - | |
abstract | abstract | - | |
abstract-title | abstract-title | labels.abstract | Localized |
thanks | thanks | - | Title footnote |
mainfont | font | brand.typography.base.family | |
fontsize | fontsize | brand.typography.base.size | |
mathfont | mathfont | - | |
codefont | codefont | brand.typography.monospace.family | |
linestretch | linestretch | - | Multiplied by 0.65em for leading |
section-numbering | sectionnumbering | - | |
linkcolor | linkcolor | - | Hex color string |
citecolor | citecolor | - | Hex color string |
filecolor | filecolor | - | Hex color string |
columns | cols | - | |
papersize | (in page.typ) | - | |
margin | (in page.typ) | - | |
page-numbering | (in page.typ) | - | |
| - | title-size | - | Quarto extension |
| - | subtitle-size | - | Quarto extension |
| - | heading-family | brand.typography.headings.family | Quarto extension |
| - | heading-weight | brand.typography.headings.weight | Quarto extension |
| - | heading-style | brand.typography.headings.style | Quarto extension |
| - | heading-color | brand.typography.headings.color | Quarto extension |
| - | heading-line-height | brand.typography.headings.line-height | Quarto extension |
toc | toc | - | |
toc-title | toc_title | - | |
toc-depth | toc_depth | - | |
toc-indent | toc_indent | - | Quarto extension |