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
Different heading text for outline/bookmark and displaying #1889
When using LaTeX, I'm able to specify an alternate text for \part, \chapter, \section, etc.
\chapter[alternate text]{display text}
If specified, the alternate text is used in ToC and PDF bookmarks.
Use Case
This is useful when the title is long and I want to break it into lines manually without affecting the outline and bookmark.
It is also useful when I want to put some additional information (e.g. author, year) into the heading but not into the ToC.
Reacted by Gaétan Lepage, InAnYan, Alexander Wörndl, KaiserY, bluss, Alfred Reibenschuh, Angelo Haller, SuperCowProducts, aarneng, Behrang Saeedzadeh and 3 more
I specifically corrected the given example. But for the OP's solution you're right, although at this point I might use a wrapper function that mimics the one provided in the OP:
This looks useful, thanks. Do you know, is it possible to fix it so that when I click a ToC record, the document is scrolled so that the "display text" line is not scrolled over?
Do you know, is it possible to fix it so that when I click a ToC record, the document is scrolled so that the "display text" line is not scrolled over?
I think I actually was thinking that this could happen, but in any case, simply changing the order shouldn't break anything else and will fix the thing:
great. i used it to add an index entry titled "Contents" in the PDF outline-metadata (aka PDF-Index). the #outline() call has already added the corresponding visible content on the page.
i think that call to outline() should create a bookmark to itself by default.
there have been coutless examples in pdf books having looooong TOC contents and maaaannny pages before TOC too, but no entry to TOC in the PDF-Index. so to reach the top of the TOC, the reader is left to scroll and scroll and scroll and scroll.
It looks like the last workaround I posted isn't perfect: Andrew15-5/rubby#6 (comment). If you have nested heading levels after the chapter call, then you have to insert alt heading last, otherwise the PDF outline will break. Which I think is a separate bug.
Interessting alternative, thank you!
Sadly the outline use the "body" title, not the alt... (you can say I'm never happy 😄)
If we add in outline the "unumbered" title, numbering is OK but the final outline looks like crap...
(i'm in a context where I want to use alternative title for other levels of titles)
No matter how many times I turn it, I don't think the tool provides a satisfying solution :(
Use headings with short and long titles. The real body of the heading is the short title, so without change it will appear in bookmarks and outlines. But the heading itself has a show rule so that it is displayed using its long title.
#outline()
#setheading(numbering: "1.")
#letfindtitle(body) = {
ifbody.has("children") andtype(body.children.at(-1, default: none)) ==content {
letmt= body.children.at(-1)
ifmt.func() ==metadataandmt.at("label", default: none) ==<altheading> {
returnmt.value.longtitle
}
}
}
#showheading: it=> {
letlongtitle= findtitle(it.body)
block({
ifit.numbering!=none {
numbering(it.numbering, ..counter(heading).get())
h(0.3em)
}
iflongtitle!=none { longtitle } else { it.body }
})
}
/// Create a chapter heading////// The document data/outline/bookmark title is `title`/// but the displayed title by the heading itself is `longtitle`.#letchapter(title, longtitle) = {
heading({
title
[#metadata((title: title, longtitle: longtitle))<altheading>]
})
}
#chapter[Short A][Long title A]
== Normal Sub#chapter[Short B][Long title B]
an alterative text that appear in the ToC with numerotation and in the PDF bookmarks
Oh, well I didn't think about it like that, not sure why.
Actually, Andrew15-5/rubby#6 has a different problem, hence why I implemented the functions this way. Since the Document Outline only supports plain text, you can't include ruby in it, but you can in the outline()/heading(), therefore the alt is only to fix the Document Outline.
My suggestion would be to add an optional parameter to heading such as:
#heading(alt: "Alt Text")[Long Text]
Call it alt, outline-text, short or something else.
And then think about a short hand syntax like:
=[Alt] Long Text or so.
Because the hacky solutions presented here are sadly all very clunky. Some break the pdf bookmarks, some jump to low, others jump to high or to the previous page and if I stick the double header into an unbreakable block my show rules that add pagebreaks before headers explode.
Reacted by Jean, Dan Kenerson, Martin Hanl and VibrantTreeStump
Activity
github-young commentedon Dec 2, 2023
I found one hacking solution in this repo: https://github.com/nju-lug/nju-thesis-typst/blob/main/nju-thesis/utils/invisible-heading.typ
Andrew15-5 commentedon Feb 9, 2024
Pretty sure you want to use this instead (#2991 (comment)):
laurmaedje commentedon Jul 15, 2024
Related: #1295
johnmapeson commentedon Oct 8, 2024
If I understand correctly, @Andrew15-5 's solution should use
#heading(outlined: false)[Introduction]instead of just= Introduction:Andrew15-5 commentedon Oct 9, 2024
I specifically corrected the given example. But for the OP's solution you're right, although at this point I might use a wrapper function that mimics the one provided in the OP:
You can make the alt parameter optional, but instead of that you might as well just use
= Headingsyntax.johnmapeson commentedon Oct 9, 2024
This looks useful, thanks. Do you know, is it possible to fix it so that when I click a ToC record, the document is scrolled so that the "display text" line is not scrolled over?
Andrew15-5 commentedon Oct 9, 2024
I think I actually was thinking that this could happen, but in any case, simply changing the order shouldn't break anything else and will fix the thing:
goyalyashpal commentedon Feb 6, 2025
great. i used it to add an index entry titled "Contents" in the PDF outline-metadata (aka PDF-Index). the #outline() call has already added the corresponding visible content on the page.
i think that call to
outline()should create a bookmark to itself by default.there have been coutless examples in pdf books having looooong TOC contents and maaaannny pages before TOC too, but no entry to TOC in the PDF-Index. so to reach the top of the TOC, the reader is left to scroll and scroll and scroll and scroll.
Andrew15-5 commentedon Mar 15, 2025
It looks like the last workaround I posted isn't perfect: Andrew15-5/rubby#6 (comment). If you have nested heading levels after the chapter call, then you have to insert alt heading last, otherwise the PDF outline will break. Which I think is a separate bug.
MaxenceG2M commentedon Jun 24, 2025
This bug is due to the increment of counter each time heading is called.
I haven't found a solution yet, since counter is hard to update / decrement
Andrew15-5 commentedon Jun 25, 2025
MaxenceG2M commentedon Jun 25, 2025
Interessting alternative, thank you!
Sadly the outline use the "body" title, not the alt... (you can say I'm never happy 😄)
If we add in outline the "unumbered" title, numbering is OK but the final outline looks like crap...
(i'm in a context where I want to use alternative title for other levels of titles)
No matter how many times I turn it, I don't think the tool provides a satisfying solution :(
Thanks again for your thoughts and help
Andrew15-5 commentedon Jun 25, 2025
What does this even mean? The functions produce the documented result.
MaxenceG2M commentedon Jun 25, 2025
Yeah, but not the result wanted in this issue.
In the @balthild (from LaTeX), you have:
Wanted solution (LaTeX):

Actual typst solution:

bluss commentedon Jun 25, 2025
Here is an alternate workaround.
Use headings with short and long titles. The real
bodyof the heading is the short title, so without change it will appear in bookmarks and outlines. But the heading itself has a show rule so that it is displayed using its long title.Andrew15-5 commentedon Jun 26, 2025
Oh, well I didn't think about it like that, not sure why.
Actually, Andrew15-5/rubby#6 has a different problem, hence why I implemented the functions this way. Since the Document Outline only supports plain text, you can't include ruby in it, but you can in the
outline()/heading(), therefore the alt is only to fix the Document Outline.szanni commentedon Mar 24, 2026
My suggestion would be to add an optional parameter to
headingsuch as:Call it
alt,outline-text,shortor something else.And then think about a short hand syntax like:
Because the hacky solutions presented here are sadly all very clunky. Some break the pdf bookmarks, some jump to low, others jump to high or to the previous page and if I stick the double header into an unbreakable block my show rules that add pagebreaks before headers explode.