What are the possible targets for outline?

I’m writting this template that has a table of contents, list of images, list of tables, etc. These you can outline with a proper selector (i.g., #outline(target: figure.where(kind: image))).

I know I can create my custom figure kind, but what if I didn’t want figures nor headings?

The documentation says that the target can be a label, selector, location or function. But I’ve tried passing a label to text to no avail. Tried passing in a function, but it complained that it wasn’t an element function. I tried location, but that required context, which started to feel unnecessarily complex.

The docs don’t really show any other example other than heading and figure, so I wanted to know what more I could do.

For context, I’m trying to create a list of abreviations, so I created my own function that manages state.

#let abreviations() = {
  let abreviation-dict = state("abreviations", (:))

  let add-abreviation(key: none, value: none, description: none) = {
    if key == none or value == none or description == none {
      panic("Key, value and description are necessary parameters.")
    }
    abreviation-dict.update(old => {
      old.insert(key, (value: value, description: description))
    })

    [#description (#value)]
  }

  (add-abreviation)
}
#let (add-abreviation) = abreviations()

The idea would be to increment it with either a label or location that could be used by outline.

Looking at the typst source reveals that Headings, Figures, and Equations (and only these) are “Outlineable”:

(See Code search results · GitHub)

If you want to create an outline of something else, you have to fake it. That is, you need to iterate over all your abbreaviations that you have in the state, and display them yourself.


Also, you might be interested in the existing packages that do abbreviations, many of these have a “List of abbreviations” feature: Search — Typst: Universe

1 Like

It’s also possible to create an outline of figures of your custom type. To get more than one kind here you’d need to use the selector.or().

#outline(title: [All], target: figure)

#outline(title: [Table], target: figure.where(kind: table))

#outline(title: [Custom], target: figure.where(kind: "custom"))

#pagebreak()

#figure(
  table(..range(2).map(str)),
  // kind: auto,
  caption: [Table figure]
)

#pagebreak()

#figure(
  box(stroke: black)[Figure],
  kind: "custom",
  supplement: "Figure ",
  caption: [Custom figure]
)

1 Like

There is a list of locatable elements, but not a list of outlinable elements. See Provide a list of outlineable elements · Issue #7900 · typst/typst · GitHub.