How can I add the word "Chapter" before the chapter title in the table of contents?

Directly in the text, I add the word “Chapter” to the chapter title using show:

#show heading.where(level: 1): it => "Chapter " + counter(heading).display("1. ") + it.body

As expected, “Chapter” does not appear in the table of contents. The documentation recommends changing the construction of table of contents lines using the following construction:

#show outline.entry: it => link(
  it.element.location(),
  it.indented(it.prefix(), it.inner()),
)

But how do I add the prefix itself? I can’t fit anything inside the parentheses.

You could do something like this?

#set heading(numbering: "1.")
#show outline.entry: it => {
  link(
    it.element.location(),
    it.indented([Chapter #it.prefix()], it.inner()))
}
#outline()
#show heading.where(level: 1): it => block("Chapter " + counter(heading).display("1. ") + it.body)
= A
= B
= C

In this case I’ve added a block around the heading again (the show rule), which could of course be removed if it shouldn’t be there.

If you always refer to these headings using the Chapter prefix, then I think you can include the word Chapter in the heading numbering itself. It depends on what you want references to labelled chapters to look like.

Please properly format all your code blocks. How to post in the Questions category

Yea. This is what I needed. Thank you very much.