typst-templates/main.typ

125 lines
2.6 KiB
Plaintext
Raw Normal View History

2023-04-18 19:59:45 -04:00
// main template that everything inherits from
#let script-size = 9pt
#let footnote-size = 8pt
#let small-size = 8pt
#let normal-size = 9pt
#let large-size = 9pt
2023-04-18 19:59:45 -04:00
#let font = "IBM Plex Sans"
#let heading_font = "IBM Plex Sans"
#let mono_font = "DejaVu Sans Mono"
2023-04-18 19:59:45 -04:00
#let settings = yaml("/settings.yml")
// reference based on TYPST_ROOT
// use paths like "/problems/problem.pdf"
// which will translate to "/home/user/docs/problems/problem.pdf"
#let lref(
2023-07-10 18:57:49 -04:00
// whether or not to prepend 'pdfref://' to the link. as long as the handler
// is installed, it allows specifying the page number linked to
// see https://github.com/dogeystamp/pyinstantref for details
pdfref: false,
url,
text
) = {
2023-07-10 18:57:49 -04:00
let realUrl = settings.prefix + url;
if (pdfref) {
realUrl = "pdfref://" + realUrl
}
return link(realUrl, text)
}
2023-04-18 19:59:45 -04:00
#let gen_title(
title: none,
) = {
// Set document metadata.
align(center, {
2023-04-29 18:51:42 -04:00
text(size: large-size, weight: "black", title, font: heading_font)
2023-04-18 19:59:45 -04:00
})
}
#let gen_authors(
authors: none,
) = {
if authors == none {
authors = (
(
name: settings.me,
2023-04-18 19:59:45 -04:00
),
)
}
let names = authors.map(author => author.name)
let author-string = if authors.len() == 2 {
names.join(" and ")
} else {
names.join(", ", last: ", and ")
}
align(center, {
text(size: footnote-size, author-string)
v(25pt, weak: true)
})
}
// this template sets up the document
// but does not do things like title, authors, etc.
#let doc_template(
paper-size: "a4",
// Content to wrap
body,
) = {
set text(size: normal-size, font: font, weight: "regular")
2023-05-13 12:18:51 -04:00
show link: body => text(fill: rgb("#777777"), weight: "bold", body)
show math.equation: eq => eq
2023-07-11 22:34:00 -04:00
show figure: fig => {
show: pad.with(x: 1em)
2023-07-11 22:38:51 -04:00
set image(width: 50%)
2023-07-11 22:34:00 -04:00
set align(center)
v(1em)
fig.body
if fig.has("caption") {
v(1em, weak: true)
[Figure ]
if fig.numbering != none {
[#counter(figure).display(fig.numbering)]
}
[. ]
fig.caption
}
}
2023-05-27 11:51:50 -04:00
set table(inset: 10pt)
2023-04-29 18:51:42 -04:00
show heading: set text(font: heading_font, weight: "black")
2023-07-30 11:01:51 -04:00
set heading(numbering: "1.")
2023-04-29 18:51:42 -04:00
show raw.where(block: true): txt => pad(
left: 0.5em,
block(
radius: 0.5em,
stroke: luma(230),
fill: luma(245),
pad(
left: 1em,
right: 1em,
top: 1em,
bottom: 1em,
txt
)
)
)
2023-04-18 19:59:45 -04:00
set page(
paper: paper-size,
)
2023-05-20 10:11:34 -04:00
set list(indent: 5pt, body-indent: 5pt)
set enum(indent: 5pt, body-indent: 5pt)
2023-04-18 19:59:45 -04:00
// Configure paragraph properties.
2023-04-29 18:51:42 -04:00
set par(justify: true)
2023-04-18 19:59:45 -04:00
// Display the article's contents.
v(29pt, weak: true)
body
}