I am writing a template for my homework submissions. For this, I would like to give each (sub-)section a corresponding heading like “Exercise n” or “Part x”, but since the individual homework problems do not (usually) have any titles per se, my current approach is to create empty headings in the following sense:
=
This is the first exercise
==
This is Part (a) of the first exercise
= An actually named exercise
This is the second exercise
In my current setup, this produces something like
Exercise 1.
This is the first exercise
a.
This is Part (a) of the first exercise
Exercise 2. An actually named exercise
This is the second exercise
The only problem with this is that neither Exercise 1 nor Part (a) are added to the PDF outline, which would enable me to quickly jump to a particular exercise or part by clicking on the side bar of my PDF viewer. My question now is how, if even, I can add the exercises and parts to the outline as “Exercise n” or “Part x”.
I know that it would probably be easier to e.g. define an exercise-function and calling it with #exercise[], but I would prefer the empty-heading approach if possible.
you can share the part of your template that deals with this if you want.
you should also check if there are heading(outlined: false) this will prevent them from showing.
also, the show heading rule, if you put it in a template, will likely break your outline title (of if the show rule is set before the outline is called), there is a solved question on the forum on how to fix it.
I’m sorry if I wasn’t clear enough. Actually I don’t want to have an outline/table of contents (in the sense of #outline()), but I want to have the PDF metadata included that allows my PDF reader to suggest me to jump quickly to the particular heading. The code that I pasted above gives me the following in the Evince PDF viewer:
As you can see, the only heading that appears in the side bar to the left is the one of the second exercise, which is non-empty. I would like to have the sidebar look something like this:
And the thing is that having this PDF outline appear works flawlessly for non-empty headings, but somehow not (out-of-the-box) for empty headings as in my use case. I also tested this in the Okular PDF viewer with the same result.
By the way, your code snippet produces an empty PDF metadata outline, but I assume that the fact that the only named heading “Contents” is not in the PDF outline is not a bug but a feature in this case. Anyway, the outline/table of contents works fine as expected, but not the PDF metadata outline.
hello, I’m responding from my phone and I just realised that the pdf bookmarks do not work in the same way the outline function does. from the limited googling and the adobe docs bookmarks need a title and an action associated with them.
My guess is that the title that typst reports is the body of the heading, not including the numbering.
I advice you to use this approach instead for empty headings, make a show rule for the different heading levels and only show the numbering, in your main, name your heading with whatever you want to appear in the bookmarks.
as, Im on my phone and am unable to use typst on it to test this i can only hint that you can display the numbering using something along the lines
// possible faulty code
#show heading: it => {
if it.level == 1 {
context counter(heading.where(level:1)).display(it.numbering)
}
// define behavior for the rest of the levels or use .where selector
}
don’t mark my replay as answer if it doesn’t work, if you manage to get it to work you can post the correct code and mark it as an answer.
Thanks again. But unfortunately the code snippet is not doing anything different for me, i.e. the empty headings still don’t show up in the PDF outline/bookmarks.
Maybe it’s just not (yet) possible to set the PDF outline/bookmarks in that way.
It would help if you provided a minimal working example that includes the way you make headings show as “Exercise 1.”, etc. But maybe the following works for you or can be adapted to your needs:
If your document is more complex, e.g. with level 1 headings that are not only for Exercises, you might need to add more complex conditions in the show rules to transform only the correct headings.
Okay, thank you. It looks a bit hacky, but this is essentially the solution that I’ve been looking for. The empty headings show up in the PDF outline/bookmarks as “Exercise 1” and “a.” now and they still display correctly within the document.
As for my previous solution, it was basically the same as