Universe

In a book or a two-column paper set with LaTeX, every full page ends at the same height: the last line of each column sits exactly on the bottom margin. LaTeX calls this \flushbottom. Typst does not do this. It fills a page until the next line no longer fits and leaves the rest empty, so the columns of a Typst document end at slightly different heights.

Procrustes fixes this. It takes the space left over at the bottom of each full page or column and shares it out over the spaces inside it: between paragraphs, around headings, lists, equations and figures, and above floating figures at the bottom. The text then ends exactly at the bottom margin. (Procrustes, in the Greek myth, made every guest fit his bed. This package only stretches.)

The same two-column page set by Typst alone and with procrustes. Without it, the two columns end at different heights above the bottom margin; with it, both end exactly on the margin.

Procrustes never changes where Typst breaks a page or a column. It only moves the lines of a full page down. The last page of the document, and pages that end with #pagebreak(), stay as they are.

Getting started

Add procrustes after your template’s own show rule. This is all most documents need:

#import "@preview/charged-ieee:0.1.4": ieee
#import "@preview/procrustes:0.1.0": flush-bottom, glue

#show: ieee.with(title: [A paper])
#show: flush-bottom.with(
  paragraphs: glue(0pt, plus: 1pt),
  headings: level => (above: glue(0pt, plus: 2pt), below: glue(0pt, plus: 1pt)),
)
  • paragraphs says how willing the space between two paragraphs is to grow.
  • headings says the same for the space above and below a heading, by level.
  • The spaces around lists, equations, code, quotes, tables and figures, and above a floating figure at the bottom of a column, stretch too, by default with the same and twice the willingness as between paragraphs.

The numbers are glue, as in TeX: glue(0pt, plus: 1pt) is LaTeX’s 0pt plus 1pt. Only the ratios between the plus values matter: a space with plus: 2pt takes twice as much of the leftover space as one with plus: 1pt. Procrustes keeps the spacing your template already has and adds the stretch to it. It does not shrink spaces; the minus of LaTeX glue is accepted but ignored.

Procrustes needs Typst 0.15 or newer.

What to expect

On ordinary pages, the stretch is a few points per page and hard to see. Procrustes has been tested with 18 templates from Typst Universe and plain Typst in one and two columns, on 196 documents with different mixes of headings, lists, equations, figures and footnotes: 99% of the full columns end exactly at the bottom, and the page breaks are those of Typst.

Some things to know:

  • Loose pages. When a large figure or table does not fit on a page, everything left over goes into the few spaces of that page, and the gaps can get large. LaTeX does the same, but warns about an “underfull” page; Procrustes does not warn.
  • Nothing to stretch. A column with a single paragraph and no space to stretch stays short.
  • Templates with unusual spacing. If a template puts fixed spacing around its headings (v(...) without weak: true), or sets spacing inside a show rule that transforms an element, a column can end a few points short or a spacing can change slightly. With the template’s spacing set the usual way (weak: true, show-set rules), this does not happen.
  • Footnotes inside a columns(...) container. Typst places footnotes there differently as soon as a column contains any added space, so a line or a footnote can move to the next page. This is a matter of Typst, not of Procrustes.
  • One more layout pass. Procrustes looks at where Typst put things and then stretches, so Typst lays the document out once more than without it.

See the reference manual for more detailed usage instructions.

Templates: spaces at chosen points

A template can also put stretchable space exactly where its LaTeX counterpart has glue, for example around theorems or displayed quotes. Declare named kinds of space and call stretch-before and stretch-after in the element’s show rule:

#import "@preview/procrustes:0.1.0": *

#show: flush-bottom.with(stretch: (extract: glue(12pt, plus: 2pt)))

#show quote.where(block: true): it => {
  stretch-before("extract")
  context block(above: natural("extract"), below: natural("extract", side: "below"),
    [#it.body#end-mark])
  stretch-after("extract")
}

Acknowledgments

The zero-height blocks with which procrustes keeps the natural spacing around lists, equations and other elements, while adding stretch next to them, are an idea from faithful-acmart by Fabian Zaiser.