Skip to content

Instantly share code, notes, and snippets.

@m13253
Last active August 7, 2026 21:54
Show Gist options
  • Select an option

  • Save m13253/dc14fbdae1e8fda3d63ba069b5ec4a44 to your computer and use it in GitHub Desktop.

Select an option

Save m13253/dc14fbdae1e8fda3d63ba069b5ec4a44 to your computer and use it in GitHub Desktop.
Matching the line spacings between Typst and LaTeX

Matching the line spacings between Typst and LaTeX

Reference LaTeX document:

\documentclass[a4paper,11pt]{article}

\usepackage[a4paper,margin=1in]{geometry}
\usepackage{lipsum}
\usepackage{setspace}
\pagestyle{empty}

\begin{document}
    \doublespacing
    Paragraph \#1: \lipsum[1][1-4]

    Paragraph \#2: \lipsum[1][1-4]
\end{document}

We replicate it using Typst:

#let tex-pt = 7200pt / 7227
// LaTeX's default \baselineskip = 13.6pt
// \doublespacing sets 1.618× stretch
// This makes a stretched \baselineskip ≈ 2.000436em
#let tex-baseline-skip = 13.6 * tex-pt * 1.618
#let tex-parskip = 0pt
// Computer Modern's exact capital height, taken from the font file
#let cm-cap-height = 0.683em

// LaTeX's default \topskip = 1em
// Typst's default \topskip = 1 cap-height
// Suppose we want a equivalence of LaTeX's 1in margin in Typst, we need to add 0.317em to top:
#set page(paper: "a4", margin: (top: 1in + 11 * tex-pt * (1 - 0.683), rest: 1in))

#set par(
  first-line-indent: (amount: 17 * tex-pt, all: true),
  justify: true,
  leading: tex-baseline-skip - cm-cap-height,
  spacing: tex-parskip + tex-baseline-skip - cm-cap-height,
)
#set text(font: "New Computer Modern", size: 11 * tex-pt, hyphenate: true)

Paragraph \#1: #lorem(30)

Paragraph \#2: #lorem(30)

An alternative method is to set top-edge to your desired \baselineskip and keep leading as 0pt. That method can be simpler, but sometimes causes troubles when you need to align something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment