Skip to content

Commit

Permalink
Minor refactor, tweaked spacing in thmbox
Browse files Browse the repository at this point in the history
  • Loading branch information
sahasatvik committed Mar 29, 2023
1 parent 52f7631 commit 4667682
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
Binary file modified basic.pdf
Binary file not shown.
Binary file modified differential_calculus.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion differential_calculus.typ
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"exercise",
"Exercise",
stroke: rgb("#ffaaaa") + 1pt,
base: "", // Unattached: count globally
base: none, // Unattached: count globally
).with(numbering: "I") // Use Roman numerals

// Examples and remarks are not numbered
Expand Down
Binary file modified example.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion example.typ
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
none,
(name, number, body) => [ // Format content
#h(1.2em) *Notation #number #name*:
#h(0.5em)
#h(0.2em)
#body
#v(0.5em)
]
Expand Down
45 changes: 28 additions & 17 deletions theorems.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#let thmcounters = state("thm",
(
"counters": ("": (), "heading": ()),
"counters": ("heading": ()),
"latest": ()
)
)
Expand All @@ -12,24 +12,36 @@
// using "fmt", which maps (name, number, body) to content.
//
// Supplying base: "heading" attaches the environment to the heading counter.
// Supplying base: "" makes the environment count up globally, i.e. keeps it unattached.
// Supplying base: none makes the environment count up globally, i.e. keeps it unattached.
//
// A theorem environment is a map (body, name:, numbering:, base:) to content.
// name: none is intended to be shown in the title
// numbering: "1.1" indicates the numbering style, can be "none"
// base: base defaults to the "base" supplied when creating the
// environment, can be overriden here.
// environment, can be overridden here.
// base_level: base_level
// specifies the number of levels of numbering before
// the environment count
// defaults to the "base_level" supplied when creating
// the environment, can be overridden here.

#let thmenv(identifier, base, base_level, fmt) = {

let global_numbering = numbering

return (body, name: none, numbering: "1.1", base: base, base_level: base_level) => {
return (
body,
name: none,
numbering: "1.1",
base: base,
base_level: base_level
) => {
let number = none
if not numbering == none {
locate(loc => {
thmcounters.update(thmpair => {
let counters = thmpair.at("counters")
// Manually update heading counter
counters.at("heading") = counter(heading).at(loc)
if not identifier in counters.keys() {
counters.insert(identifier, (0, ))
Expand All @@ -38,7 +50,8 @@
let tc = counters.at(identifier)
if base != none {
let bc = counters.at(base)


// Pad or chop the base count
if base_level != none {
if bc.len() < base_level {
bc = bc + (0,) * (base_level - bc.len())
Expand All @@ -47,13 +60,14 @@
}
}

// Reset counter if the base counter has updated
if tc.slice(0, -1) == bc {
counters.at(identifier) = (..bc, tc.last() + 1)
} else {
counters.at(identifier) = (..bc, 1)
}
} else {
// if we have no base counter, just count one level
// If we have no base counter, just count one level
counters.at(identifier) = (tc.last() + 1,)
let latest = counters.at(identifier)
}
Expand Down Expand Up @@ -118,14 +132,15 @@
) = {
let boxfmt(name, number, body) = {
if not name == none {
name = [#namefmt(name) :]
name = [ #namefmt(name)]
} else {
name = [:]
name = []
}
let title = titlefmt(head)
let title = head
if not number == none {
title += " " + titlefmt(number)
title += " " + number
}
title = titlefmt(title)
body = bodyfmt(body)
pad(
..padding,
Expand All @@ -136,20 +151,16 @@
width: 100%,
radius: radius,
breakable: breakable,
[
#title
#name
#h(0.5em)
#body
]
[#title#name:#h(0.2em)#body]
)
)
}
return thmenv(identifier, base, base_level, boxfmt)
}


// Plainer defaults on thmbox with no padding, smaller inset, and emphasized title in place of bold.
// Plainer defaults on thmbox with no padding, smaller inset, and emphasized
// title in place of bold.

#let thmplain = thmbox.with(
padding: (top: 0em, bottom: 0em),
Expand Down

0 comments on commit 4667682

Please # to comment.