|
| 1 | +# Lemming |
| 2 | +Provides customizable theorem-like and proof environments that aim to behave closely to the way native elements behave. |
| 3 | +This package will upgrade to [native custom elements](https://github.com/typst/typst/issues/147), once they arrive. |
| 4 | +For now it employs the great [elembic](https://typst.app/universe/package/elembic). |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +See the [CHANGELOG](CHANGELOG.md) for differences between versions. |
| 9 | + |
| 10 | + |
| 11 | +## Basic usage |
| 12 | + |
| 13 | +First, create the environments you want to use. |
| 14 | +By default, the `supplement` of the environment will be a capitalized version of the `kind` specified. |
| 15 | +```typ |
| 16 | +#import "@preview/lemming:0.3.1" as lem |
| 17 | +
|
| 18 | +#let theorem = lem.environment.with(kind: "theorem") |
| 19 | +#let lemma = lem.environment.with(kind: "lemma") |
| 20 | +
|
| 21 | +#let proof = lem.proof |
| 22 | +
|
| 23 | +// Unfortunately necessary for now to make references work |
| 24 | +#show: lem.prepare() |
| 25 | +``` |
| 26 | +If you want your environments to use a shared counter, set their `supplement` instead of `kind`, i.e.: [^1] |
| 27 | +```typ |
| 28 | +#let theorem = lem.environment.with(supplement: [Theorem]) |
| 29 | +#let lemma = lem.environment.with(supplement: [Lemma]) |
| 30 | +``` |
| 31 | +[^1]: |
| 32 | + Note that you should pass a value of type `content` and not `str` to `supplement`. |
| 33 | + Otherwise `show`-rules might not work as expected. |
| 34 | + |
| 35 | + |
| 36 | +Now, just use your environments in your document. |
| 37 | + |
| 38 | +```typ |
| 39 | +#theorem(name: "Noether")[ |
| 40 | + #lorem(20) |
| 41 | +] |
| 42 | +
|
| 43 | +#theorem(numbering: none, supplement: [Satz])[ |
| 44 | + #lorem(20) |
| 45 | +] |
| 46 | +``` |
| 47 | + |
| 48 | +## Labels and references |
| 49 | +Due to implementation constraints, you have to specify labels as below instead of attaching it at the back of your environments. |
| 50 | +Hopefully, this will become unnecessary in the future. |
| 51 | +```typ |
| 52 | +#theorem(name: "Noether", label: <theorem:noether>)[ |
| 53 | + #lorem(20) |
| 54 | +] |
| 55 | +``` |
| 56 | +If references do not work, make sure you have applied the following `show` rule. |
| 57 | +```typ |
| 58 | +#show: lem.prepare() |
| 59 | +``` |
| 60 | + |
| 61 | +## Set rules |
| 62 | +You can change the defaults of all parameters using `set` rules. |
| 63 | +```typ |
| 64 | +// Unnecessary as "1.1" is the default numbering |
| 65 | +// Think: #set lem.environment(numbering: "1") |
| 66 | +#show: lem.set_(lem.environment, numbering: "1") |
| 67 | +``` |
| 68 | + |
| 69 | +## Show-Set rules |
| 70 | +You can use `show set` rules too. |
| 71 | +For example, you can make the body text `upright` instead of the default `italic` |
| 72 | +```typ |
| 73 | +// Think: #show lem.environment.body: set text(style: "normal") |
| 74 | +#show lem.selector(lem.environment-body): set text(style: "normal") |
| 75 | +``` |
| 76 | +Self-referential `show set` rules work a bit different than native ones. |
| 77 | +```typ |
| 78 | +// Think: #show lem.environment.where(kind: "theorem"): set lem.environment( |
| 79 | +// numbering: heading-subnumbering( |
| 80 | +// lem.environment.where(kind: "theorem"), 1, "H.1.1" |
| 81 | +// ) |
| 82 | +// ) |
| 83 | +#show: lem.cond-set( |
| 84 | + theorem, |
| 85 | + numbering: heading-subnumbering(lem.counter-name("theorem"), 1, "H.1.1"), |
| 86 | +) |
| 87 | +``` |
| 88 | +This rules employs the `heading-subnumbering` function from the [discount](https://typst.app/universe/package/discount) package. |
| 89 | + |
| 90 | +**Advice**: Instead of setting block properties |
| 91 | +```typ |
| 92 | +#show lem.selector(lem.proof): set block(inset: (left: 1cm)) // DON'T DO THIS |
| 93 | +``` |
| 94 | +wrapping elements in blocks leads to less unwanted side-effects |
| 95 | +```typ |
| 96 | +#show: lem.show_(lem.proof, it => block(inset: (left: 1cm), it)) |
| 97 | +``` |
| 98 | + |
| 99 | +## Show rules |
| 100 | +To customize the display of your environment even further, you can write a custom `show` rule. |
| 101 | +```typ |
| 102 | +// Think: #show lem.environment: box(stroke: blue) |
| 103 | + #show: lem.show_(lem.environment, it => box(stroke: blue, it)) |
| 104 | +``` |
| 105 | +These can be conditional too. |
| 106 | +```typ |
| 107 | +// Think: #show lem.environment.where(kind: "lemma"): it => box(stroke: red, inset: 0.5em, it) |
| 108 | +#show: lem.show_(lemma, it => box(stroke: red, inset: 0.5em, it)) |
| 109 | +``` |
| 110 | + |
| 111 | +To change the visuals further, you can write a full custom `show`-rule. |
| 112 | +For example, if you want the number at front and the supplement in smallcaps, you can write the following. |
| 113 | +```typ |
| 114 | +#show: lem.show_(lem.environment, it => { |
| 115 | + it = lem.fields(it) // Hopefully not necessary in the future |
| 116 | + block({ |
| 117 | + strong( |
| 118 | + if it.numbering != none { |
| 119 | + numbering(it.numbering, ..it.counter.get()) |
| 120 | + sym.space.nobreak |
| 121 | + } + smallcaps(it.supplement), |
| 122 | + ) |
| 123 | + if it.name != none { |
| 124 | + [ (#emph(it.name))] |
| 125 | + } |
| 126 | + strong(it.separator) |
| 127 | +
|
| 128 | + // For convenience, by default it just makes text italic |
| 129 | + lem.environment-body(it.body) |
| 130 | + }) |
| 131 | +}) |
| 132 | +``` |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | +## HTML |
| 137 | +In HTML export, `environment` elements emit a `math-environment` tag and `proof` elements emit a `math-proof` tag. |
| 138 | + |
| 139 | +## Enviroment Fields |
| 140 | +While writing your `show` rule, you can acess the following fields on `it`: |
| 141 | +| name | type | description | |
| 142 | +| -- | -- | -- | |
| 143 | +| body | `content` | The body of the environment, required and positional. | |
| 144 | +| name | `content \| none` | Additional note for the environment, for example the name of a theorem. | |
| 145 | +| kind | `str` | The kind of math environment. Default: `"theorem"`| |
| 146 | +| supplement | `content \| auto` | The word used for the environment. Defaults to the capizalized kind. | |
| 147 | +| separator | `content` | The symbol between between the header and body. Default: `[. ]` | |
| 148 | +| numbering | `str \| function \| none` | How to number the environment. Accepts a numbering pattern or function. Default: `"1.1"` | |
| 149 | +| end-marker | `content \| none` | The symbol to place at the end of the environment. Default: `none` | |
| 150 | +| counter | `counter` | The counter corresponding to the environment, synthesized. | |
| 151 | + |
| 152 | +## Proofs |
| 153 | +The `proof` environment works similar and should do exactly what you expect. |
| 154 | +Its fields are: |
| 155 | + |
| 156 | +| name | type | description | |
| 157 | +| -- | -- | -- | |
| 158 | +| body | `content` | The body of the proof, required and positional. | |
| 159 | +| supplement | `content` | The term before the proof body, Default `"Proof"` | |
| 160 | +| separator | `content` | The symbol between proof supplement and body, Default: `[. ]` | |
| 161 | +| qed | `content \| none` | The Symbol to insert after the body, Default: `$square$` | |
0 commit comments