Typst or LaTeX?
Styling PDF documents with Quarto extensions
Nicola Rennie, Lancaster University
satRdays London, 27 April 2024
Academic background in statistics and operational research.
Experience in statistics/data science consultancy.
Lecturer in Health Data Science in Lancaster Medical School.
Research interests: reproducible research, modelling healthcare data, research software engineering, communicating data effectively, …
Creating PDF documents with Quarto
Styling PDF documents
The pros and cons of Typst and LaTeX for PDFs
Combining R outputs with different types of PDF
Documents from different authors look the same.
Default options usually look like the default options.
It’s easier to read stuff that looks nice.
I don’t really like PDFs…
…but if I have to make them, I make them with Quarto.
Quarto is an open-source scientific and technical publishing system that allows you to combine text, images, code, plots, and tables in a fully-reproducible document.
Quarto has support for multiple languages including R, Python, Julia, and Observable.
It also works for a range of output formats such as PDFs, HTML documents, websites, presentations, …
LaTeX or Typst?
See quarto.org/docs/reference/formats/pdf for all PDF options.
LaTeX is a software system for typesetting documents, that separates out the content from the styling.
Quarto (and R Markdown) use it to convert from .qmd to .pdf files (with help from Pandoc and {knitr}).
document.qmd
Quarto extensions are a powerful way to modify and extend the behavior of Quarto. Extensions can be used to add styling to your documents.
Extensions aren’t just used to change document styling. There are also extensions to:
Install (e.g. from GitHub):
---
title: "Pretty PDFs with Quarto"
format: PrettyPDF-pdf
---
## Quarto
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.
### Running Code
When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
```r
1 + 1
```
You can add options to executable code like this
```r
#| echo: false
2 * 2
```
The `echo: false` option disables the printing of code (only output is displayed).
Tables with {knitr}
Tables with {kableExtra}
Tables with {gt}
{gt} supports the HTML, LaTeX, and RTF output formats.
You need to install it separately from Quarto
Errors are often hard to understand or debug
It can be quite slow to render documents
If only there was another way …
Typst is a markup-based typesetting system that is designed to be as powerful as LaTeX while being much easier to learn and use which has been around since late December 2022.
It comes with Version 1.4+ of Quarto.
See quarto.org/docs/reference/formats/typst for all Typst options.
Quarto extensions for Typst work similarly:
format
in the YAMLExample: dept-news
(by Quarto team)
Choosing between types of PDF
Similar PDF styling implemented with LaTeX (left) and Typst (right)
LaTeX
\usepackage{geometry}
\usepackage{eso-pic}
\usepackage{xcolor}
\geometry{a4paper, total={170mm,257mm}, left=20mm, top=20mm, bottom=20mm, right=50mm}
\definecolor{light}{HTML}{E6E6FA}
\AddToShipoutPicture{%
\AtPageLowerLeft{%
\put(\LenToUnit{\dimexpr\paperwidth-3cm},0){%
\color{light}\rule{3cm}{\LenToUnit\paperheight}}%
}%
}%
Reasons to use LaTeX:
You want to include equations (currently easier in LaTeX)
(Currently) more flexibility with images and tables
Most journals are not (yet) ready for Quarto or Typst
You already know LaTeX, and have built lots of stuff using it
Reasons to use Typst:
Easier to learn (personal opinion!)
More informative error messages
No extra installations
Speed
Typst & Quarto blog: https://nrennie.rbind.io/blog/making-pdf-with-quarto-typst-latex/
LaTeX & Quarto blog: https://nrennie.rbind.io/blog/making-pretty-pdf-quarto/
Typst documentation: typst.app/docs/guides
LaTeX help: www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes
Quarto documentation: quarto.org