typst-templates/main.typ

218 lines
4.5 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 = "Nimbus Sans"
#let heading_font = "Nimbus 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.
2023-08-08 21:23:42 -04:00
text(size: 20pt, weight: "black", title, font: heading_font)
2023-04-18 19:59:45 -04:00
}
2023-12-02 20:47:28 -05:00
#let author_string(authors: none) = {
2023-04-18 19:59:45 -04:00
if authors == none {
authors = (
(
name: settings.me,
2023-04-18 19:59:45 -04:00
),
)
}
2023-12-02 20:47:28 -05:00
2023-04-18 19:59:45 -04:00
let names = authors.map(author => author.name)
2023-12-02 20:47:28 -05:00
return if authors.len() == 2 {
2023-04-18 19:59:45 -04:00
names.join(" and ")
} else {
names.join(", ", last: ", and ")
}
2023-12-02 20:47:28 -05:00
}
2023-04-18 19:59:45 -04:00
2023-12-02 20:47:28 -05:00
#let gen_authors(
authors: none,
) = {
2023-12-18 18:41:25 -05:00
text(author_string(authors: authors))
2023-08-08 21:23:42 -04:00
}
#let gen_preamble(
title: none,
authors: none,
prefix: none,
suffix: none,
) = {
pad(left: -2%, {
gen_title(title: title)
v(13pt, weak: true)
pad(left: 1.5pt, prefix)
align(right,
rect(
width: 50%,
stroke: none,
{
[
#{gen_authors(authors: authors)}
]
linebreak()
2023-08-08 21:23:42 -04:00
suffix
})
)
v(10pt)
line(length: 100%, stroke: 1pt + rgb("#555555"))
2023-04-18 19:59:45 -04:00
})
2023-08-08 21:23:42 -04:00
v(5%, weak: true)
2023-04-18 19:59:45 -04:00
}
// this template sets up the document
// but does not do things like title, authors, etc.
#let doc_template(
paper-size: "us-letter",
2023-12-02 20:47:28 -05:00
title: "",
2023-12-18 20:36:00 -05:00
authors: none,
enable-footer: true,
2023-04-18 19:59:45 -04:00
// Content to wrap
body,
) = {
2024-11-10 12:34:06 -05:00
set text(size: normal-size, font: font, weight: "regular", lang: settings.lang, hyphenate: auto)
2024-01-29 21:50:29 -05:00
show link: text.with(fill: rgb("#5577bb"), weight: "bold")
show math.equation: eq => eq
2024-02-08 21:45:51 -05:00
set figure.caption(position: top)
set figure(gap: 1em)
show figure.caption: emph
2023-07-11 22:34:00 -04:00
show figure: fig => {
2024-02-08 21:45:51 -05:00
show: pad.with(x: 1em, y: 0.6em)
show image: pad.with(y: 0.5em)
2023-07-11 22:38:51 -04:00
set image(width: 50%)
2023-07-11 22:34:00 -04:00
set align(center)
fig
2023-07-11 22:34:00 -04:00
}
2023-10-14 16:34:25 -04:00
set table(inset: 10pt, stroke: 0.5pt + black)
show heading: it => [
#set text(font: heading_font, weight: "black")
#text(it)
#v(0.1em)
]
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: 0em,
2023-04-29 18:51:42 -04:00
stroke: luma(230),
fill: luma(250),
2023-04-29 18:51:42 -04:00
pad(
left: 1em,
right: 1em,
top: 1em,
bottom: 1em,
txt
)
)
)
2023-04-18 19:59:45 -04:00
set page(
paper: paper-size,
margin: (top: 8%, rest: 10%),
2023-12-02 20:47:28 -05:00
footer-descent: 50%,
2023-12-18 20:36:00 -05:00
footer: if enable-footer [
2023-12-02 20:47:28 -05:00
#set text(size: 8pt, fill: luma(80))
#columns(3)[
#align(left)[
2024-09-05 11:43:42 -04:00
//©
#author_string(authors: authors),
2023-12-02 20:47:28 -05:00
#datetime.today().year()
]
#colbreak()
#align(center)[
_ #title _
]
#colbreak()
#align(right)[
2024-11-10 12:34:06 -05:00
#context counter(page).display("1")
2023-12-02 20:47:28 -05:00
]
]
],
2023-04-18 19:59:45 -04:00
)
set list(indent: 5pt, body-indent: 5pt, marker: ("▪", "‣"))
2023-05-20 10:11:34 -04:00
set enum(indent: 5pt, body-indent: 5pt)
2023-04-18 19:59:45 -04:00
// Configure paragraph properties.
2024-11-10 12:34:06 -05:00
set par(justify: true, linebreaks: "optimized")
2023-04-18 19:59:45 -04:00
// Display the article's contents.
v(29pt, weak: true)
body
}
2024-03-30 15:51:39 -04:00
////////////////////////////////
// compsci notes utils
////////////////////////////////
// did i finish this problem?
#let status(stat: "incomplete") = {
if stat == "complete" {
text(fill: rgb("#448d00"))[
*Status*: Completed
]
} else if stat == "cheated" {
text(fill: rgb("#aaaa22"))[
*Status*: Solved with editorial
]
} else {
text(fill: rgb("#aa4422"))[
*Status*: Incomplete
]
}
}
// show associated source code
#let source_code(
lang: "cpp",
block: true,
src_path: "problems/src/",
// convert tabs to spaces
detab: true,
problem_id
) = {
let raw_text = read("../" + src_path + problem_id + "." + lang)
if detab {
raw_text = raw_text.replace("\t", " ")
}
text(font: mono_font)[
#raw(
raw_text,
block: true,
lang: lang,
)
]
}