Repository navigation
Description
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.
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
where line-height value. Essentially, we maintain consistent baseline spacing unless there is an collision.
In the future, an additional option min-line-gap
See below for the explanation of
Alternative
The TeX model
(Reference: The TeXBook, p.77-80)
TeX employs the following formula:
where \baselineskip, \lineskiplimit and \lineskip respectively. Notably the first formula presented in Proposal section is a special case where
#1028 (comment) demonstrated an instance of the model in Typst where
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.


Activity
Enivex commentedon May 22, 2024
Allow different elements on the line to have different values of leading, with the largest "element height + leading" determining the line height. Inline equations could have zero or minimal leading.
That being said, I'm not convinced that the current model is better either. Just saying that there are (at least partial) solutions within the current framework.
Enter-tainer commentedon May 22, 2024
i think it is how current model works? the problem is that, once the "largest element" becomes too large, you no longer want to use the original leading(which is designed for not-so-large cases), but a much smaller value, like 1pt. And that is why inline math are pretending if they are actually smaller.
Enivex commentedon May 22, 2024
Why couldn't it just always be 1 pt for inline math then? (Disregarding lines solely composed of inline math)
Enter-tainer commentedon May 22, 2024
i havent think in detail and im not sure if it is a good idea. i personally perfer @peng1999 's because the idea behind is backed by *TeX and is battle tested.
One thing to notice is that "changing the spacing model" sounds difficult but actually doesnt need change a lot of code, at least for the demo in #1028 (comment), the changeset is very small and straight forward. I've also search all occurance of "leading" and found that there isnt too much usage.
Enter-tainer commentedon May 23, 2024
Sorry i didn't read this yesterday.
This sounds even more complicated than any model mentioned here. IIUC spacing models mentioned here(apart from in design) all have a single leading/line-height within a paragraph. And the one you mentioned, can set different leading for every element.
But i'm not sure what it will looks like in typst. Currently
leadingis only defined inpar. Should we addleadingto all other elements liketext,equation(and set leading automatically depending on if it's inline/block)? I feel like it is not a good user interface.Another thing to notice is that
leadingin InDesign actually meansline-heightlaurmaedje commentedon May 23, 2024
Will leave a comment here once I've had the chance to discuss this with @reknih. I'll try to recover the original reasoning for the current model.
Andrew15-5 commentedon May 25, 2024
Related: #159, #1221.
The (good-enough) solution I currently use everywhere: #159 (comment).
laurmaedje commentedon Jun 3, 2024
The current model
Let me first lay out our original thoughts behind the thoughts behind our original design:
Text and its surrounding containers should interact in a nice, evenly-spaced manner: If you write
#rect(fill: aqua, inset: 5pt)[Hello]in Typst today, you get a rectangle with a very even inset. In contrast, if you take CSS for instance, a<span style="padding: 5px; background: aqua">Hello</span>is not evenly spaced. The left inset looks smaller than top and bottom, and even these two aren't perfectly even.The reason why Typst's output is evenly spaced is because of the way top- and bottom-edge work. Rather than using
ascenderanddescender(plus half-leading in CSS), we picked the default edgescap-heightandbaselinebecause they most closely reflect the real extent of normal uppercase letters in a font.Even default spacing: Since
cap-height&baselineare closely related to visual edges and the spacing between them (leading) is even, the current leading model gives very even looking spacing independently of the font. With a line-height based model, changing the font without changing the line-height can give a widely varying look.Correspondence between metrics for line and paragraph spacing: The line leading and block spacing work in very similar ways and are therefore metrically compatible: Specifying twice the amount for
block.spacingas forpar.leadingwill lead to twice the visual spacing.With the existence of top-edge and bottom-edge, leading was a natural and simple way to define the spacing, so we didn't see reason to complicate things further. This means it's also easy to have a stack, grid, or any other things (like list spacing) spaced the same as paragraphs. Notably, handling math equations well was not a design goal at the time because Typst didn't have support for equations at the time. :P
The proposed model
The obvious main benefit of the proposed change is that it handles equations more nicely. But it's also nice that not only font size, but also font change (e.g. raw block) doesn't lead to almost unnoticable shifts in line layout. So that's a big plus.
That the line height doesn't react to font change is both a benefit and a downside at the same time, in my opinion. It leads to a less even look when changing fonts, but leads to more predictable behaviour and less layout shifting when changing fonts.
For the spacing between lines, I believe the proposed change is good. I think what's still important to discuss is how all of this affects the remaining metrics: The bounding box of first and last line and the spacing between paragraphs:
I assume, since the proposal doesn't say anything special about the first and last line, that they should remain as-is. This means we would retain the nice even spacing interaction with containers, which is good.
At the same time, this raises the question of how equations are handled in the first and last line. If we remove the current equation slack hack, then almost all equations will have a non-zero descent, and as a result a final line with an equation in it will lead to different container bounds than one with an equation.
Moreover, the question is how paragraph spacing interacts with this. Right now, the spacing between paragraphs is defined as
block.spacing(though I'm considering to move it topar.spacingfor discoverability and also since paragraphs are not blocks per se). With aline-height-based model, should this stay as-is? This would mean no metrical correspondence between the values specified for paragraph spacing and line height.laurmaedje commentedon Jun 13, 2024
This is only slightly related, but still somewhat relevant: #4390
Enter-tainer commentedon Jun 16, 2024
When implementing this in #4236. I found it hard to deal with spacing between paragraphs. Especially for a tight list/enum/term.
Paragraph spacing difference
This leads to another difference in typst and LaTeX. In typst, the spacing between paragraphs is defined as the distance between the bottom edge of previous paragraph and the top edge of current paragraph. If you set it to 0, these 2 paragraph will be very close. (Actually, they are too close, look at the
handg. Maybe this is bacause the font metrics.)However, in LaTeX, it layouts text line by line, and each line always has a minimal spacing with the first line. If we set
\parskipto zero, it will make the distance between paragraphs looks like the distance between lines within a paragraph.Tight list implementation
Back to the tight list implementation issue. In LaTeX, each list item is a paragraph. To make a list look tight, simply remove all extra inserted spaces, like setting
\parskip,\itemskipto 0.In typst, the implemetation is similar (at least for term list). The distance between paragraphs should be carefully calculated. In the previous model, it should equals to
leading: the distance between lines' top/bottom edge.However this make it very hard when it comes to the line height model. In this way, we don't know "the distance between lines' top edge and bottom edge" unless we can see the ascent and descent of lines. And currently I cannot get it when it cross the boundary of paragraphs.
I don't know if there is a way to robustly get "the descent of the last line in previous par" and "the ascent of the first line in current par". Or how hard it would be to implement this mechenism? If this is possible, we can do this and get a nice tight list. Otherwise we might need to consider how to deal with paragraph spacing in this proposal cc @peng1999
8 remaining items
laurmaedje commentedon Jul 22, 2024
I'm honestly not sure.
Perhaps. I am not just wondering about the spacing between paragraphs though, but also about the one from the top of the page / container to the first baseline. And similarly from the last baseline to the bottom of a container.
xkevio commentedon Oct 13, 2024
Maybe a dumb thought, but could we support both definitions and call the one we have "leading" and the new one "line-spacing"? I know it could be somewhat confusing and would add to the kitchen sink argument and I don't know how that would behave with the issues mentioned here but idk.
I do like this definition we have since it is easy to understand but it is true that converting or porting templates from typesetting tools with other definitions is difficult and since there's no solid conversion, it is hard to rectify.
Andrew15-5 commentedon Oct 13, 2024
I would also prefer to keep both, just because it's more customizable, but I'm afraid it will put too much overhead on maintaining both modes. But maybe it's not that hard to do, IDK.
Enivex commentedon Oct 13, 2024
I think having both would be the worst of both worlds
alerque commentedon Oct 13, 2024
In my experience it is hard to have a leading algorithm that is right for all scenarios. Some are more generally useful than others but I don't think there is one magic bullet. Over at SILE we ship with five different leading algorithms (
tex,fixed,fit-font,fit-glyph, andcss) out of the box, and users can easily supply their own leading calculation function in a 3rd party package or even inline in a document.We have also had a long standing issue considering changing the default from
textofixedas well. The problem is it isn't a clear cut win in all scenarios.I find in my own projects that I use different ones even inside the same project (e.g. the covers or spine of a book, the imprint page, content inside tables, poetry, or the body of prose books might each be best suited to a different way of figuring leading. It isn't just a matter of tuning parameters on one algorithm either, sometimes a different algorithm can be useful.
laurmaedje commentedon Oct 18, 2024
Based on comments here, in other issues, and also on Hackernews, I want to clarify one thing: I'm not at all against changing the line spacing model and I'm also not defending the current model because I want to keep it.
I just want to make sure that if we change this, we don't do it hastily, but rather think things through properly. Otherwise, we will end up changing it twice. I was too occupied with other things recently to properly invest time into this issue, but that doesn't mean that it's disregarded. Things just take a bit of time sometimes.
woerndl commentedon Oct 19, 2024
Having extensive experience working with typography and layouts in HTML/CSS, DTP tools like Illustrator/InDesign, Sketch and Figma, as well as some experience in LaTeX, I want to add my two cents.
Please keep in mind that this is mainly from a user perspective. I hope some of what I write adds value by offering a more complete picture of the topic, as @laurmaedje wisely aims to do, to prevent making changes twice.
Appreciation time
First, I want to mention that @peng1999 created an great issue here, which goes far beyond the usual "please make line height work." I think the ideas here are already a great starting point.
And Laurenz, I want to applaud your response to this issue and many others. Your calm, friendly, and community-oriented approach to handling proposals is an under-appreciated skill, and I hope it will greatly contribute the success of Typst in the long run.
The most basic case
The strong reaction from many people on this issue may stem from a basic scenario: an institution or other entity requiring 12pt Arial with a 1.5 line height.
Ideally, you want to maintain consistent line height throughout the document, creating a basic form of a baseline grid.
For example, you struggled with line height consistency in your own thesis due to the case mentioned in this issue:

What usually happens: People set the line height to 1.5, then compare it to Word (for social sciences) or LaTeX (for STEM) and experience a mini breakdown, because you now have 2 (or 3) different versions.
The strong reactions in some of the issues, with replies suggesting that "leading" was chosen due to historical practices, might have been interpreted by some as: you set a 10pt font size and get 9.6pt because that's how Gutenberg did it. (I'm joking here.) Even though it was never intended to keep this as is.
Typesetters using leading for letterpress printing typically handled one size per line. Today, it's common to have different sizes or even different typefaces per line.
Monospace code blocksor 🦥 are just two obvious examples. In this sense, the use of leading to achieve a certain line height was more of a technological constraint than a feature.Some ingredients for dealing with line height in layouts
Laurenz, you mentioned here that your thoughts on even spacing in (inline-)blocks elements were one of the reasons for the current model. You also briefly mentioned here that you would want Typst to be able handle certain DTP tasks, such as magazine-like layouts.
In my experience the following ingredients are helpful to achieve that:
Having a baseline grid is a beast of its own and probably a separate feature, but it might make sense to consider the possibility, as this needs to hook into the line heights, and I suppose this is what you mean by "thinking it through first."
Your easy to use
#rect(fill: aqua, inset: 5pt)[Hello]example could be kept easy, if inline-block elements would honor the line-height of their content. This is what CSS does.That said, I think opinionated spacing is a slippery slope. Default spacings often do more harm than good or, in other words, cost more time than they save. Thus the rise of things like
reset.cssornormalize.css. (Different topic)But ideas like special treatments for the first or last lines and mixing or collapsing block-level with text spacing can lead to utter chaos really quickly.
If it helps anyone involved, I can provide a few visual examples that showcase common scenarios related to handling line height in layouts and typesetting. Since this post is already too long, I refrained from making it even longer.
Enivex commentedon Oct 19, 2024
@woerndl you may want to join the Discord. That's where most of the nitty gritty discussion takes place
ertugruluyar-github commentedon Mar 26, 2025
Hi, what is the last status on this topic?
I am asking because I am struggling to set Single Line Spacing, as in the Office365 Word in Typst.
I am currently developing a thesis template. And in the cover page, I couldn't get the exact measures, they don't getting same. Roughly 0.5em (12pt font size) of leading value with default top-edge and bottom-edge values in Typst is equal to Single Line Spacing in Office365 Word.
Andrew15-5 commentedon Mar 26, 2025
See #4224 (comment). Might solve this problem.
Also 1/1.5/2 line spacing is just a rough estimate as it's basically a range of actual spacing (i.e., 1.4 or 1.7 can be classified as "1.5"). And from what I've discovered several years ago, different tools have different exact value for "1.5", with a certain someone making it 2.2 instead of 1.5.
SolidTux commentedon Mar 26, 2025
Regarding Word spacing, this is a good reference.
If you care about exact line spacing, do not use the default top-edge and bottom-edge as they will depend on the font.
So, something like the following should get you close to Word's single spacing (and 0.75em and 1.33em to 1.5/2 spacing)
But I think, this is getting a bit off-topic and might better discussed in the forum.
ertugruluyar-github commentedon Mar 27, 2025
Do I need to this:
My font is Times New Roman and and 12pt.
And wouldn't be bad to changing default top-edge and bottom edge defaults, because of above discussions. See #4224 (comment)
Doing only this would be enough?
ertugruluyar-github commentedon Mar 27, 2025
I have created a Question in the forum: https://forum.typst.app/t/getting-office-365-word-line-spacing-in-typst/3422/1
sungodmoth commentedon Nov 25, 2025
As another reason to want this behaviour, I think having the line spacing depend on
top-edge/bottom-edgeis both unintuitive (in the sense that positioning text within a container and spacing lines don't seem like they should depend on the same property) and in some cases obtrusive; in particular, I think there are plenty of use-cases for setting text totop-edge: "bounds",bottom-edge: "bounds"for positioning within a container, but this results in awful, visually inconsistent line spacing:For a personal project I have a workaround for this that involves manually splitting text into lines and setting only the top line to
top-edge: "bounds"and only the bottom line tobottom-edge: "bounds"while keeping all other lines at"cap-height"/"baseline", which is hardly an elegant solution.This could be solved by:
top-edge/bottom-edgeORtop-edgeandbottom-edgefor spacing purpose, instead always spacing according to"cap-height"/"baseline"ORtop-edge: "bounds"andbottom-edge: "bounds"(1) and (2) would both break things for people who want to set
top-edge: "ascender",bottom-edge: "descender"(e.g. to imitate the output of another program), but (3) would be very inconsistent (though I think it's justifiable by the assumption that almost nobody would ever want to use"bounds"for line spacing).gaurang-ingale commentedon Aug 17, 2026
I was quite enjoying using typst, but the leading model seems to be the most unintuitive and frustrating thing to deal with. I hope this changes in the future, will come back to typst when it does. Just being able to set line height is an absolute necessity for a type setting tool such as typst.