refactor: Table of Contents

This commit is contained in:
Laurenz 2024-04-18 12:09:55 +02:00
parent 2f399cd5ef
commit bf75041a0c
No known key found for this signature in database
GPG key ID: E3D5C22DBA1A8C36

View file

@ -141,8 +141,8 @@
appendix: none, appendix: none,
// First chapter of your thesis // First chapter of your thesis
// This is required to generate the content section correctly // This is *not* required anymore
first_chapter_title: "Introduction", // first_chapter_title: none,
// Factor of page location when to pagebreak headings // Factor of page location when to pagebreak headings
// to avoid a heading without content on the same page. // to avoid a heading without content on the same page.
@ -404,103 +404,39 @@
#pagebreak() #pagebreak()
= #selected_lang.contents // = #selected_lang.contents
#locate(loc => { #set outline(
let headings = query(heading, loc) indent: n => {
let before_content = true // Max indent is 2
let after_content = false if n > 2 { n = 2 }
return n * 2em
for elem in headings { },
// kind of hacky, we track whether the main document has started by looking for a chapter by name fill: repeat(" . ")
if elem.body == [#first_chapter_title] {
before_content = false
}
// similarly, track the end of the main content by the position of the "Bibliography" chapter
if elem.body == [#selected_lang.bibliography] {
after_content = true
}
// page numbers of the main document are arabic, the first pages are roman
let index_fmt = if before_content {
"I"
} else {
"1"
}
let location = elem.location()
let page_index = counter(page).at(location).at(0)
let formatted_index = numbering(index_fmt, page_index)
// only the main content should be numbered
let formatted_name = if before_content or after_content {
elem.body
} else [
#numbering("1.1", ..counter(heading).at(location))
#h(4pt)
#elem.body
]
let is_chapter = elem.level == 1
// indent headings in the table of contents based on their level
let indent = if is_chapter {
0pt
} else if elem.level == 2 {
2em
} else {
4em
}
// non-chapter headings have their line filled with dots
let spacer = if is_chapter { " " } else { " . " }
// if elem.body != [#selected_lang.abstract] and elem.outlined != false {
if elem.outlined != false {
link(
location,
[
#h(indent)
// add extra spacing between chapters
#if is_chapter {v(1pt)}
// chapters are bold, sections are not
#if is_chapter [*#formatted_name*] else [#formatted_name]
#box(width: 1fr, repeat(spacer))
#h(8pt)
#if is_chapter [*#formatted_index*] else [#formatted_index] \
],
) )
#show outline.entry.where(level: 1): it => {
if it.element.func() != heading { return it }
show ".": ""
v(2pt)
strong(it)
} }
}
})
// #outline(target: heading.) #outline(target: heading, depth: 2, title: selected_lang.contents)
// #show outline.entry.where(
// level: 1
// ): it => {
// v(12pt, weak: true)
// strong(it)
// }
// #outline(target: heading, depth: 3, indent: 2em, fill: repeat(" . "))
#pagebreak()
// start adding headings to the outline after the table of contents // start adding headings to the outline after the table of contents
#set heading(outlined: true) #set heading(outlined: true)
#pagebreak(weak: true)
= #selected_lang.list_of_figures
#show outline.entry: it => [ #show outline.entry: it => [
#v(12pt, weak: true) #it #v(12pt, weak: true) #it
] ]
// List of figures #outline(target: figure, title: none)
= #selected_lang.list_of_figures
#outline(target: figure, title: none, fill: repeat(" . "))
#pagebreak() #pagebreak(weak: true)
= #selected_lang.acronyms = #selected_lang.acronyms