Now that the first RC for 0.13 is out, I thought I’d try to adapt my template. I’ve been trying to fix some outline show rules by reading the preview docs, yet there’s still a problematic part in my code that I don’t know how to fix:
// Make the Lists of Figures/Tables/... more concise and easier to read, like in the LaTeX templates
show outline.entry: it => context {
if it.element.has("kind") {
let loc = it.element.location()
if counter(figure.where(kind: it.element.kind)).at(loc).first() == 1 {
v(1em)
}
show link: set text(rgb("000000"))
link(loc,
box(it.body.children.at(2), width: 2.6em) // figure number
+ it.body.children.slice(4).join() // figure caption
+ box(it.fill, width: 1fr)
+ it.page
)
} else {
it
}
}
This code serves to visually simplify figure outlines, by using show rules to, among other things, hide the supplements. The problematic part is here:
While I understood that it.body is now it.element.body and that it.page is now it.page(), I have no idea of where the numbers and captions of the figure went. How can I replicate those?
Hi @tcfx,
if you use the web app or the Tinymist extension, you can hover with your mouse pointer over code, for example it.element and see all the internal fields of the element.
To get the caption you need to use it.element.caption.body Edit: see laurmaedje’s answer
The correct figure number is a bit more complicated, you need: numbering(it.element.numbering, ..it.element.counter.at(it.element.location()))
To replace it.body, you should be using it.body() rather than it.element.body. The numbering is now separate and accessible via it.prefix(), so you don’t have to go through the whole ordeal with numbering(..) etc.
The preview outline entry docs are a bit messed up because the docs generator choked on methods in a sub-element. We need to fix that before the proper release.
@laurmaedje uhh I was confused because the functions did not show up in autocomplete.
If no supplement should be displayed I guess the whole numbering(...) is needed, or is there a better way?
For headings, no supplement will be added, but for figures it is indeed added and if you don’t want that the numbering stuff is neccessary. Will check about the autocomplete not working.
You should use a block instead a box. The old outline used line breaks between entries whereas the new one expects them to be blocks (as that makes much more sense semantically and means we can use show-set rules for block spacing).
I was initially gonna use a grid as a workaround, but that makes sense, and it may explain a spacing issue I am having with the main outline.
That being said, the main problem remains: I’m still unable to correctly fetch the numbers of the figures, which are chapter-relative, with “1.1” numbering for normal chapters and “A.1” numbering for appendices. Currently 1.1 becomes 0.1, B.1 becomes -.1, etc.
Typst doesn’t and didn’t natively support chapter-relative numbers, so nothing has really changed in that regard. Maybe you loaded some package that implemented this?
I implemented it manually, here. Can’t this still be considered a regression, though? I honestly think it would make sense to have a way to call it.prefix() without the supplement. This way, my template would still replicate the LaTeX one rather than losing functionality relative to 0.12. For comparison with an already existing functionality, it would be something like how calling a labeled figure like @this[] removes the supplement in the reference.
Update: I figured it out myself. It’s it.prefix().children.at(2).
The final code thus becomes:
// Make the Lists of Figures/Tables/... more concise and easier to read, like in the LaTeX templates
show outline.entry: it => context {
if it.element.has("kind") {
let loc = it.element.location()
if counter(figure.where(kind: it.element.kind)).at(loc).first() == 1 {
v(1em)
}
show link: set text(rgb("000000"))
block(
link(loc,
box(it.prefix().children.at(2), width: 2.6em) // figure number
+ it.body() // figure caption
+ box(it.fill, width: 1fr)
+ it.page()
)
)
} else {
it
}
}