Skip to content

Commit

Permalink
Added features contributed by DVDTSB, via ctheorems
Browse files Browse the repository at this point in the history
  • Loading branch information
sahasatvik committed Sep 22, 2023
1 parent 5dccab9 commit c115e60
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 30 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The [differential_calculus.typ](differential_calculus.typ) ([render](differentia
#show: thmrules
#set page(width: 16cm, height: auto, margin: 1.5cm)
#set text(font: "Linux Libertine", lang: "en")
#set heading(numbering: "1.1.")
#let theorem = thmbox("theorem", "Theorem", fill: rgb("#eeffee"))
Expand All @@ -51,8 +52,8 @@ The [differential_calculus.typ](differential_calculus.typ) ([render](differentia
= Prime numbers
#definition[
A natural number is called a _prime number_ if it is greater than 1
and cannot be written as the product of two smaller natural numbers.
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]
#example[
The numbers $2$, $3$, and $17$ are prime.
Expand All @@ -76,6 +77,21 @@ The [differential_calculus.typ](differential_calculus.typ) ([render](differentia
#corollary[
There are infinitely many composite numbers.
]
```


## Acknowledgements

Thanks to

- [MJHutchinson]("https://github.com/MJHutchinson") for suggesting and
implementing the `base_level` and `base: none` features,
- [rmolinari]("https://github.com/rmolinari") for suggesting and
implementing the `separator: ...` feature,
- [DVDTSB]("https://github.com/DVDTSB") for contributing
- the idea of passing named arguments from the theorem directly to the `fmt`
function.
- the `number: ...` override feature.
- the `title: ...` override feature in `thmbox`.
- The awesome devs of [typst.app]("https://typst.app/") for their
support.
Binary file modified basic.pdf
Binary file not shown.
Binary file modified basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions basic.typ
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
= Prime numbers

#definition[
A natural number is called a _prime number_ if it is greater than 1
and cannot be written as the product of two smaller natural numbers.
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]
#example[
The numbers $2$, $3$, and $17$ are prime.
Expand Down
Binary file modified differential_calculus.pdf
Binary file not shown.
Binary file modified manual.pdf
Binary file not shown.
79 changes: 67 additions & 12 deletions manual.typ
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ sets some plainer defaults. You can also write

Note that the last _Lemma_ is _not_ numbered 3.1.2!

You can also override the automatic numbering as follows.
```typst
#lemma(number: "42")[
The square of any natural number cannot be two more than a multiple of 4.
]
```
#lemma(number: "42")[
The square of any natural number cannot be two more than a multiple of 4.
]

Note that this does _not_ affect the counters either!


== Limiting depth

Expand Down Expand Up @@ -286,9 +298,10 @@ You can go even further and use the `thmenv` function directly. It accepts an
"Notation", // supplement
none, // base - do not attach, count globally
none, // base_level - use the base as-is
(name, number, body) => [ // fmt - format content using the environment
// name, number, and body
#h(1.2em) *Notation (#number) #name*:
(name, number, body, color: black) => [
// fmt - format content using the environment
// name, number, body, and an optional color
#text(color)[#h(1.2em) *Notation (#number) #name*]:
#h(0.2em)
#body
#v(0.5em)
Expand All @@ -298,14 +311,18 @@ You can go even further and use the `thmenv` function directly. It accepts an
#notation[
The variable $p$ is reserved for prime numbers.
]
#notation("for Reals", color: green)[
The variable $x$ is reserved for real numbers.
]
```
#let notation = thmenv(
"notation", // identifier
"Notation", // supplement
none, // base - do not attach, count globally
none, // base_level - use the base as-is
(name, number, body) => [ // fmt - format content using the environment name, number, and body
#h(1.2em) *Notation (#number) #name*:
(name, number, body, color: black) => [
// fmt - format content using the environment name, number, body, and an optional color
#text(color)[#h(1.2em) *Notation (#number) #name*]:
#h(0.2em)
#body
#v(0.5em)
Expand All @@ -315,6 +332,27 @@ You can go even further and use the `thmenv` function directly. It accepts an
#notation[
The variable $p$ is reserved for prime numbers.
]
#notation("for Reals", color: green)[
The variable $x$ is reserved for real numbers.
]

Note that the `color: green` named argument supplied to the theorem
environment gets passed to the `fmt` function. In general, all extra named
arguments supplied to the theorem will be passed to `fmt`.
On the other hand, the positional argument `"for Reals"` will always be
interpreted as the `name` argument in `fmt`.

```typst
#lemma(title: "Lem.")[
All multiples of 3 greater than 3 are composite.
]
```
#lemma(title: "Lem.")[
All multiples of 3 greater than 3 are composite.
]

Here, we override the `title` (which defaults to the `head`) in the `fmt`
produced by `thmbox`.


== Labels and references <references>
Expand Down Expand Up @@ -392,15 +430,20 @@ The `thmenv` function produces a _theorem environment_.
base, // base counter name, can be "heading" or none
base_level, // number of base number levels to use
fmt // formatting function of the form
// (name, number, body) -> content
// (name, number, body, ..args) -> content
) = { ... }
```

The `fmt` function must aceept a theorem `name`, `number`, `body`, and produce
formatted content. It may also accept additional positional arguments, via
`args`.

A _theorem environment_ is itself a map of the following form.
```typst
(
..name, // name, often used in the title
..args,
body, // body content
number: auto, // number, overrides numbering if present
numbering: "1.1", // numbering style, can be a function
refnumbering: auto, // numbering style used in references,
// defaults to "numbering"
Expand All @@ -409,6 +452,11 @@ A _theorem environment_ is itself a map of the following form.
) -> content
```

Positional arguments in `args` are as follows
- `name`: The name of the theorem, typically displayed after the title.

All additional named arguments in `args` will be passed on to the associated
`fmt` function supplied in `thmenv`.


== `thmbox` and `thmplain`
Expand Down Expand Up @@ -452,8 +500,15 @@ defaults.

= Acknowledgements

Thanks to #link("https://github.com/MJHutchinson")[MJHutchinson] for
suggesting and implementing the `base_level` and `base: none` features,
#link("https://github.com/rmolinari")[rmolinari] for suggesting and
implementing the `separator: ...` feature, and to the awesome devs of
#link("https://typst.app/")[typst.app] for their support.
Thanks to
- #link("https://github.com/MJHutchinson")[MJHutchinson] for suggesting and
implementing the `base_level` and `base: none` features,
- #link("https://github.com/rmolinari")[rmolinari] for suggesting and
implementing the `separator: ...` feature,
- #link("https://github.com/DVDTSB")[DVDTSB] for contributing
- the idea of passing named arguments from the theorem directly to the `fmt`
function.
- the `number: ...` override feature.
- the `title: ...` override feature in `thmbox`.
- The awesome devs of #link("https://typst.app/")[typst.app] for their
support.
Binary file modified manual_examples.pdf
Binary file not shown.
15 changes: 12 additions & 3 deletions manual_examples.typ
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ these has been explained in full detail there.
#lemma[
The square of any odd number is one more than a multiple of $4$.
]

#lemma(number: "42")[
The square of any natural number cannot be two more than a multiple of 4.
]

== Limiting depth

Expand Down Expand Up @@ -120,8 +122,9 @@ these has been explained in full detail there.
"Notation", // supplement
none, // base - do not attach, count globally
none, // base_level - use the base as-is
(name, number, body) => [ // fmt - format content using the environment name, number, and body
#h(1.2em) *Notation (#number) #name*:
(name, number, body, color: black) => [
// fmt - format content using the environment name, number, body, and an optional color
#text(color)[#h(1.2em) *Notation (#number) #name*]:
#h(0.2em)
#body
#v(0.5em)
Expand All @@ -131,7 +134,13 @@ these has been explained in full detail there.
#notation[
The variable $p$ is reserved for prime numbers.
]
#notation("for Reals", color: green)[
The variable $x$ is reserved for real numbers.
]

#lemma(title: "Lem.")[
All multiples of 3 greater than 3 are composite.
]

== Labels and references <references>

Expand Down
24 changes: 14 additions & 10 deletions theorems.typ
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,26 @@
let global_numbering = numbering

return (
..name,
..args,
body,
number: auto,
numbering: "1.1",
refnumbering: auto,
base: base,
base_level: base_level
) => {
if name != none and name.pos().len() > 0 {
name = name.pos().first()
} else {
name = none
let name = none
if args != none and args.pos().len() > 0 {
name = args.pos().first()
}
if refnumbering == auto {
refnumbering = numbering
}
let number = none
let result = none
if not numbering == none {
if number == auto and numbering == none {
number = []
}
if number == auto and numbering != none {
result = locate(loc => {
return thmcounters.update(thmpair => {
let counters = thmpair.at("counters")
Expand Down Expand Up @@ -79,7 +81,7 @@
}
figure(
result + // hacky!
align(left, fmt(name, number, body)) +
align(left, fmt(name, number, body, ..args.named())) +
figure(none, supplement: none, numbering: none, kind: "thmenv-counter", gap: 0em), // even more hacky!
kind: "thmenv",
outlined: false,
Expand Down Expand Up @@ -111,13 +113,15 @@
if supplement == auto {
supplement = head
}
let boxfmt(name, number, body) = {
let boxfmt(name, number, body, title: auto) = {
if not name == none {
name = [ #namefmt(name)]
} else {
name = []
}
let title = head
if title == auto {
title = head
}
if not number == none {
title += " " + number
}
Expand Down

0 comments on commit c115e60

Please # to comment.