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
Indentation on multiline headings with full-width character #6527
bugSomething isn't workinglayoutRelated to the layout category, which is about composing, positioning, etc.textRelated to the text category, which is all about text handling, shaping, etc.
As far as I know, full width characters are present for compatibility purposes with older encoding standards, and shouldn't really be used. Especially outside the context of CJK writing.
hanging-indent
The default value of auto indicates that the subsequent heading lines will be indented based on the width of the numbering.
Default: auto
As shown in the following examples, it relates to #5778 and punctuation width adjustment. A full-width Han character 口 will not trigger this issue.
#setpage(width: 12em, height: auto, margin: 1em)
#settext(
lang: "zh",
font: "Noto Serif CJK SC",
top-edge: "ascender",
bottom-edge: "descender",
)
#lettests= {
[
#setheading(numbering: nums=>"一、")
= 国国国国国国国国国
]
[
#setheading(numbering: nums=>"一口")
= 国国国国国国国国国
]
}
The default hanging-indent is #auto.
#tests
Change hanging-indent to #2em.
#setheading(hanging-indent: 2em)
#tests
Remove the #0.3em space. (See \#5778)
#showheading: it=> {
showh.where(amount: 0.3em): noneit
}
#tests
Change hanging-indent back to #auto.
#setheading(hanging-indent: auto)
#tests
A better fix (for Typst 0.15) might be to handle heading.numbering and heading.body separately, for example by wrapping the content of heading.numbering in a box.
#showheading: it=> {
iftype(it.numbering) ==str {
letfields= it.fields()
_=fields.remove("numbering")
_=fields.remove("body")
counter(heading).update((..it) => {
letp= it.pos()
p.at(-1) =p.at(-1) -1p
})
showheading: settext(text.size)
heading(
numbering: (..n) => {
// here, you can add `#h(.3em, weak: true)` or not// maybe `heading` should have a field like `body-indent` to control the spacing between `heading.numbering` and `heading.body`box([#std.numbering(it.numbering, ..n)#h(.3em, weak: true)])
},
..fields,
it.body,
)
} else {
it
}
}
Some tests:
#setpage(height: auto, width: 5cm, margin: 1em)
#settext(lang: "zh", region: "CN", font: "Noto Serif CJK SC")
// #show heading: set text(size: 15pt)#lettest= [永人永人永人永人]
#setheading(numbering: "〔1〕")
not good:
= #test#setheading(numbering: "一、")
= #test#setheading(numbering: "一(1)")
== #test#line(length: 100%)
#showheading: it=> {
iftype(it.numbering) ==str {
letfields= it.fields()
_=fields.remove("numbering")
_=fields.remove("body")
counter(heading).update((..it) => {
letp= it.pos()
p.at(-1) =p.at(-1) -1p
})
showheading: settext(text.size)
heading(
numbering: (..n) => {
// here, you can add `#h(.3em, weak: true)` or not// maybe `heading` should have a field like `body-indent` to control the spacing between `heading.numbering` and `heading.body`box([#std.numbering(it.numbering, ..n)#h(.3em, weak: true)])
},
..fields,
it.body,
)
} else {
it
}
}
fix:
#setheading(numbering: "〔1〕")
= #test#setheading(numbering: "一、")
= #test#setheading(numbering: "一(1)")
== #test#setheading(numbering: "一口")
= #test#setheading(numbering: "1)")
= Long title test#setheading(numbering: "1)") // fullwidth brace= Long title test
If pass function to heading.numbering, then wrap it to box
#import"@preview/numbly:0.1.0": *#letbox-numbly(..arr, default: "1.") = (..num) =>box(numbly(..arr, default: "1.")(..num))
#setheading(numbering: box-numbly(
"{1:附录 A})", // use {level:format} to specify the format"{1:A}.{2})", // if format is not specified, arabic numbers will be used
))
= #test== #lorem(2)== #test
Interesting. It even generates better output than #7247 for 〔1〕.
It never occurred to me, because box may cause vertical misalignment with the old compilers.
Your solution can summarized into the following util function. It fixes the hanging-indent by replacing the numbering text with a measure-stable box.
Here, measure-stable means that measure(it).width + 0.3em == measure(it + h(0.3em, weak: true)).width.
bugSomething isn't workinglayoutRelated to the layout category, which is about composing, positioning, etc.textRelated to the text category, which is all about text handling, shaping, etc.
Activity
Enivex commentedon Jun 30, 2025
As far as I know, full width characters are present for compatibility purposes with older encoding standards, and shouldn't really be used. Especially outside the context of CJK writing.
That being said, this does look like a bug.
YDX-2147483647 commentedon Jul 2, 2025
I have encountered this problem before, too.
Workaround
Explanations
As shown in the following examples, it relates to #5778 and punctuation width adjustment. A full-width Han character
口will not trigger this issue.docs: citation form, auto hanging indent, cjk-latin space at `\ `
docs: citation form, auto hanging indent, cjk-latin space at `\ `
docs: citation form, auto hanging indent, cjk-latin space at `\ `
docs: citation form, auto hanging indent, cjk-latin space at `\ `
Fixed auto hanging indent for `一、` numbering
tianyi-smile commentedon Aug 2, 2026
A better fix (for Typst 0.15) might be to handle
heading.numberingandheading.bodyseparately, for example by wrapping the content ofheading.numberingin abox.Some tests:
If pass
functiontoheading.numbering, then wrap it toboxe.g.
YDX-2147483647 commentedon Aug 2, 2026
Interesting. It even generates better output than #7247 for
〔1〕.It never occurred to me, because
boxmay cause vertical misalignment with the old compilers.Your solution can summarized into the following util function. It fixes the hanging-indent by replacing the numbering text with a
measure-stablebox.Here,
measure-stable means thatmeasure(it).width + 0.3em == measure(it + h(0.3em, weak: true)).width.The only caveat I found is that
spacingdoes not work for general values:tianyi-smile commentedon Aug 2, 2026
I think this is caused by
weak: trueinh. The following should work:YDX-2147483647 commentedon Aug 2, 2026
If strong
his used, is it still possible to decrease the actual space between numbering and body to less than 0.3 em?tianyi-smile commentedon Aug 2, 2026
I think we can set
box.inset, like:Tests