Skip to content

About

A Quarto extension for creating PDF documents with Typst

Topics

Resources

Stars

110 stars

Watchers

4 watching

Forks

Repository files navigation

quarto-preprint

A Quarto extension for creating PDF documents with Typst.

Examples

Default output theme: jou output
Full-width content Single-column appendices

Overview

“An article about computational science in a scientific publication is not the scholarship itself, it is merely advertising of the scholarship. The actual scholarship is the complete software development environment and the complete set of instructions which generated the figures.”

–Buckheit and Donoho (1995, paraphrasing Jon Claerbout)

Quarto is "An open-source scientific and technical publishing system" for writing reproducible documents that combine computations and prose written in markdown into HTML, PDF, Word, and other outputs. For many R users, Quarto is a successor of R Markdown but with a broader scope and better support for different output formats and computational content in other languages.

quarto-preprint is a Quarto extension that provides the preprint-typst output format. When using this format, Quarto renders your document into PDF using Typst, a modern replacement for LaTeX. preprint-typst builds on the standard Quarto Typst template and enables separated author-affiliation formatting, additional metadata variables for scholarly writing, opinionated but customizable typesetting, improved two-column layouts (including full-width floats), appendices, and more. In addition, preprint-typst aims to

  • Be fast: Typst creates PDF files very quickly
  • Just Work: No LaTeX installation required (Typst ships with Quarto)
  • Be 100% Quarto compatible: Switch between output formats without changing content
  • Have rich features: Separated author-affiliation formatting, two-column layouts, full-width floats, appendices

Note that quarto-preprint is the name of the Quarto extension, and preprint-typst is the name of the Quarto output format.

Installation

Add to existing Quarto project

quarto add mvuorre/quarto-preprint

This creates a _extensions/preprint/ directory in your project. The preprint-typst format is then ready to use.

Start new Quarto project

quarto use template mvuorre/quarto-preprint

This creates a new project directory with a starter document, _quarto.yml configuration file, and example bibliography.bib file.

Updating

When you are in a project that already uses this extension, you can update the extension with

quarto update extension mvuorre/quarto-preprint

Configuration

Quarto document output is configured through YAML front matter metadata. To use preprint-typst as the output format, include format: preprint-typst in the front matter. Here is a minimal example that specifies a title, a table of contents, and two output formats:

---
title: "My Paper"
toc: true
format:
  preprint-typst:
    wordcount: true
  html:
    theme: cosmo
---

Your content here...

Front matter variables can be shared across output formats (such as toc above) or specific to them (like wordcount above). See Quarto’s guide to writing scholarly documents and Quarto’s Typst format documentation.

preprint-typst supports all of Quarto’s YAML front matter variables for scholarly writing and Typst documents. Below, we document the additional variables supported by preprint-typst.

preprint-typst extension options

preprint-typst enables these custom variables for Typst output:

  • running-head (string) - Short title text displayed in page headers
    • Example: running-head: "Short Title"
  • authornote (string) - Text appearing after corresponding author information
    • Example: authornote: "Author affiliations and contact"
  • wordcount (boolean) - Display word count below abstract
    • Example: wordcount: true
    • Counts the main text's prose, including headings and footnotes. Code, tables, figures and their captions, equations, the reference list, the abstract, and appendices are not counted. Citations are counted with citeproc: true, because Pandoc writes them as plain text. Callouts are counted, except cross-referenced ones.
  • hide-abstract-title (boolean) - Hide the abstract heading by default; set to false to show Quarto's standard abstract label
    • Example: hide-abstract-title: false
  • theme (string) - Select a theme ("default", "jou")
    • Example: theme: jou creates an optimized two-column layout (10pt text, narrower margins)
    • Explicit fontsize, columns, and margin settings take precedence over the theme
  • functions (array) - Enable Typst functions in Quarto divs [typst-function]
    • Example: functions: ["place"]

Typography

  • mathfont (string) - Font family for equations [Quarto]
    • Example: mathfont: "New Computer Modern Math"
  • codefont (string) - Font family for code [Quarto]
    • Example: codefont: "Monaco"
  • linkcolor (hex code) - Color for hyperlinks [Quarto, Typst]
    • Example: linkcolor: "#0066cc"
  • citecolor (hex code) - Color for citations and cross-references when Typst handles them [Quarto]
    • Example: citecolor: "#0066cc"
  • filecolor (hex code) - Color for internal label links [Quarto]
    • Example: filecolor: "#444444"

Branding

preprint-typst supports Quarto's brand.yml (_brand.yml) to the same extent as Quarto's built-in Typst format. Explicit document metadata (e.g. mainfont, fontsize, linkcolor) takes precedence over brand settings.

Note that Quarto's logo default placing and size renders the logo over the title. Use Quarto's logo options to fix the logo's placement, e.g.

format:
  preprint-typst:
    logo:
      location: right-top
      padding-right: 0.15in

Layout

  • line-number (boolean) - Enable line numbers [Typst]
    • Example: line-number: true
    • This is simplified to a boolean instead of allowing custom numbering as per Typst.
  • linestretch (number) - Multiplier for line spacing [Quarto, Typst]
    • Multiplies Typst's default leading (0.65em), same as Quarto.
    • The default is 10/13 (0.5em leading); 1 would be Typst's default, looser spacing
    • Example: linestretch: 1.1
  • spacing (string) - Vertical spacing between paragraphs [Typst]
    • Example: spacing: "0.6em"
  • first-line-indent (string) - Indentation for paragraph first lines [Typst]
    • Example: first-line-indent: "1.8em"
  • all (boolean) - Whether to indent all paragraphs (including first in section) [Typst]
    • Example: all: false
  • col-gutter (string) - Horizontal spacing between columns [Typst]
    • Example: col-gutter: "4.2%" or col-gutter: "2em"
  • Margin content works as in Quarto's Typst format.
    • Note: any margin content, even a single .column-margin div or reference-location: margin, switches the document to one column, also with theme: jou. Set columns: 2 explicitly to keep two (narrow) columns.

Language

  • lang (string) - Document language [Quarto, Typst]
    • Example: lang: "en" or lang: "de"
  • region (string) - Document region [Quarto, Typst]
    • Example: region: "US" or region: "GB"
  • Labels ("Appendix", "Keywords", ...) follow lang where Quarto has a translation. Change any label with Quarto's language option. Besides Quarto's own keys (e.g. crossref-apx-prefix, title-block-keywords, or section-title-references, which titles Typst's reference list), preprint-typst uses these, which have no translations:
    • preprint-words: word count label ("Words")
    • preprint-correspondence: "Send correspondence to:"
    • preprint-equal-contribution: "{0} contributed equally to this work.", where {0} is replaced by the author names
    • Note callouts are labelled "Box" (see Boxes)

Bibliography & citations

Using Typst's own citation processing

Typst has its own citation processing system. Set its style with bibliographystyle (default: apa) or csl, and the title of its reference list with the section-title-references language label.

Using Pandoc (recommended)

However, to allow better bibliography customization via the csl YAML variable, and use of Quarto’s #refs div, you must use Pandoc's citation processing with citeproc: true. When citeproc: true, you can load a CSL file directly from an URL, and add the References section anywhere in your document (e.g. before any appendices) using Quarto’s #refs div:

# References

::: {#refs}
:::

to display the bibliography section anywhere in the document (for example, before any appendices).

Note. There is currently a bug in Typst whereby some CSL styles aren't properly applied (typst/typst#2639). For example, the APA style lacks hanging indents. Until this is fixed in Typst, you can customize the display of the references section by including custom Typst code that targets any blocks in the document. For example, to add hanging indents, write:

format:
  preprint-typst:
    include-before-body:
      - text: "#show <refs>: set par(hanging-indent: 1.4em)"

Citation management

Quarto documents require citations in a separate .bib file. The vscode-zotero VS Code plugin helps with inserting in-text citations and managing the .bib file. The plugin works in all VS Code based editors, including Positron.

Extra features

Boxes

In preprint-typst, Quarto note callouts render as understated grayscale boxes labelled "Box" ("Box 1" when cross-referenced with an #nte- id). Other callout types keep Quarto's styling. To use a different label, set Quarto's language strings callout-note-title, crossref-nte-prefix, and crossref-note-prefix.

::: {#nte-boxes .callout-note}
## This is a box
Boxes, like all callouts, have no icon by default. Use `icon=true` to show one.
:::

See @nte-boxes.

Full-width content

You can include page-wide figures (or any other content) in documents that have more than one column. To do so, wrap the content in a Quarto div like this:

::: {.place arguments='top, scope: "parent", float: true'}
Any content here will span the whole page.
:::

The above uses the Typst’s place() function through the typst-function Quarto extension to place the div’s content in "parent" scope (the document page is the column’s parent) and must specify that Typst should treat the content as a float. The first argument top specifies that the content should be placed on the top of the page; use bottom to place it on the bottom.

Since this feature uses a Quarto div, if you want to include further divs inside this div, use more colons. For example:

:::: {.place arguments='top, scope: "parent", float: true'}

::: {#fig-wide fig-cap="Full-width figure"}
{{< placeholder 600 200 format=svg >}}
:::

Other full-width content. Note linebreaks here (between the colons and content) are important.

::::

Note: The function only takes effect in Typst documents, other formats (e.g. HTML) will display the content with no extra formatting.

Appendices

To include an appendix, include the following raw Typst block in your Quarto document, followed by your appendix content:

```{=typst}
#show: appendix.with()
```

# Appendix title

Appendix content.

(The heading above would render as "Appendix A: Appendix title". A heading titled # Appendix renders as "Appendix A". Figures, tables, listings, equations, and callouts are numbered separately within each appendix, e.g. "Figure A1", "Figure A1a", "Equation A1", "Box A1".)

Note: If you want the appendix to appear as an appendix in HTML output as well, add the .appendix class to the headings. Appendices are an experimental feature. They are provided through a custom Typst function, and their implementation and functionality may change as Quarto’s Typst integration matures.

Get help & contribute

Send your comments, bug reports, and pull requests to https://github.com/mvuorre/quarto-preprint. If you're reporting a bug, please include a reproducible example / full details of what you’re trying to do, how, and what goes wrong. If you want to submit an improvement, please submit an issue before submitting a pull request.

Testing

make test renders example.qmd and every tests/*/index.qmd, checks the expect: entries in their front matter, and writes _build/<timestamp>/report.html with any failures, warnings, and every page that changed since main (set another git ref with make test REF=v1.6.0). Requires uv.

About

A Quarto extension for creating PDF documents with Typst

Topics

Resources

Stars

110 stars

Watchers

4 watching

Forks

Releases

Contributors

Languages