Skip to content

Proposal: change leading option to line-height #4224

@peng1999

Description

@peng1999

I propose deprecating the par.leading option, and add a par.line-height option instead.

Motivation

The current leading model do not persist baseline distance

Current leading model specifies the space between bottom edge of last line and top edge of the next line. This is fine when every line frame is of the same height but becomes undesirable when some lines become taller. See #1028 (comment) for example. To alleviate the problem, currently Typst hacks into the bounding box of inline formula. However, this workaround is not ideal as it leads to the exact issues described in #1028 and lacks a straightforward solution.

Furthermore, line spacing becomes uneven when text with different size appeared in paragraph. No proper solution exists under current leading model.

Typst:
image

LaTeX:
image

The current leading model is confusing and inconsistent with precedence

Typst define leading as “The spacing between lines”. However, other typesetting software such as Adobe InDesign and Affinity Publisher use the term “leading” to refer to the distance between text baselines. Other typesetting systems like CSS, LaTeX, and Microsoft Word do not employ the term “leading”, yet they all relate line spacing to the distance between baselines.

Typography guidelines (example) consider line spacing in terms of baseline distance too.

Proposal

Deprecate the leading option and introduce a new option called line-height, which represents the basic distance between baselines. leading can be removed in the future version along with locate function.

For each line frame $L_i$, define $H_i$ as the distance from the top edge to the baseline (height), and $D_i$ as the distance from the baseline to the bottom edge (depth). During layout processes, Typst should insert a blank frame of height $x$ between two lines, $L_1$ and $L_2$. The height of this frame is determined by:
$$x = \max(0, s - D_1 - H_2)$$
where $s$ represents the line-height value. Essentially, we maintain consistent baseline spacing unless there is an collision.

In the future, an additional option min-line-gap$=g$ can be added, changing the above formula to
$$x = \max(g, s - D_1 - H_2).$$
See below for the explanation of $g$.

Alternative

The TeX model

(Reference: The TeXBook, p.77-80)

TeX employs the following formula:

$$x = \begin{cases}s - D_1 - H_2, &s - D_1 - H_2 \geq l\\g, &\text{otherwise}\end{cases}$$

where $x$ is the space inserted between lines, and $s$, $l$, $g$ corresponds to \baselineskip, \lineskiplimit and \lineskip respectively. Notably the first formula presented in Proposal section is a special case where $l = g = 0$. So the proposed formula is compatible to the LaTeX algorithm.

#1028 (comment) demonstrated an instance of the model in Typst where $s=14\text{pt}, l=0,$ and $g=1\text{pt}$.

The InDesign model

From InDesign's document:

The default auto-leading option sets the leading at 120% of the type size. […] By default, leading is a character attribute, which means that you can apply more than one leading value within the same paragraph. The largest leading value in a line of type determines the leading for that line.

This model is not suitable for Typst because it do not play well with inline formulas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    change requestA proposal for changes to an existing featurelayoutRelated to the layout category, which is about composing, positioning, etc.textRelated to the text category, which is all about text handling, shaping, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions