Show borders around the main text area, header and footer in Typst documents.
This may be useful to understand and debug layout issues.
The idea is similar to the LaTeX showframe
package.
Additionally, some internal functions for resolving page and margin dimensions are exposed since they might be useful beyond this package.
The main entry point is the scaffolding method, which renders a grid to
indicate text area, header and footer. It should be placed in the page's
background:
#import "@preview/scaffolder:0.2.1": scaffolding
#set page(paper: "a6")
#set page(background: scaffolding())
#lorem(100)
#pagebreak()
#set page(
background: scaffolding(stroke: blue + 1pt),
columns: 2,
)
#lorem(100)The following methods resolve the actual values of some parameters related to layout:
get-text-dir: Resolvestext.dirto eitherltrorrtl.get-page-binding: Resolvespage.bindingto eitherleftorright.get-page-margins: Resolvespage.marginto a dictionary with keysleft,right,topandbottom.
All of the require context:
#import "@preview/scaffolder:0.2.1": get-text-dir, get-page-binding, get-page-margins
#context {
let dir = get-text-dir()
let binding = get-page-binding()
let margins = get-page-margins()
}
The following limitations are known, PRs to address them are always welcome!:
- (none)
The following are some ideas of functionality that might be added or improved in this package:
- Further separate measuring and rendering steps in the implementation.
This would allow to make the rendering more customizable
e.g. like the cross markers in this related
tex.SEquestion, or by not having contiguous lines but just rectangles around the main and margin text areas.
The following Typst issues and forum post inspired this package and informed its design and implementation:
A more general visual debug mode for Typst has also been proposed in typst/#5226.
- the
layoutpackage shows the page dimensions - the
showframepackage - the
geometrypackage used as\usepackge[showframe,pass]{geometry} - a related
tex.SEquestion