how to remove numbers from outline?

383 Views Asked by At

I am making a blog style document which has no pages, as a consequence my outline looks like this atm:

enter image description here

I am trying to wrap my head around the show function, I thought this would remove numbering:

#show outline.entry.where(page: []): p => {
}
#outline()

but I was wrong

1

There are 1 best solutions below

0
PgSuper On

This will work (at least for Typst v0.7.0):

#show outline.entry: it => {
  if it.at("label", default: none) == <modified-entry> {
    it // prevent infinite recursion
  } else {
    [#outline.entry(
      it.level,
      it.element,
      it.body,
      [],  // remove fill
      []  // remove page number
    ) <modified-entry>]
  }
}
#outline()

= Abc

== def

=== g

== h

Result (rendered using the Typst rendering bot):

Result of the sample code: outline entries without page numbers or filling dots

(Replace the [], // remove fill line by it.fill, to keep the dotted fill if you want.)

Basically, we used show rules to replace each outline.entry element with a custom one we build. We check if it already has a label arbitrarily called modified-entry; if so, we just return the outline.entry we received unmodified (this is done to prevent the show rule from applying to the custom outline.entry instances we build, which would result in infinite recursion - see https://github.com/typst/typst/issues/229).

Otherwise, we return our custom outline.entry, which we build by copying each field from the original entry (so as to keep its original information), except that we remove the fill and the page number by replacing them with [] (empty content - note that the content type represents any kind of arbitrary markup you can place in the Typst document tree). We also wrap the outline.entry returned inside a larger content block (hence the [ ... ] around it) so that we can append a label to it: <modified-entry> - we use this label to mark outline.entry instances which we already modified, thus using the check described in the paragraph above to prevent infinite recursion on the show rule (prevent it from trying to modify what was already modified, endlessly!).

The result is that we remove the fill (dots) and page number from each outline entry.

For more info, see the docs specifying the parameters/fields for each outline.entry here: https://typst.app/docs/reference/meta/outline/#outline-entry

If this turns out to be useful, you can also check the original PR which introduced the outline.entry element (which I authored!), here (there are some usage examples in the test files): https://github.com/typst/typst/pull/1423