Refactor handout.typ
Reviewed-on: #7 Co-authored-by: Mark <mark@betalupi.com> Co-committed-by: Mark <mark@betalupi.com>
This commit is contained in:
113
lib/typst/local/handout/0.1.0/lib.typ
Executable file
113
lib/typst/local/handout/0.1.0/lib.typ
Executable file
@ -0,0 +1,113 @@
|
||||
/// Typst handout library, used for all documents in this repository.
|
||||
|
||||
// Re-exports
|
||||
// All functions that maybe used by client code are listed here
|
||||
#import "misc.typ": *
|
||||
#import "object.typ": problem, definition, theorem
|
||||
#import "solution.typ": if_solutions, if_no_solutions, solution
|
||||
|
||||
|
||||
/// Main handout wrapper.
|
||||
/// Use this as follows:
|
||||
///
|
||||
/// ```
|
||||
/// #show: handout.with(
|
||||
/// group: "Advanced 2",
|
||||
/// title: [Handout Title],
|
||||
/// by: "author",
|
||||
/// subtitle: "optional",
|
||||
/// )
|
||||
///
|
||||
/// <rest of document>
|
||||
/// ```
|
||||
#let handout(
|
||||
doc,
|
||||
group: none,
|
||||
title: none,
|
||||
by: none,
|
||||
subtitle: none,
|
||||
) = {
|
||||
set page(
|
||||
margin: 20mm,
|
||||
width: 8.5in,
|
||||
height: 11in,
|
||||
footer: align(
|
||||
center,
|
||||
context counter(page).display(),
|
||||
),
|
||||
footer-descent: 5mm,
|
||||
)
|
||||
|
||||
//
|
||||
// Text style
|
||||
set text(font: "New Computer Modern")
|
||||
set par(
|
||||
leading: 0.55em,
|
||||
first-line-indent: 0mm,
|
||||
justify: true,
|
||||
spacing: 0.5em,
|
||||
)
|
||||
|
||||
//
|
||||
// List style
|
||||
show list: set block(spacing: 0.5em, below: 1em)
|
||||
set list(
|
||||
tight: false,
|
||||
indent: 5mm,
|
||||
spacing: 3mm,
|
||||
)
|
||||
|
||||
//
|
||||
// Heading style
|
||||
set heading(numbering: (..nums) => nums.pos().at(0))
|
||||
show heading.where(level: 1): it => {
|
||||
set align(center)
|
||||
set text(weight: "bold")
|
||||
block[
|
||||
Section #counter(heading).display(): #text(it.body)
|
||||
]
|
||||
}
|
||||
|
||||
//
|
||||
// Hack for custom references
|
||||
show ref: it => {
|
||||
import "object.typ": ref_obj
|
||||
|
||||
let x = ref_obj(it) // Custom impl for object references
|
||||
if (x != none) { return x }
|
||||
|
||||
return it // Use default `ref` implementation otherwise
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Begin content
|
||||
//
|
||||
|
||||
// Make handout title
|
||||
{
|
||||
import "header.typ": make_header, solution_warning
|
||||
import "solution.typ": show_solutions
|
||||
|
||||
let url = link(
|
||||
"https://betalupi.com/handouts",
|
||||
"betalupi.com/handouts",
|
||||
)
|
||||
|
||||
make_header(
|
||||
title,
|
||||
subtitle: subtitle,
|
||||
by: by,
|
||||
top_left: group,
|
||||
top_right: url,
|
||||
)
|
||||
|
||||
if show_solutions {
|
||||
solution_warning()
|
||||
}
|
||||
}
|
||||
|
||||
// Include rest of document
|
||||
doc
|
||||
}
|
||||
|
Reference in New Issue
Block a user