Hide or ignore? ToC structure issue

As you can see in the picture above, hide height to 0pt is not the right way to ignore headings, and the PDF bookmark is different from the outline().
The script is:

// heading_ignore(heading, level) 
#let hi(h, l) = {heading(outlined:false, bookmarked:false, level:l)[#h]}

#outline()

= Markdown

== CommonMark

#table(columns:3, align:left+horizon,
[#hi([Heading 1], 1)], [\# Heading 1], [Heading 1\ \=\=\=],
[#hi([Heading 2], 2)], [\#\# Heading 2], [Heading 2\ \-\-\-],
[#hi([Heading 3 (up to 6)], 3)], [\#\#\# Heading 3 (up to 6)], [],)

== GitHub Markup

== JupyterBook MyST

A workaround is:

// heading_fake(heading, level)
#let hf(h, l) = {text(1.6em-l*0.2em, weight:"bold")[#h]}

The Typst output is what I would expect: you have headings such as = Markdown and == Commonmark which you don’t configure in any way so they end up in the table of contents.

Could you include an image of the output you expect?

1 Like

I think this is maybe the same bug as the one reported here? Bookmarks are displaying at the correct depth only in the Typst app but not in other PDF readers. · Issue #5615 · typst/typst · GitHub

2 Likes

BTW, you don’t need {} when defining a one-line function/variable. You can also simplify many other things:

#show raw: set text(11pt)

// heading-ignore(heading, level)
#let hi(l, h) = heading(outlined: false, bookmarked: false, level: l)[#h]
#let hi(l, h) = text(1.6em - l * 0.2em, weight: "bold")[#h]

#outline()

= Markdown
== CommonMark
#table(
  columns: 3,
  align: left + horizon,
  hi(1)[Heading 1], `# Heading 1`, `= Heading 1`,
  hi(2)[Heading 2], `## Heading 2`, `== Heading 2`,
  hi(3)[Heading 3 (up to 6)], `### Heading 3 (up to 6)`, `=== Heading 3 (infinite)`,
)

== GitHub Markup
== JupyterBook MyST

image

Though specifics depend on exact guidelines.

With

#show table.cell.where(x: 1): set raw(lang: "md")
#show table.cell.where(x: 2): set raw(lang: "typ")

you can spice up the output with syntax highlighting:

1 Like

@sijo open the pdf with Web browser Firefox (PDF.js library), the outline is broken! I marked a yellow area in picture to compare the two outlines (PDF.js and typ outline()), you could see the differences.
@Andrew Thank you for code style addvices, help me a lot!

1 Like