How to have headings without numbers in a fluent way?

I want typst writing to be

  • fluent
  • style separate from content
  • light on markup

I got a bit concerned about these directives I was using for unnumbered headings, like this

#heading(numbering: none, level: 3)[Generators]

Here’s a fluent way - I think - to make the markup nice.

(In the document’s template or style file)

// Markers for headings without number
#show selector(<nonumber>): set heading(numbering: none)

Nonnumbered headings are now “fluent”:

=== Generators <nonumber>
3 Likes

Another way would be

#let nonumber(body) = {
  set heading(numbering: none)
  body
}

#nonumber[=== Generators]

Both have their up- and downsides – the show rule applies to other files while the function has to be imported, but function seems a bit more “direct” to me.

2 Likes

You can actually drop the selector() part.

I guess if you don’t need numbering for some specific headings, then it’s a very good solution. The other one would be to do let h-no-num = heading.with(numbering: none), but it still will look verbose for non-first level headings. Or something in between: Headings without numbers in a fluent way - #2 by SillyFreak.

This also assumes you won’t reference the headings, since they require numbering. But in addition to that, the heading label must be unique.

1 Like

Not just about verbose, but it’s good to have these headings show up the same way with the same syntax highlighting as regular headings. With this marker it works well. It’s in a document with numbered headings, but there is an extra chapter which doesn’t use heading numbering.

bild

1 Like

I cannot get this to work for some reason for Typst. See text below scrreenshot for copy+paste.

#show selector(<nonumber>): set heading(numbering: none)

= Hi <nonumber>


== Bye
As seen in @nonumber

It’s entirely equivalent to the other version. The syntax without label and selector is the canonical way to do it (which I didn’t know when I started the thread):

#show <nonumber>: set heading(numbering: none)

I think that’s an expected result - we can’t make references to headings without numbering. Which is also why it’s ok to use a label to disable numbers. We won’t reference those headings.