Marmare314 / lemmify

A library for typesetting mathematical theorems in typst.
GNU General Public License v3.0
11 stars 7 forks source link
typst

Lemmify

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 user-defined element functions are introduced). But no functionality should be lost.

Basic Usage

To get started with Lemmify, follow these steps:

  1. Import the Lemmify library:

    #import "@preview/lemmify:0.1.5": *
  2. Define the default styling for a few default theorem types:

    #let (
    theorem, lemma, corollary,
    remark, proposition, example,
    proof, rules: thm-rules
    ) = default-theorems("thm-group", lang: "en")
  3. Apply the generated styling:

    #show: thm-rules
  4. Create theorems, lemmas, and proofs using the defined styling:

    
    #theorem(name: "Some theorem")[
    Theorem content goes here.
    ]<thm>

proof[

Complicated proof. ]

@proof and @thm[theorem]


5. Customize the styling further using show rules. For example, to add a red box around proofs:
```typst
#show thm-selector("thm-group", subgroup: "proof"): it => box(
  it,
  stroke: red + 1pt,
  inset: 1em
)

The result should now look something like this:

image

Useful examples

If you do not want to reset the theorem counter on headings you can use the max-reset-level parameter:

default-theorems("thm-group", max-reset-level: 0)

It specifies the highest level at which the counter is reset. To manually reset the counter you can use the thm-reset-counter 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 new-theorems function.

#let (note, rules) = new-theorems("thm-group", ("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 my-styling = (
  thm-styling: thm-styling-simple,
  thm-numbering: ..,
  ref-styling: ..
)

#let (note, rules) = new-theorems("thm-group", ("note": "Note), ..my-styling)

By varying the group parameter you can create independently numbered theorems:

#let (
  theorem, proof,
  rules: thm-rules-a
) = default-theorems("thm-group-a")
#let (
  definition,
  rules: thm-rules-b
) = default-theorems("thm-group-b")

#show: thm-rules-a
#show: thm-rules-b

To specify parameters of the styling functions the .with function is used.

#let (
  theorem,
  rules: thm-rules
) = default-theorems(
  "thm-group",
  thm-numbering: thm-numbering-heading.with(max-heading-level: 2)
)

Example

#import "@preview/lemmify:0.1.5": *

#let my-thm-style(
  thm-type, name, number, body
) = grid(
  columns: (1fr, 3fr),
  column-gutter: 1em,
  stack(spacing: .5em, strong(thm-type), number, emph(name)),
  body
)

#let my-styling = (
  thm-styling: my-thm-style
)

#let (
  theorem, rules
) = default-theorems("thm-group", lang: "en", ..my-styling)
#show: rules
#show thm-selector("thm-group"): box.with(inset: 1em)

#lorem(20)
#theorem[
  #lorem(40)
]
#lorem(20)
#theorem(name: "Some theorem")[
  #lorem(30)
]

image

Documentation

The two most important functions are:

default-theorems: Create a default set of theorems based on the given language and styling.

new-theorems: Create custom sets of theorems with the given styling.


use-proof-numbering: Decreases the numbering of a theorem function by one. See Styling for more information.


thm-selector: 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.

thm-reset-counter: Reset theorem group counter manually. Returned content needs to added to the document.

thm-reset-counter-heading-at: Reset theorem group counter at headings of the specified level. Returns a rule that needs to be shown.

thm-reset-counter-heading: 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.


thm-styling: 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.

Pre-defined functions


thm-numbering: A function: figure -> content, that determines how theorems are numbered.

Pre-defined functions: (Assume heading is 1.1 and theorem count is 2)


ref-styling: A function: (arg, thm-numbering, ref) -> content, to style theorem references.

Pre-defined functions:


ref-numbering: Same as thm-numbering but only applies to the references.

Roadmap

If you are encountering any bugs, have questions or are missing features, feel free to open an issue on Github.

Changelog