initial commit

This commit is contained in:
dogeystamp 2023-04-18 19:59:45 -04:00
commit c9e2457b6d
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
4 changed files with 215 additions and 0 deletions

40
README.md Normal file
View File

@ -0,0 +1,40 @@
# typst templates
I have the following directory structure for these:
```
docs/
├── problems
│   ├── src
│   │   └── test.cpp
│   ├── test.pdf
│   └── test.typ
└── templates
└── ...
```
Example usage (this is test.typ in the above tree:)
```typ
#import "../templates/problems.typ": template, source_code, status
#show: template.with(
title: "CCC '22 J1 - Cupcake Party",
problem_url: "https://dmoj.ca/problem/cc22j1",
stat: "incomplete",
)
= Thought process
#lorem(20)
== Important things
#lorem(50)
#source_code("test")
```
Need fonts:
- Fira Math
- JetBrains Mono
- Roboto

43
compsci.typ Normal file
View File

@ -0,0 +1,43 @@
// generic compsci utilities
#import "main.typ": mono_font
// did i finish this problem?
#let status(stat: "incomplete") = {
if stat == "complete" {
align(center, {
text(fill: rgb("#aadd44"))[
*Status*: Completed
]
})
} else {
align(center, {
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,
)
]
}

103
main.typ Normal file
View File

@ -0,0 +1,103 @@
// main template that everything inherits from
#let script-size = 12pt
#let footnote-size = 10pt
#let small-size = 9pt
#let normal-size = 12pt
#let large-size = 12pt
#let me = "dogeystamp"
#let font = "Roboto"
#let heading_font = "JetBrains Mono"
#let math_font = "Fira Math"
#let mono_font = "JetBrains Mono"
#let gen_title(
title: none,
) = {
// Set document metadata.
align(center, {
text(size: large-size, weight: 700, title, font: heading_font)
})
}
#let gen_authors(
authors: none,
) = {
if authors == none {
authors = (
(
name: me,
),
)
}
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")
show math.equation: set text(font: math_font)
show heading: set text(font: heading_font)
set page(
paper: paper-size,
)
set heading(numbering: "1.")
set list(indent: 24pt, body-indent: 5pt)
set enum(indent: 24pt, body-indent: 5pt)
show link: set text()
show math.equation: set block(below: 8pt, above: 9pt)
show math.equation: set text(weight: 400)
show figure: it => {
show: pad.with(x: 23pt)
set align(center)
v(12.5pt, weak: true)
// Display the figure's body.
it.body
// Display the figure's caption.
if it.has("caption") {
// Gap defaults to 17pt.
v(if it.has("gap") { it.gap } else { 17pt }, weak: true)
smallcaps[Figure]
if it.numbering != none {
[ #counter(figure).display(it.numbering)]
}
[. ]
it.caption
}
v(15pt, weak: true)
}
// Configure paragraph properties.
set par(first-line-indent: 1.2em, justify: true, leading: 0.8em)
show par: set block(spacing: 2em)
// Display the article's contents.
v(29pt, weak: true)
body
}

29
problems.typ Normal file
View File

@ -0,0 +1,29 @@
// templates for compsci problem documents outside of contests
#import "main.typ": gen_title, gen_authors, doc_template, mono_font
#import "compsci.typ": source_code, status
#let template(
title: none,
authors: none,
problem_url: none,
stat: "incomplete",
body
) = {
doc_template({
gen_title(title: title)
if problem_url != none {
v(10pt, weak: true)
align(center, {
text(scale(link(problem_url)), size: 0.9em, font: mono_font)
v(10pt, weak: true)
})
}
v(10pt, weak: true)
status(stat: stat)
v(15pt, weak: true)
gen_authors(authors: authors)
body
})
}