#show heading.where(level: 1): set heading(
numbering: "1:",
supplement: [Example]
)
#show heading.where(level: 1): it => {
it.supplement + " " + context { numbering(it.numbering, counter(heading).get().first()) } + " " + it.body
}
= First one <one>
== Level two
See things @two
= Second One <two>
== Level two
Which works, but I am wondering if there is a better/simpler method to have this behavior.
With the behaviour being, that the heading numbering has some text before it, like Text [numbering]: and that references to a heading show up as [supplement] [numbering], like shown in the picture.
Is there a better way to do this?
Also, how would I make the supplement be shown in the outline as well?
Hi there!
Yes, I do have a solution that might be a bit better:
#show heading.where(level: 1): set heading(
numbering: (.., last) => {
if last != 1 {
"Example " + str(last - 1) + ":"
}
else {
h(-0.4em)
}
}
)
#outline()
= First one
== Level two
See things
= Second One
== Level two
So you can actually create a custom function for the numbering (see documentation). The parameter last is the number, which is converted into a string, so it can be added to the other strings.
Regarding the outline the “supplement” “Example 1:” etc. they now show up in the outline just like the numbering would, although the indent is pretty large. I think that’s because it’s dependent on the length of the numbering. Apparently the title of the outline is a heading as well, so I had to exclude it and lower the number by one. Because there was still an indent in front of the outline’s heading, I added the else clause. Here’s the result:
If there are any questions or wishes left, feel free to ask again
Thanks, but the problem with using numbering to add Example 1:, is, that the : is included when using @label to reference a heading, which is not really desired.
The upside is, that it shows up in the outline. And the outline indenting can be set easily:
#set outline(indent: 2em)
But this gave me the idea to try to remove the : from the reference. And the customization section of ref had everything I needed.
Now I can use:
Updated Code
#set outline(indent: 2em)
#outline()
#set heading(numbering: "1.a")
#show heading.where(level: 1): set heading(
numbering: (num) => {"Example " + numbering("1:", num)},
supplement: [Example]
)
#show ref: it => {
let el = it.element
if el != none and el.func() == heading and el.level == 1{
link(el.location(),
numbering(
(num) => el.supplement + " " + str(num),
..counter(heading).at(el.location())
))
} else {
it
}
}
#show ref: it => {
emph(it)
}
= First one <one>
== Level two
See things @four and @sub_four
= Second One <two>
== Level two
= Third one
== Level two
See things at @two
= Fourth Heading <four>
== Sub fourth heading <sub_four>
And that gives me exactly the layout/behaviour I want:
I simplified your solution slightly, so it’s easier to read:
#set heading(numbering: "1.a")
#show heading.where(level: 1): set heading(
numbering: num => "Example " + numbering("1:", num),
supplement: "Example",
)
#show ref: it => {
let el = it.element
if el == none or el.func() != heading or el.level != 1 { return it }
let heading-levels = counter(heading).at(el.location())
let body = numbering(n => [#el.supplement #n], ..heading-levels)
link(el.location(), body)
}
#show ref: emph
Also note that you can use - in label/function/variable names, which is also a conventional way to name things. So the <sub_four> would be <sub-four> and the reference would be @sub-four.