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
Allow adding an optional short caption to be displayed in the outline
Use Case
When adding a caption to a figure, the text might be quite long, in particular, when the figure contains a table or (multiple) images that require explanation. The entire caption text is automatically added to the outline, which may look really messy, depending on the text length.
In the caption package of LaTeX, one can add an argument <list entry> (kind of a short caption), that shows up in the outline instead of the <heading> (i.e. the actual caption), if given: \caption[⟨list entry⟩]{⟨heading⟩}. If no <list entry> is given, the <heading> is shown in the outline (as is happening now in typst) and if it is given, but left empty ( \caption[]{⟨heading⟩}) , no entry will be made in the outline.
Reacted by Mikaël Capelle, Paul Kretschel, Tony, jothepro, Guilain Ernotte, Edgar Onghena, Janosh Riebesell, Florian Nick, Andreas Kröpelin, Ming-Long Huang and 33 more
I propose changing the heading.outlined type from boolean to string/none. This modification will enable the Table of Contents (ToC) to display a specified string if it is not set to none.
Reacted by NicolasHaeffner, Janosh Riebesell, Juntong Chen, Carl Kuhlemann, cAttte, Luca and Daniel Ayala
#outline(title: [Figures], target: figure)
#figure(
rect(),
caption: flex-caption(
[This is my long caption text in the document.],
[This is short],
)
)
Reacted by Bing Guo, lkndl, miliog, Marcel, Luiz Henrique Oliveira Martins, Juntong Chen, Pascal Daniel, YouRik, Bryan Casanelli, Andreas Zach and 2 more
#outline(title: [Figures], target: figure)
#figure(
rect(),
caption: flex-caption(
[This is my long caption text in the document.],
[This is short],
)
)
Working nicely 😄 . Also works for headings:
#heading(level:1, flex-caption(
[ a ver long title a ver long title a ver long title ],
[my short one])
)
#outline(title: [Figures], target: figure)
#figure(
rect(),
caption: flex-caption(
[This is my long caption text in the document.],
[This is short],
)
)
For future reference - this can (obviously) also be used to omit citations inside figure outlines.
#outline(title: [Figures], target: figure)
#figure(
rect(),
caption: flex-caption(
[Some figure showing x @somesource], //Display caption including citation
[Some figure showing x], //Caption without citation used in the outline
)
)
Hi all — I'm new to Typst, so if I should check out some more documentation on my own, please don't hesitate to tell me "just read [XYZ]"!
But I was curious if the new "context" introduced in 0.11.0 will be able to improve the current workaround? I tend to think it can, but I am not entirely sure how. Any advice?
But I was curious if the new "context" introduced in 0.11.0 will be able to improve the current workaround?
Yes, it would now look like this:
#letflex-caption(long, short) = contextifin-outline.get() { short } else { long }
Reacted by Oliver (Yi-Che) Chang, jon4sreiter, Gaétan Lepage, AhmedSalih3d, Pascal Daniel, Eric Martin Feltham, YouRik, q-wertz, Bryan Casanelli, Andreas Zach and 3 more
But I was curious if the new "context" introduced in 0.11.0 will be able to improve the current workaround?
Yes, it would now look like this:
#letflex-caption(long, short) = contextifin-outline.get() { short } else { long }
You saved my day in my step of trying to migrate a document from LaTeX to Typst, as a learning experience. I was quite bummed out, thinking that it was not possible at all - hopefully this is integrated into the figure environment in some way in the future
Kind regards
Reacted by Andreas Kröpelin, Eric Martin Feltham and bluss
before any usage of outline() (e.g. of your theme). If I changed the order I got the same caption version in the outline and below the figure.
In an extra file (misc_functions.typ in my case) add the function definition (I changed it to have named arguments because I always mix up short and long version 😅 ):
#letflex-caption(short: none, long: none) = contextifstate("in-outline", false).get() {
short
} else { long }
// [...]
When you want to use flex-caption in file chapters/test.typ:
#import"../misc_functions.typ": *// [...]#figure(
"My awesome figure",
caption: flex-caption(
short: [Short caption appearing in outline.],
long: [Long caption appearing in document body],
),
) <fig:example>
Let me know if I just misunderstood some typst basics and the whole thing also works in an easier way 😅
EDIT:
Removed unnecessary line in main file. Thx for noticing @jasperlig
Reacted by Bryan Casanelli, Tom, Paul Kailer, raldone01, Marius Maryniak, Braden Griebel and VibrantTreeStump
As it took me quite a white to get it up and running (in a multi file document) here a full example derived from the solution of @andreasKroepelin
In your main file add
#letin-outline= state("in-outline", false)
#showoutline: it=> {
in-outline.update(true)
itin-outline.update(false)
}
#letflex-caption(short, long) = contextifin-outline.get() { short } else { long }
// [...]// e.g. #show: my-theme.with(...) and/or outline(title: "List of figures", target: figure.where(kind: image))#include"chapters/test.typ"
before any usage of outline() (e.g. of your theme). If I changed the order I got the same caption version in the outline and below the figure.
In an extra file (misc_functions.typ in my case) add the function definition (I changed it to have named arguments because I always mix up short and long version 😅 ):
#letflex-caption(short: none, long: none) = contextifstate("in-outline", false).get() {
short
} else { long }
// [...]
When you want to use flex-caption in file chapters/test.typ:
#import"../misc_functions.typ": *// [...]#figure(
"My awesome figure",
caption: flex-caption(
short: [Short caption appearing in outline.],
long: [Long caption appearing in document body],
),
) <fig:example>
Let me know if I just misunderstood some typst basics and the whole thing also works in an easier way 😅
It seem like the #let flex-caption(short, long) = context if in-outline.get() { short } else { long } in the main file is not beeing used and therefore should be removed.
When using this approach I am getting a warning at compile time:
warning: layout did not converge within 5 attempts
Wrapping the short text in a block() as suggested here gets rid of the warning, but messes up the outline (as expectable). Weirdly enough, commenting other parts of the main text seems to randomly trigger or solve this warning. Any clues on how to bisect this properly?
It seem like the #let flex-caption(short, long) = context if in-outline.get() { short } else { long } in the main file is not beeing used and therefore should be removed.
@q-wertz You're most probably right: I can't reproduce the issue in a MWE and it seems to have gone away by itself anyway, so it was likely caused by a conflict elsewhere. I am indeed using the drafting package :)
While having explicit control over the short and long title has already been answered, I'd like to highlight the option of simply shortening the title to the first sentence by default, by splitting it on the first fullstop. For example:
#showoutline.entry: it=> {
(
text(weight: "bold", [Figure #it.element.numbering:]), // some markup to look niceit.element.caption.body.text.split(".").at(0) +".", // only show first sentence as "short title"box(width: 1fr, repeat[.]), // fill with dots, if you wantit.page() // page number
).join("")
}
This way, you don't need custom functions, or importing these in every document that has a figure. You only need to define this once for the figure outline
Activity
kamasylvia commentedon Aug 25, 2023
I propose changing the
heading.outlinedtype frombooleantostring/none. This modification will enable the Table of Contents (ToC) to display a specified string if it is not set tonone.NicolasHaeffner commentedon Sep 29, 2023
But then, if it is none is it not showing or is it using the long caption?
laurmaedje commentedon Sep 29, 2023
See also: #1892 (comment)
yrd commentedon Oct 12, 2023
Here's an idea for a workaround while this isn't implemented yet:
Seems to work and produce the desired result (as far as I can tell).
bguo068 commentedon Dec 13, 2023
This works for me. Thank you!!
laurmaedje commentedon Dec 13, 2023
Here is another solution that is maybe a little bit less cursed:
Which can then be used like this:
bguo068 commentedon Dec 14, 2023
Working nicely 😄 . Also works for headings:
Thank you so much!!
mst2k commentedon Feb 25, 2024
For future reference - this can (obviously) also be used to omit citations inside figure outlines.
yichechang commentedon Mar 30, 2024
Hi all — I'm new to Typst, so if I should check out some more documentation on my own, please don't hesitate to tell me "just read [XYZ]"!
But I was curious if the new "context" introduced in
0.11.0will be able to improve the current workaround? I tend to think it can, but I am not entirely sure how. Any advice?andreasKroepelin commentedon Apr 30, 2024
Yes, it would now look like this:
AhmedSalih3d commentedon Nov 12, 2024
You saved my day in my step of trying to migrate a document from LaTeX to Typst, as a learning experience. I was quite bummed out, thinking that it was not possible at all - hopefully this is integrated into the figure environment in some way in the future
Kind regards
q-wertz commentedon Mar 24, 2025
As it took me quite a white to get it up and running (in a multi file document) here a full example derived from the solution of @andreasKroepelin
In your main file add
before any usage of
outline()(e.g. of your theme). If I changed the order I got the same caption version in the outline and below the figure.In an extra file (
misc_functions.typin my case) add the function definition (I changed it to have named arguments because I always mix up short and long version 😅 ):When you want to use
flex-captionin filechapters/test.typ:Let me know if I just misunderstood some typst basics and the whole thing also works in an easier way 😅
EDIT:
Removed unnecessary line in main file. Thx for noticing @jasperlig
jasperlig commentedon Sep 13, 2025
It seem like the
#let flex-caption(short, long) = context if in-outline.get() { short } else { long }in the main file is not beeing used and therefore should be removed.nmaggioni commentedon Sep 13, 2025
When using this approach I am getting a warning at compile time:
Wrapping theWeirdly enough, commenting other parts of the main text seems to randomly trigger or solve this warning. Any clues on how to bisect this properly?shorttext in ablock()as suggested here gets rid of the warning, but messes up the outline (as expectable).q-wertz commentedon Sep 14, 2025
Thx @jasperlig for noticing. Updated the comment.
@nmaggioni never had a problem with that due to this code. Do you have a clean code or other packages/function/... in use? Or can you give a MWE?
My last converge problem was due to the usage of the drafting package and two margin notes close to each other.
nmaggioni commentedon Sep 18, 2025
@q-wertz You're most probably right: I can't reproduce the issue in a MWE and it seems to have gone away by itself anyway, so it was likely caused by a conflict elsewhere. I am indeed using the
draftingpackage :)feat: allow having long and short captions
bgmeulem commentedon Jan 30, 2026
While having explicit control over the short and long title has already been answered, I'd like to highlight the option of simply shortening the title to the first sentence by default, by splitting it on the first fullstop. For example:
This way, you don't need custom functions, or importing these in every document that has a figure. You only need to define this once for the figure outline