Lemmify is a library for typesetting mathematical theorems in typst. It aims to be easy to use while trying to be as flexible and idiomatic as possible. This means that the interface might change with updates to typst (for example if userdefined element functions are introduced). But no functionality should be lost.
Basic Usage
To get started with Lemmify, follow these steps:
 Import the Lemmify library:
#import "@preview/lemmify:0.1.6": *
 Define the default styling for a few default theorem types:
#let (
theorem, lemma, corollary,
remark, proposition, example,
proof, rules: thmrules
) = defaulttheorems("thmgroup", lang: "en")
 Apply the generated styling:
#show: thmrules
 Create theorems, lemmas, and proofs using the defined styling:
#theorem(name: "Some theorem")[
Theorem content goes here.
]<thm>
#proof[
Complicated proof.
]<proof>
@proof and @thm[theorem]
 Customize the styling further using show rules. For example, to add a red box around proofs:
#show thmselector("thmgroup", subgroup: "proof"): it => box(
it,
stroke: red + 1pt,
inset: 1em
)
The result should now look something like this:
Useful examples
If you do not want to reset the theorem counter on headings you can use the maxresetlevel
parameter:
defaulttheorems("thmgroup", maxresetlevel: 0)
It specifies the highest level at which the counter is reset. To manually reset the counter you can use the thmresetcounter
function.
By specifying numbering: none
you can create unnumbered theorems.
#example(numbering: none)[
Some example.
]
To make all examples unnumbered you could use the following code:
#let example = example.with(numbering: none)
To create other types (or subgroups) of theorems you can use the newtheorems
function.
#let (note, rules) = newtheorems("thmgroup", ("note": text(red)[Note]))
#show: rules
If you have already defined custom styling you will notice that the newly created theorem does not use it. You can create a dictionary to make applying it again easier.
#let mystyling = (
thmstyling: thmstylingsimple,
thmnumbering: ..,
refstyling: ..
)
#let (note, rules) = newtheorems("thmgroup", ("note": "Note), ..mystyling)
By varying the group
parameter you can create independently numbered theorems:
#let (
theorem, proof,
rules: thmrulesa
) = defaulttheorems("thmgroupa")
#let (
definition,
rules: thmrulesb
) = defaulttheorems("thmgroupb")
#show: thmrulesa
#show: thmrulesb
To specify parameters of the styling functions the .with
function is used.
#let (
theorem,
rules: thmrules
) = defaulttheorems(
"thmgroup",
thmnumbering: thmnumberingheading.with(maxheadinglevel: 2)
)
Example
#import "@preview/lemmify:0.1.6": *
#let mythmstyle(
thmtype, name, number, body
) = grid(
columns: (1fr, 3fr),
columngutter: 1em,
stack(spacing: .5em, strong(thmtype), number, emph(name)),
body
)
#let mystyling = (
thmstyling: mythmstyle
)
#let (
theorem, rules
) = defaulttheorems("thmgroup", lang: "en", ..mystyling)
#show: rules
#show thmselector("thmgroup"): box.with(inset: 1em)
#lorem(20)
#theorem[
#lorem(40)
]
#lorem(20)
#theorem(name: "Some theorem")[
#lorem(30)
]
Documentation
The two most important functions are:
defaulttheorems
: Create a default set of theorems based on the given language and styling.
group
: The group id.lang
: The language to which the theorems are adapted.thmstyling
,thmnumbering
,refstyling
: Styling parameters are explained in further detail in the Styling section.proofstyling
: Styling which is only applied to proofs.maxresetlevel
: The highest heading level on which theorems are still reset.
newtheorems
: Create custom sets of theorems with the given styling.
group
: The group id.subgroupmap
: Mapping from group id to some argument. The simple styles usethmtype
as the argument (ie “Beispiel” or “Example” for group id “example”)thmstyling
,thmnumbering
,refstyling
,refnumbering
: Styling which to apply to all subgroups.
useproofnumbering
: Decreases the numbering of a theorem function by one. See Styling for more information.
thmselector
: Returns a selector for all theorems of the specified group. If subgroup is specified, only the theorems belonging to it will be selected.
There are also a few functions to help with resetting counters.
thmresetcounter
: Reset theorem group counter manually. Returned content needs to added to the document.
thmresetcounterheadingat
: Reset theorem group counter at headings of the specified level. Returns a rule that needs to be shown.
thmresetcounterheading
: Reset theorem group counter at headings of at most the specified level. Returns a rule that needs to be shown.
Styling parameters
If possible the best way to adapt the look of theorems is to use show rules as shown above, but this is not always possible. For example if we wanted theorems to start with 1.1 Theorem
instead of Theorem 1.1
. You can provide the following functions to adapt the look of the theorems.
thmstyling
: A function: (arg, name, number, body) > content
, that allows you to define the styling for different types of theorems. Below only the arg
will be specified.
Predefined functions
thmstylesimple(thmtype)
: thmtype num (name) bodythmstyleproof(thmtype)
: thmtype num (name) body □thmstylereversed(thmtype)
: num thmtype (name) body
thmnumbering
: A function: figure > content
, that determines how theorems are numbered.
Predefined functions: (Assume heading is 1.1 and theorem count is 2)
thmnumberingheading
: 1.1.2maxheadinglevel
: only use the a limited number of subheadings. In this case if it is set to1
the result would be1.2
instead.
thmnumberinglinear
: 2thmnumberingproof
: No visible content is returned, but the counter is reduced by 1 (so that the proof keeps the same count as the theorem). Useful in combination withuseproofnumbering
to create theorems that reference the previous theorem (like proofs).
refstyling
: A function: (arg, thmnumbering, ref) > content
, to style theorem references.
Predefined functions:
thmrefstylesimple(thmtype)
@thm > thmtype 1.1
@thm[custom] > custom 1.1
refnumbering
: Same as thmnumbering
but only applies to the references.
Roadmap
 More predefined styles.
 Referencing theorems by name.
 Support more languages.
 Better documentation.
 Outlining theorems.
If you are encountering any bugs, have questions or are missing features, feel free to open an issue on Github.
Changelog

Version 0.1.6
 Add Portuguese translation (@PgBiel)
 Add Catalan translation (@Eloitor)
 Add Spanish translation (@mismorgano)
 Remove extra space before empty supplements (@PgBiel)
 Use refstyling parameter of defaulttheorems

Version 0.1.5
 Add Russian translation (@WeetHet)

Version 0.1.4
 Fix error on unnamed theorems

Version 0.1.3
 Allow “1.1.” numbering style by default
 Ignore unnumbered subheadings
 Add maxheadinglevel parameter to thmnumberingheading
 Adapt lemmify to typst version 0.8.0

Version 0.1.2
 Better error message on unnumbered headings
 Add Italian translations (@porcaror)

Version 0.1.1
 Add Dutch translations (@BroodjeKroepoek)
 Add French translations (@MDLC01)
 Fix size of default styles and make them breakable