What is the type of 'body'?

heading.body is of type content, see: Heading Function – Typst Documentation

There is corrently no “official” way to turn content into a string, but a workaround by @Eric can be found here: Turning content into string: `str(content)` · Issue #2196 · typst/typst · GitHub

#let to-string(it) = {
  if type(it) == str {
    it
  } else if type(it) != content {
    str(it)
  } else if it.has("text") {
    it.text
  } else if it.has("children") {
    it.children.map(to-string).join()
  } else if it.has("body") {
    to-string(it.body)
  } else if it == [ ] {
    " "
  }
}

Also when posting code snippeats, make sure to wrap them in triple backticks :slight_smile: