Skip to content

Commit

Permalink
Removed thmref, normal references work (breaking change)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahasatvik committed Sep 22, 2023
1 parent d09b6ea commit d1e8076
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 169 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Copy and import the [theorems.typ](theorems.typ) file to use in your own project
- Environments can share the same counter, via same `identifier`s.
- Environment counters can be _attached_ (just as subheadings are attached to headings) to other environments, headings, or keep a global count via `base`.
- The depth of a counter can be manually set, via `base_level`.
- Environment numbers can be referenced, via `#thmref(<label>)[]`.
Currently, the `<label>` must be placed _inside_ the environment.
- Environments can be referenced, via `@references`.

## Manual and Examples
Get acquainted with `typst-theorems` by checking out the minimal example below!
Expand All @@ -24,6 +23,7 @@ The [differential_calculus.typ](differential_calculus.typ) ([render](differentia
### Preamble
```
#import "theorems.typ": *
#show: thmrules
#set page(width: 16cm, height: auto, margin: 1.5cm)
#set heading(numbering: "1.1.")
Expand Down Expand Up @@ -56,11 +56,10 @@ The [differential_calculus.typ](differential_calculus.typ) ([render](differentia
]
#example[
The numbers $2$, $3$, and $17$ are prime.
#thmref(<cor_largest_prime>)[Corollary] shows that this list is not
exhaustive!
@cor_largest_prime shows that this list is not exhaustive!
]
#theorem(name: "Euclid")[
#theorem("Euclid")[
There are infinitely many primes.
]
#proof[
Expand All @@ -72,8 +71,8 @@ The [differential_calculus.typ](differential_calculus.typ) ([render](differentia
]
#corollary[
There is no largest prime number. <cor_largest_prime>
]
There is no largest prime number.
] <cor_largest_prime>
#corollary[
There are infinitely many composite numbers.
]
Expand Down
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.
10 changes: 5 additions & 5 deletions basic.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "theorems.typ": *
#show: thmrules

#set page(width: 16cm, height: auto, margin: 1.5cm)
#set text(font: "Linux Libertine", lang: "en")
Expand Down Expand Up @@ -30,11 +31,10 @@
]
#example[
The numbers $2$, $3$, and $17$ are prime.
#thmref(<cor_largest_prime>)[Corollary] shows that this list is not
exhaustive!
@cor_largest_prime shows that this list is not exhaustive!
]

#theorem(name: "Euclid")[
#theorem("Euclid")[
There are infinitely many primes.
]
#proof[
Expand All @@ -46,8 +46,8 @@
]

#corollary[
There is no largest prime number. <cor_largest_prime>
]
There is no largest prime number.
] <cor_largest_prime>
#corollary[
There are infinitely many composite numbers.
]
Binary file modified differential_calculus.pdf
Binary file not shown.
11 changes: 6 additions & 5 deletions differential_calculus.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "theorems.typ": *
#show: thmrules

// Define theorem environments

Expand Down Expand Up @@ -195,7 +196,7 @@
$
]
]
#theorem(name: "Chain Rule")[
#theorem("Chain Rule")[
Let $f: RR^n -> RR^m$, $g: RR^m -> RR^k$ where $f$ is differentiable at $a
in RR^n$ and $g$ is differentiable at $f(a) in RR^m$. Then, $g compose
f$ is differentiable, with $D(g compose f)(a) = Dg(f(a)) compose Df(a)$.
Expand Down Expand Up @@ -564,7 +565,7 @@ $
]

= Inverse and implicit function theorems
#theorem(name: [Inverse function theorem])[
#theorem([Inverse function theorem])[
Let $f: RR^n -> RR^n$ be continuously differentiable on a neighbourhood
of $a in RR^n$, and let $"det" (Df(a)) != 0$. Then, there exist neighbourhoods
$U$ of $a$ and $W$ of $f(a)$ such that the restriction $f: U -> W$ is
Expand Down Expand Up @@ -615,7 +616,7 @@ $
]
]

#theorem(name: [Implicit function theorem])[
#theorem([Implicit function theorem])[
Let $f: RR^n times RR^m -> RR^m$ be continuously differentiable in an open
set containing $(a, b)$, with $f(a, b) = 0$. Let $"det" (diff f^j \/ diff
x_(n + k) (a, b)) != 0$. Then, there exists an open set $U subset RR^n$
Expand Down Expand Up @@ -649,15 +650,15 @@ $

= Taylor's theorem

#theorem(name: "Clairaut")[
#theorem("Clairaut")[
Let $f: RR^n -> RR$ have continuous second order partial derivatives.
Then, $
frac(diff ^2 f, diff x_i diff x_j) = frac(diff ^2
f, diff x_j diff x_i).
$
]

#theorem(name: "Taylor")[
#theorem("Taylor")[
Let $f: RR^2 -> RR$ have continuous second order partial derivatives,
and let $(x_0, y_0) in RR^2$. Then, there exists $ epsilon > 0$ such that
for all $norm((x - x_0, y - y_0)) < epsilon$,
Expand Down
Binary file modified manual.pdf
Binary file not shown.
126 changes: 43 additions & 83 deletions manual.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "manual_template.typ": *
#import "theorems.typ": *
#show: thmrules

#show: project.with(
title: "typst-theorems",
Expand Down Expand Up @@ -35,11 +36,13 @@ counters for this purpose. Environments can
Import all functions provided by `typst-theorems` using
```typst
#import "theorems.typ": *
#show: thmrules
```
The second line is crucial for displaying `thmenv`s and references correctly!

The core of this module consists of `thmenv` and `thmref`. The functions
`thmbox` and `thmplain` provide some simple defaults for the appearance of
`thmenv`s.
The core of this module consists of `thmenv`.
The functions `thmbox` and `thmplain` provide some simple defaults for the
appearance of `thmenv`s.


= Feature demonstration
Expand All @@ -63,22 +66,22 @@ Create box-like _theorem environments_ using `thmbox`, a wrapper around
Such definitions are convenient to place in the preamble or a template; use
the environment in your document via
```typst
#theorem(name: "Euclid")[
There are infinitely many primes. <euclid>
]
#theorem("Euclid")[
There are infinitely many primes.
] <euclid>
```

This produces the following.
#theorem(name: "Euclid")[
There are infinitely many primes. <euclid>
]
#theorem("Euclid")[
There are infinitely many primes.
] <euclid>

Note that `name` is optional. This `theorem` environment will be numbered
Note that the `name` is optional. This `theorem` environment will be numbered
based on its parent `heading` counter, with successive `theorem`s
automatically updating the final index.

The `<euclid>` label can be used to refer to this Theorem via `thmref`;
this will be futher explained in @references[Section].
The `<euclid>` label can be used to refer to this Theorem via the reference
`@euclid`. Go to @references to read more.

You can create another environment which uses the same counter, say for
_Lemmas_, as follows.
Expand Down Expand Up @@ -131,7 +134,7 @@ _Corollaries_ can be created as follows.

Note that we have provided a `numbering` string; this can be any valid
numbering pattern as described in the
#linkb("https://typst.app/docs/reference/meta/numbering/")[numbering]
#link("https://typst.app/docs/reference/meta/numbering/")[numbering]
documentation.


Expand Down Expand Up @@ -189,7 +192,7 @@ You can limit the number of levels of the `base` numbering used as follows.
stroke: rgb("#68ff68") + 1pt
)
#definition(name: "Prime numbers")[
#definition("Prime numbers")[
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. <prime>
]
Expand All @@ -200,20 +203,20 @@ You can limit the number of levels of the `base` numbering used as follows.
base_level: 1,
stroke: rgb("#68ff68") + 1pt
)
#definition(name: "Prime numbers")[
#definition("Prime numbers")[
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. <prime>
]

Note that this environment is _not_ numbered 3.2.1!

```typst
#definition(name: "Composite numbers")[
#definition("Composite numbers")[
A natural number is called a _composite number_ if it is greater than $1$
and not prime.
]
```
#definition(name: "Composite numbers")[
#definition("Composite numbers")[
A natural number is called a _composite number_ if it is greater than $1$
and not prime.
]
Expand Down Expand Up @@ -280,6 +283,7 @@ You can go even further and use the `thmenv` function directly. It accepts an
```typst
#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
Expand All @@ -297,6 +301,7 @@ You can go even further and use the `thmenv` function directly. It accepts an
```
#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
Expand All @@ -314,64 +319,33 @@ You can go even further and use the `thmenv` function directly. It accepts an

== Labels and references <references>

You can place a `<label>` _inside_ a theorem environment to reference it later
via `thmref`.
You can place a `<label>` outside a theorem environment, and reference it
later via `@` references! For example, go back to @euclid.

```typst
Recall that there are infinitely many prime numbers via
#thmref(<euclid>)[Theorem].
Recall that there are infinitely many prime numbers via @euclid.
```
#pad(
left: 1.2em,
[
Recall that there are infinitely many prime numbers via
#thmref(<euclid>)[Theorem].
Recall that there are infinitely many prime numbers via @euclid.
]
)

The optional `fmt` argument can be used to convert the counter value (an array
of integers) and the optional body text into content.

```typst
#let numfmt = (nums, body) => {
if body.pos().len() > 0 {
body = body.pos().join(" ")
return smallcaps([#body (#strong(numbering("1.1", ..nums)))])
}
return smallcaps(strong(numbering("1.1", ..nums)))
}
You can reference future environments too, like
#thmref(<oddprime>, fmt: numfmt)[Corollary].
You can reference future environments too, like @oddprime[Cor.].
```
#let numfmt = (nums, body) => {
if body.pos().len() > 0 {
body = body.pos().join(" ")
return smallcaps([#body (#strong(numbering("1.1", ..nums)))])
}
return smallcaps(strong(numbering("1.1", ..nums)))
}
#pad(
left: 1.2em,
[
You can reference future environments too, like
#thmref(<oddprime>, fmt: numfmt)[Corollary].
You can reference future environments too, like @oddprime[Cor.].
]
)

Note that all such references are links to the the label location. The
`makelink` argument lets you disable this behaviour.
```typst
This reference to #thmref(<prime>, makelink: false)[Definition] is not
linked!
```
#pad(
left: 1.2em,
[
This reference to #thmref(<prime>, makelink: false)[Definition] is not
linked!
]
)
*Caution*: Links created by references to `thmenv`s will be styled according
to `#show link:` rules.



== Overriding `base`
Expand All @@ -383,8 +357,8 @@ linked!
]
#corollary[
All primes greater than $2$ are odd. <oddprime>
]
All primes greater than $2$ are odd.
] <oddprime>
#remark(base: "corollary")[
Two is a _lone prime_.
]
Expand All @@ -395,8 +369,8 @@ linked!
There are infinitely many composite numbers.
]
#corollary[
All primes greater than $2$ are odd. <oddprime>
]
All primes greater than $2$ are odd.
] <oddprime>
#remark(base: "corollary")[
Two is a _lone prime_.
]
Expand All @@ -414,6 +388,7 @@ The `thmenv` function produces a _theorem environment_.
```typst
#let thmenv(
identifier, // environment counter name
supplement, // supplement used in references
base, // base counter name, can be "heading" or none
base_level, // number of base number levels to use
fmt // formatting function of the form
Expand All @@ -424,32 +399,16 @@ The `thmenv` function produces a _theorem environment_.
A _theorem environment_ is itself a map of the following form.
```typst
(
..name, // name, often used in the title
body, // body content
name: "", // name, often used in the title
numbering: "1.1", // numbering style, can be a function
refnumbering: auto, // numbering style used in references,
// defaults to "numbering"
base: base, // base counter name override
base_level: base_level // base_level override
) -> content
```

== `thmref`

A `<label>` placed within an environment can be referenced using `thmref`.
```typst
#let thmref(
label, // label
fmt: auto, // formatting function, of the form
// (number array, body arguments) -> content
makelink: true, // create link to label
..body // body - typically prepended to number
) = { ... }
```

Note that the `<label>` _must_ be attached to something _inside_ the
environment.

*Caution*: Links created by `thmref` will be styled according to `#show link:`
rules, not `#show ref:` rules.


== `thmbox` and `thmplain`
Expand All @@ -459,6 +418,7 @@ The `thmbox` wraps `thmenv`, supplying a box-like `fmt` function.
#let thmbox(
identifier, // identifier
head, // head - common name, used in the title
supplement: auto, // supplement for references, defaults to "head"
fill: none, // box fill
stroke: none, // box stroke
inset: 1.2em, // box inset
Expand Down Expand Up @@ -492,8 +452,8 @@ defaults.

= Acknowledgements

Thanks to #linkb("https://github.com/MJHutchinson")[MJHutchinson] for
Thanks to #link("https://github.com/MJHutchinson")[MJHutchinson] for
suggesting and implementing the `base_level` and `base: none` features,
#linkb("https://github.com/rmolinari")[rmolinari] for suggesting and
#link("https://github.com/rmolinari")[rmolinari] for suggesting and
implementing the `separator: ...` feature, and to the awesome devs of
#linkb("https://typst.app/")[typst.app] for their support.
#link("https://typst.app/")[typst.app] for their support.
Binary file modified manual_examples.pdf
Binary file not shown.
Loading

0 comments on commit d1e8076

Please # to comment.