Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configuration
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
export DENO=v2.4.5
# TODO figure out where 0.1.41 apple silicon libs are available
export DENO_DOM=v0.1.41-alpha-artifacts
export PANDOC=3.6.3
export PANDOC=3.8.3
export DARTSASS=1.87.0
export ESBUILD=0.25.10
export TYPST=0.13.0
export TYPST=0.14.2


# NB: we can't put comments in the same line as export statements because it
Expand Down
24 changes: 22 additions & 2 deletions dev-docs/update-pandoc-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@

Carlos needs to run this:

- [ ] Ensure archives are upgraded
- [ ] Run `AWS_PROFILE=... ./package/src/quarto-bld update-pandoc PANDOC_VERSION`
- [x] Ensure archives are upgraded
- [x] Run `AWS_PROFILE=... ./package/src/quarto-bld update-pandoc PANDOC_VERSION`
- [ ] look at `git diff`, specifically for changes in Pandoc templates, and adjust as needed.

As a reminder, our templates are kept in the same directories as Pandoc's templates, but with different names. `git diff` will show the diff in Pandoc's template; we have to manually patch
ours. (We can't just use `patch` because the templates have diverged too much)

### Pandoc templates

The general rule for the naming is that "format.template" indicates Pandoc naming, and "template.format" indicates ours. Examples below:

#### beamer

- Pandoc's: src/resources/formats/beamer/pandoc/beamer.template
- Ours: src/resources/formats/beamer/pandoc/template.tex

Partials:

- Pandoc's:
- src/resources/formats/beamer/pandoc/latex.common
- Ours:
- src/resources/formats/beamer/pandoc/common.latex


## Manual steps

- [ ] Update schemas by inspecting [their changelog](https://github.com/jgm/pandoc/blob/main/changelog.md) for new commands, deprecation removals, etc
Expand Down
210 changes: 210 additions & 0 deletions llm-docs/pandoc-quarto-typst-templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# 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/` directory
- **Destination**: `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.typst` content via `$template.typst()$`
- Disables smart quotes if not enabled
- Processes header-includes
- Invokes the `conf()` function with all document metadata
- Renders include-before content, TOC, body, bibliography, and include-after content

**template.typst**: Defines the `conf()` document function and helpers. It:
- Provides a `content-to-string` helper to extract text from content nodes
- Defines `conf()` which accepts all document metadata parameters
- Sets 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:
1. `definitions.typ()` - utility definitions
2. `typst-template.typ()` - the article function
3. Header-includes loop
4. `page.typ()` - page configuration
5. `typst-show.typ()` - applies the article function
6. Include-before loop
7. Body
8. `notes.typ()` - endnotes handling
9. `biblio.typ()` - bibliography
10. Include-after loop

### definitions.typ - Utility Definitions

Combines Pandoc definitions with Quarto-specific functionality:

**From Pandoc**:
- `content-to-string` helper to extract text from content nodes (used for PDF metadata and link colors)
- `horizontalrule` definition for horizontal rules
- Term list show rule with indented descriptions
- Code highlighting definitions (conditionally included)

**Quarto additions**:
- `endnote` helper for endnote rendering
- Code block styling (gray background, padding, rounded corners)
- `block_with_new_content` helper for reconstructing blocks with modified content
- `empty` function to check if content is empty (handles strings and content nodes)
- Subfloat support via `quartosubfloatcounter` and `quarto_super` function for nested figures with sub-numbering
- Callout figure show rule that transforms callout figures with proper titles and cross-reference numbering
- `callout` function 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`, `date`
- `abstract-title`, `abstract`, `thanks`

**Layout** (from Pandoc):
- `cols`, `lang`, `region`

**Typography** (from Pandoc):
- `font`, `fontsize`, `mathfont`, `codefont`, `linestretch`, `sectionnumbering`
- `linkcolor`, `citecolor`, `filecolor`

**Quarto Extensions**:
- `title-size`, `subtitle-size` for customizable title sizing
- `heading-family`, `heading-weight`, `heading-style`, `heading-color`, `heading-line-height` for brand typography
- `toc`, `toc_title`, `toc_depth`, `toc_indent` for integrated table of contents

**Functionality**:
- Sets `document()` metadata (title, keywords, author string) for PDF accessibility
- Configures paragraph justification and leading from `linestretch`
- Applies conditional font settings using `set ... if` pattern (Typst 0.14+)
- Applies link colors using `content-to-string` helper
- Renders 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-through
- `by-author` → `authors` (uses Quarto's author normalization with `it.name.literal` and `it.affiliations`)
- `labels.abstract` → `abstract-title` (localized)
- `mainfont` → `font`
- `fontsize` → `fontsize`
- `mathfont` → `mathfont`
- `codefont` → `codefont`
- `linestretch` → `linestretch`
- `section-numbering` → `sectionnumbering`
- `thanks` → `thanks`
- `linkcolor`, `citecolor`, `filecolor` → link color parameters
- `keywords` → `keywords`
- `toc`, `toc-title`, `toc-depth`, `toc-indent` → TOC parameters
- `columns` → `cols`

**Brand.yaml Fallbacks** (used when Pandoc metadata not set):
- `brand.typography.base.family` → `font`
- `brand.typography.base.size` → `fontsize`
- `brand.typography.monospace.family` → `codefont`
- `brand.typography.headings.family` → `heading-family`
- `brand.typography.headings.weight` → `heading-weight`
- `brand.typography.headings.style` → `heading-style`
- `brand.typography.headings.color` → `heading-color`
- `brand.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 |
8 changes: 4 additions & 4 deletions src/command/check/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,16 @@ async function checkVersions(conf: CheckConfiguration) {
// with our installers
const checkData: [string | undefined, string, string][] = strict
? [
[pandocVersion, "3.6.3", "Pandoc"],
[pandocVersion, "3.8.3", "Pandoc"],
[sassVersion, "1.87.0", "Dart Sass"],
[denoVersion, "2.4.5", "Deno"],
[typstVersion, "0.13.0", "Typst"],
[typstVersion, "0.14.0", "Typst"],
]
: [
[pandocVersion, ">=3.6.3", "Pandoc"],
[pandocVersion, ">=3.8.3", "Pandoc"],
[sassVersion, ">=1.87.0", "Dart Sass"],
[denoVersion, ">=2.3.1", "Deno"],
[typstVersion, ">=0.13.0", "Typst"],
[typstVersion, ">=0.14.0", "Typst"],
];
const fun = strict ? strictCheckVersion : checkVersion;
for (const [version, constraint, name] of checkData) {
Expand Down
49 changes: 0 additions & 49 deletions src/execute/engine-shared.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/execute/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
ExecutionTarget,
kQmdExtensions,
} from "./types.ts";
import { languagesInMarkdown } from "./engine-shared.ts";
import { languagesInMarkdown } from "../core/pandoc/pandoc-partition.ts";
import { languages as handlerLanguages } from "../core/handlers/base.ts";
import { RenderContext, RenderFlags } from "../command/render/types.ts";
import { mergeConfigs } from "../core/config.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/execute/ojs/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import { logError } from "../../core/log.ts";
import { breakQuartoMd, QuartoMdCell } from "../../core/lib/break-quarto-md.ts";

import { MappedString } from "../../core/mapped-text.ts";
import { languagesInMarkdown } from "../engine-shared.ts";
import { languagesInMarkdown } from "../../core/pandoc/pandoc-partition.ts";

import {
pandocBlock,
Expand Down
15 changes: 12 additions & 3 deletions src/resources/filters/quarto-post/typst-brand-yaml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ function render_typst_brand_yaml()
end
end

-- monospace font family is handled by codefont in typst-template.typ via typst-show.typ
-- here we only handle properties that Pandoc doesn't support: weight, size, color
local monospaceInline = _quarto.modules.brand.get_typography(brandMode, 'monospace-inline')
if monospaceInline and next(monospaceInline) then
quarto.doc.include_text('in-header', table.concat({
'#show raw.where(block: false): set text(',
conditional_entry('font', monospaceInline.family and _quarto.modules.typst.css.translate_font_family_list(monospaceInline.family), false),
conditional_entry('weight', _quarto.modules.typst.css.translate_font_weight(monospaceInline.weight)),
conditional_entry('size', monospaceInline.size, false),
conditional_entry('fill', monospaceInline.color, false),
Expand All @@ -189,11 +190,12 @@ function render_typst_brand_yaml()
}))
end

-- monospace font family is handled by codefont in typst-template.typ via typst-show.typ
-- here we only handle properties that Pandoc doesn't support: weight, size, color
local monospaceBlock = _quarto.modules.brand.get_typography(brandMode, 'monospace-block')
if monospaceBlock and next(monospaceBlock) then
quarto.doc.include_text('in-header', table.concat({
'#show raw.where(block: true): set text(',
conditional_entry('font', monospaceBlock.family and _quarto.modules.typst.css.translate_font_family_list(monospaceBlock.family), false),
conditional_entry('weight', _quarto.modules.typst.css.translate_font_weight(monospaceBlock.weight)),
conditional_entry('size', monospaceBlock.size, false),
conditional_entry('fill', monospaceBlock.color, false),
Expand Down Expand Up @@ -307,7 +309,7 @@ function render_typst_brand_yaml()
inset = '0.75in'
end
logoOptions.width = _quarto.modules.typst.css.translate_length(logoOptions.width or '1.5in')
logoOptions.inset = inset
logoOptions.inset = pandoc.RawInline('typst', inset)
logoOptions.location = logoOptions.location and
location_to_typst_align(logoOptions.location) or 'left+top'
quarto.log.debug('logo options', logoOptions)
Expand Down Expand Up @@ -356,6 +358,13 @@ function render_typst_brand_yaml()
['line-height'] = line_height_to_leading(headings['line-height'] or base['line-height']),
}
end

local monospace = _quarto.modules.brand.get_typography(brandMode, 'monospace')
if monospace and monospace.family then
meta.brand.typography.monospace = {
family = pandoc.RawInline('typst', _quarto.modules.typst.css.translate_font_family_list(monospace.family)),
}
end
return meta
end,
}
Expand Down
Loading
Loading