phd-typst/template.typ

92 lines
1.9 KiB
Plaintext

#let phd(doc) = {
set page(paper: "a4", numbering: "1")
set par(first-line-indent: 1em, justify: true, leading: 1em)
// Code formatting
show raw.where(block: true): it => {
set par(justify: false)
let split = it.text.split("\n")
let len = split.len()
grid(
columns: (100%, 100%),
column-gutter: -100%,
block(width: 100%, inset: 1em, for (i, line) in split.enumerate() {
if i != len - 1 {
box(width: 0pt, align(right, str(i + 1) + h(2em)))
hide(line)
linebreak()
}
}),
block(radius: 1em, fill: luma(246), width: 100%, inset: 1em, it),
)
}
show heading: content => {
v(0.5em)
content
v(0.38em)
}
show figure: content => {
content
v(1em)
}
show link: content => {
set text(fill: blue)
content
}
show cite: content => {
set text(fill: blue)
content
}
show ref: content => {
set text(fill: blue)
content
}
set heading(supplement: (..nums) =>
if (nums.pos().len() == 1) {
[Chapter]
} else {
[Section]
}
)
set heading(numbering: (..nums) => {
if nums.pos().len() >= 4 {
none
} else {
nums.pos().map(str).join(".") + " "
}
})
show heading.where(level: 1): it => {
set text(size: 11pt, weight: "regular")
align(right, {
pagebreak();
v(100pt)
if it.numbering != none {
text(size: 50pt, weight: "bold")[Chapter ]
set heading(numbering: (..nums) => str(nums.pos().at(0)))
text(counter(heading).display(), size: 150pt, fill: rgb(173, 216, 230))
}
v(50pt)
text(it.body, size: 40pt, weight: "bold")
if it.numbering != none {
pagebreak()
} else {
v(40pt)
}
})
}
show heading.where(level: 2): set text(size: 15pt)
show heading.where(level: 3): set text(size: 13pt)
doc
}