You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support hanging-punctuation in the left margin #7231
Punctuation such as quotation marks should hang into the left margin. (See Thinking with Type, Ellen Lupton, 3rd edition, p. 76) The microtype package does this in LaTeX.
Here is the current behavior:
Here is what it looks like with hanging punctuation:
Use Case
This would be useful because hanging punctuation is good in both the left and the right margins. :)
I am sorry if I am submitting this issue to the wrong place—I'm new here. Please point me in the right direction if this is the wrong place. How new I am: I tried out Typst yesterday, fell in love with it, and started work on this feature shortly thereafter. I actually have a mock-up in my fork. It took very little effort to get a hacky version working.
Please let me know where to go with this feature from here. It's working for me in this one little case. If there are tests I need to add, documentation, switches, etc. please let me know and give me a nudge in the right direction.
Reacted by Kevin K., pure-chance, Jeremy Gao, Joseph Alexander Wilson, Daniel Ayala, Kirill Lukashev and David
Reacted by Victor L., Carl Kuhlemann and Daniel Ayala
Welcome! This is definitely the right place to start :)
For tests, read the testing guide. But to summarize, you can start by running cargo testit to check the reference image test suite, then cargo testit --update to update the rendered images, and finally commit the changed images and review them with an image diff tool or in GitHub. (and it's usually best to include updated test images in the same commit that updates them)
I think this is a much more subjective feature than slight punctuation overhang, and I'm not sure it should be enabled by default. But even if it would be, we'd probably need more fine-grained customization than just overhang: true | false to toggle things separately.
@laurmaedje What if overhang accepted a dict where you could specify the amount of overhang in [0.0, 1.0] for categories like quotes, dashes, punctuation? For backwards-compatibility it could still accept a boolean that turns them all on to the default.
That said… arguably you might want left-hanging quotes even if you turn off paragraph justification. Butterick goes to some lengths on his website (example, paragraph 4) to hang quotes into the left margin even with ragged-right.
Personally, I'm persuaded enough by the consensus I see among typographers that left-hanging indentation is important enough to turn on by default. However, the only tool that I know does this by default is microtype. In that case, maybe make overhang and overhang-left as separate options, each accepting a boolean to turn on everything, or a dict to fine-tune the amount of overhang for each category?
I think that the feature is a good fit for Typst. The devil is in the details.
Taking a look at what purposes overhang serves at either edge of the paragraph, we got a few differences: On the right side, we want to optically make the border more even, whereas at the left side, we may have this aim or we may want to pull the quotation marks out entirely, like in your example (e.g. for pull quotes). So there are two use-cases, requiring different adjustments. I am not convinced that a user-configurable percentage of overhang should be exposed. Instead, Typst should be able to accommodate these two use cases (as well as no overhang) to the best of its ability.
Additionally, the left edges of characters in the latin alphabet are often more straight than the right edges. This means that we are dealing with characters like B, C, D, E, F, G, K, L, M, N, P, and R that are more solid on the left than on the right. Hence, the left paragraph border gives the impression of a firmer edge than the right one, leaving less margin for error. The current adjustments have been designed for typical fonts and use at the right paragraph border (and not all quotes are symmetric).
Finally, we can see from this example on Wikipedia that not only punctuation overhangs at the left edge.
Given the reduced margin for error and the greater diversity of use-cases / requirements, I would be uncomfortable with enabling this adjustment by default, especially with a hard-coded list of character adjustments. If we can perform optical measurements for the actual glyphs in the font, I could be persuaded more easily to make this the default.
So there are two use-cases, requiring different adjustments.
This is a good point and I agree.
I don't know if I've got the experience (and the time!) to build out an optical alignment algorithm. (Don't get me wrong: I would love to, and I'm confident in my ability to learn whatever I need to, but I'm also a busy student!) I'm confident I could build out a pull-quote feature.
So, @reknih, do you think it would make sense to break this into two PRs? First, a setting in par to turn on pull-quotes that moves the quotation marks all the way into the margin, and second, an optical alignment algorithm to fine-tune the left edge of the paragraph.
I can do the first. I am not sure if I'd be able to tackle the second on my own.
@laurmaedje What if overhang accepted a dict where you could specify the amount of overhang in [0.0, 1.0] for categories like quotes, dashes, punctuation? For backwards-compatibility it could still accept a boolean that turns them all on to the default.
This is exactly what I proposed in #6582 (comment). It can be expanded with slight modifications for the left hanging.
I personally would prefer the protrusion table to be exposed to users. The table is not as simple as hard-coding values for the Latin script. There is a lot of variability in terms of language (see the linked issue) and personal preferences, like whether punctuation should be slighted protruded or fully overhang.
What microtype does is that it hard-codes a protrusion table for each font:
In fact, that's all microtype does. It doesn't implement the protrusion and font expansion (the implementation is in pdftex and its derivatives). It's just a collection of hard-coded protrusion and font expansion tables for each font, plus a nicer interface to configure them.
I don't think it is feasible for Typst to just hard-code all the values. Maybe we should expose a default table, and the user could bring their own if they prefer. The package ecosystem could also be helpful for providing pre-defined protrusion tables, like we would have a separate microtype package for Typst to contain hard-coded tables.
The actual implementation details of this feature, known as margin kerning, in pdftex is described in detail in the orignal Hàn Thế Thành thesis and the literal program of pdftex.
Reacted by David, Kirill Lukashev and Ashton Wiersdorf
I think I can make pull-quotes—separate from left-hanging punctuation/characters—without too much trouble. Would this be a welcome feature? If so, would it make most sense to add this as an option to par, since that's where justification gets set?
To add to this, consider an option for the user to set which glyphs are permitted from protrusion at the end of a line as well as at the start of a line.
For example, in Korean, these glyphs are "banned" from starting a line, but also are permitted from protrusion at the end of a line:
@ashton314 My main concern is the API design rather than implementation. I am not yet sure what's best here. The best way to have this move forward is to explore the API design space and write down the different options you see so that we can discuss them.
I think there should be a default settings for protrusion with an option for the user to change it. Anyways, it is a feature I would love to see. With typst's fast live rendering it would be particularly easy to make a personal manual adjustement if desired.
Activity
ashton314 commentedon Oct 27, 2025
Update on this: I've got it working with whatever the smartquotes for the current language are.
I've got a few failing tests around smart quotes—I'm assuming this is because they now hang.
@reknih @elegaanz <- Per point 1 of the contributing guide, I'm pinging you to ask you to take a look at this before I submit a formal PR. :)
I'll need some help getting all the tests to pass.
isuffix commentedon Oct 28, 2025
Welcome! This is definitely the right place to start :)
For tests, read the testing guide. But to summarize, you can start by running
cargo testitto check the reference image test suite, thencargo testit --updateto update the rendered images, and finally commit the changed images and review them with an image diff tool or in GitHub. (and it's usually best to include updated test images in the same commit that updates them)laurmaedje commentedon Oct 28, 2025
I think this is a much more subjective feature than slight punctuation overhang, and I'm not sure it should be enabled by default. But even if it would be, we'd probably need more fine-grained customization than just
overhang: true | falseto toggle things separately.ashton314 commentedon Oct 28, 2025
@laurmaedje What if
overhangaccepted a dict where you could specify the amount of overhang in[0.0, 1.0]for categories likequotes,dashes,punctuation? For backwards-compatibility it could still accept a boolean that turns them all on to the default.That said… arguably you might want left-hanging quotes even if you turn off paragraph justification. Butterick goes to some lengths on his website (example, paragraph 4) to hang quotes into the left margin even with ragged-right.
Personally, I'm persuaded enough by the consensus I see among typographers that left-hanging indentation is important enough to turn on by default. However, the only tool that I know does this by default is
microtype. In that case, maybe makeoverhangandoverhang-leftas separate options, each accepting a boolean to turn on everything, or a dict to fine-tune the amount of overhang for each category?laurmaedje commentedon Oct 28, 2025
@reknih I'd like your input on this.
reknih commentedon Oct 28, 2025
I think that the feature is a good fit for Typst. The devil is in the details.
Taking a look at what purposes overhang serves at either edge of the paragraph, we got a few differences: On the right side, we want to optically make the border more even, whereas at the left side, we may have this aim or we may want to pull the quotation marks out entirely, like in your example (e.g. for pull quotes). So there are two use-cases, requiring different adjustments. I am not convinced that a user-configurable percentage of overhang should be exposed. Instead, Typst should be able to accommodate these two use cases (as well as no overhang) to the best of its ability.
Additionally, the left edges of characters in the latin alphabet are often more straight than the right edges. This means that we are dealing with characters like B, C, D, E, F, G, K, L, M, N, P, and R that are more solid on the left than on the right. Hence, the left paragraph border gives the impression of a firmer edge than the right one, leaving less margin for error. The current adjustments have been designed for typical fonts and use at the right paragraph border (and not all quotes are symmetric).
Finally, we can see from this example on Wikipedia that not only punctuation overhangs at the left edge.
Given the reduced margin for error and the greater diversity of use-cases / requirements, I would be uncomfortable with enabling this adjustment by default, especially with a hard-coded list of character adjustments. If we can perform optical measurements for the actual glyphs in the font, I could be persuaded more easily to make this the default.
ashton314 commentedon Oct 28, 2025
This is a good point and I agree.
I don't know if I've got the experience (and the time!) to build out an optical alignment algorithm. (Don't get me wrong: I would love to, and I'm confident in my ability to learn whatever I need to, but I'm also a busy student!) I'm confident I could build out a pull-quote feature.
So, @reknih, do you think it would make sense to break this into two PRs? First, a setting in
parto turn on pull-quotes that moves the quotation marks all the way into the margin, and second, an optical alignment algorithm to fine-tune the left edge of the paragraph.I can do the first. I am not sure if I'd be able to tackle the second on my own.
Krasjet commentedon Oct 30, 2025
This is exactly what I proposed in #6582 (comment). It can be expanded with slight modifications for the left hanging.
I personally would prefer the protrusion table to be exposed to users. The table is not as simple as hard-coding values for the Latin script. There is a lot of variability in terms of language (see the linked issue) and personal preferences, like whether punctuation should be slighted protruded or fully overhang.
What
microtypedoes is that it hard-codes a protrusion table for each font:In fact, that's all
microtypedoes. It doesn't implement the protrusion and font expansion (the implementation is in pdftex and its derivatives). It's just a collection of hard-coded protrusion and font expansion tables for each font, plus a nicer interface to configure them.I don't think it is feasible for Typst to just hard-code all the values. Maybe we should expose a default table, and the user could bring their own if they prefer. The package ecosystem could also be helpful for providing pre-defined protrusion tables, like we would have a separate
microtypepackage for Typst to contain hard-coded tables.The actual implementation details of this feature, known as margin kerning, in pdftex is described in detail in the orignal Hàn Thế Thành thesis and the literal program of pdftex.
ashton314 commentedon Nov 7, 2025
@reknih @laurmaedje Hey, just wanted to poke this issue again:
I think I can make pull-quotes—separate from left-hanging punctuation/characters—without too much trouble. Would this be a welcome feature? If so, would it make most sense to add this as an option to
par, since that's wherejustificationgets set?ponte-vecchio commentedon Nov 9, 2025
To add to this, consider an option for the user to set which glyphs are permitted from protrusion at the end of a line as well as at the start of a line.
For example, in Korean, these glyphs are "banned" from starting a line, but also are permitted from protrusion at the end of a line:
// 행 시작 금지 문자 "!", "%", ")", ",", ".", ":", ";", "?", "]", "}", "¢", "°", "’", "”", "′", "″", "℃", "〉", "》", "」", "』", "】", "〕", "!", "%", ")", ".", ":", ";", "?", "]", "}", "¢"while these are the opposite (banned from ending in a line but can protrude at the start of a line:
// 행 끝 금지 문자 "(", "[", "{", "£", "¥", "‘", "“", "〈", "《", "「", "『", "【", "〔", "$", "(", "[", "{", "£", "¥", "₩"But then users should be able to remove or amend this like (for glyphs suchas
%which some people do not like to see protrude).I suspect this should depend on
langflag though.laurmaedje commentedon Nov 10, 2025
@ashton314 My main concern is the API design rather than implementation. I am not yet sure what's best here. The best way to have this move forward is to explore the API design space and write down the different options you see so that we can discuss them.
dayala1 commentedon Dec 18, 2025
I think there should be a default settings for protrusion with an option for the user to change it. Anyways, it is a feature I would love to see. With typst's fast live rendering it would be particularly easy to make a personal manual adjustement if desired.