clean up compsci templates

This commit is contained in:
dogeystamp 2024-03-30 15:51:39 -04:00
parent d07c85a011
commit ea26a0215d
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
5 changed files with 48 additions and 70 deletions

View File

@ -1,23 +0,0 @@
// templates for compsci notes
#import "main.typ": gen_preamble, doc_template, mono_font, lref
#import "compsci.typ": source_code
#let template(
title: none,
authors: none,
body
) = {
doc_template(
title: title,
{
gen_preamble(
title: title,
authors: authors,
prefix: [_Algorithm notes_]
)
body
}
)
}

View File

@ -1,43 +0,0 @@
// generic compsci utilities
#import "main.typ": mono_font
// 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,
)
]
}

View File

@ -1,6 +1,6 @@
// general document // general document
#import "main.typ": gen_preamble, doc_template, lref #import "main.typ": gen_preamble, doc_template, lref, source_code, status
#let template( #let template(
title: none, title: none,

View File

@ -166,3 +166,48 @@
v(29pt, weak: true) v(29pt, weak: true)
body body
} }
////////////////////////////////
// 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,
)
]
}

View File

@ -1,7 +1,6 @@
// templates for compsci problem documents outside of contests // templates for compsci problem documents outside of contests
#import "main.typ": gen_preamble, doc_template, mono_font, lref #import "main.typ": gen_preamble, doc_template, mono_font, lref, source_code, status
#import "compsci.typ": source_code, status
#let template( #let template(
title: none, title: none,
@ -17,7 +16,7 @@
prefix: status(stat: stat), prefix: status(stat: stat),
suffix: { suffix: {
if (problem_url != none) { if (problem_url != none) {
[#linebreak()#link(problem_url)] [#link(problem_url)]
} }
} }
) )