forked from flavio20002/typst-orange-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-index.typ
88 lines (79 loc) · 2.69 KB
/
my-index.typ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#let classes = (main: "Main")
#let index_string = "my_index"
#let index(content) = place(hide(
figure(
classes.main,
caption: content,
numbering: none,
kind: index_string
)))
#let make-index-int(title: none, main-color-state:none) = {
let content-text(content) = {
let ct = ""
if content.has("text") {
ct = content.text
}
else {
for cc in content.children {
if cc.has("text") {
ct += cc.text
}
}
}
return ct
}
set par(first-line-indent: 0em)
context{
let main-color = main-color-state.at(here())
let elements = query(selector(figure.where(kind: index_string)).before(here()))
let words = (:)
for el in elements {
let ct = ""
if el.caption.has("body"){
ct = content-text(el.caption.body)
}
else{
ct = content-text(el.caption)
}
// Have we already know that entry text? If not,
// add it to our list of entry words
if words.keys().contains(ct) != true {
words.insert(ct, ())
}
// Add the new page entry to the list.
let ent = (class: el.body.text, page: el.location().page())
if not words.at(ct).contains(ent){
words.at(ct).push(ent)
}
}
let sortedkeys = words.keys().sorted()
let register = ""
if title != none {
heading(level: 1, numbering: none, title)
}
block(columns(2,gutter: 1cm, [
#for sk in sortedkeys [
#let formattedPageNumbers = words.at(sk).map(en => {
link((page: en.page, x:0pt, y:0pt), text(fill: black, str(en.page)))
})
#let firstCharacter = sk.first()
#if firstCharacter != register {
v(1em, weak:true)
box(width: 100%, fill: main-color.lighten(60%), inset: 5pt, align(center, text(size: 1.1em, weight: "bold", firstCharacter)))
register = firstCharacter
v(1em, weak:true)
}
#set text(size: 0.9em)
#if(sk.contains("!")){
h(2em)
sk.slice(sk.position("!")+1)
}else{
sk
}
#box(width: 1fr, repeat(text(weight: "regular")[. #h(4pt)]))
#formattedPageNumbers.join(",")
#v(0.65em, weak:true)
]
]))
}
}