Universe

A typst package providing modern environments for theorems and proofs; equipped with predefined variants for all common use cases but also the flexibility to create custom ones with ease. Built to easily write lecture notes with minimal setup.

Usage

Before using any of the features this package has to offer, add the following lines to the top of your document:

#import "@preview/typst-thmbox:0.2.0": *

#show: thmbox-init()

Now, the basic building block for thmbox environments is thmbox:

#thmbox[
    This is a basic Thmbox
] <basic-box>

It can be referenced (see @basic-box).

Using the color, variant, and title parameters, we can style this box:

#thmbox(
    variant: "Important Theorem", 
    title: "Fundamental Theorem of Math", 
    color: red
)[
    A statement can only be believed if it is proven. 
]

To prove this statement, we can follow up with a proof:

#proof[
    Proven by obviousness.
]

For your environments, Thmbox actually ships with a variety of predefined ones, for theorems, corollaries, definitions, examples, etc:

Note that you don’t need to specify the title parameter by name:

#definition[Typst][
    Let Typst be the coolest typesetting system.
]

Usage Notes

The recommended way of implementing new types of thmboxes is like this:

// derive from some predefined function
#let important = note.with(
    fill: rgb("#ffdcdc"), 
    variant: "Important", 
    color: red,
)

#important[
    This is in fact very important!
]

Of course, deriving from thmbox is just as good, but the predefined environments have some other parameters already set as well.


By default, the counter for thmboxes has two levels where the first one marks the chapter and the second gets reset at the start of each chapter. To change that, use the counter-level parameter of thmbox-init. The default is 2, but for example, 1 will be one number counting in the entire document, 3 will count per section, and so on.

You can also use custom counters. Those must be registered with sectioned-counter(<counter>, level: <level>) where level works just like counter-level mentioned above.

// Just some arbitrary custom counter
#let exercise-counter = counter("exercise")

// Register the counter for thmbox
#show: sectioned-counter(exercise-counter, level: 1)

// Use the counter
#let my-exercise = exercise.with(counter: exercise-counter)

#my-exercise[The first exercise!]

As set rules don’t work with user-defined functions, a similar effect can be achieved the following way:

// Define your custom thmbox args
#let my-thmbox-rules = (
    fill: rgb("#fffdd3")
)

// redefine predefined environments
#let my-definition = definition.with(..my-thmbox-rules)

// use
#my-definition[
    This definition has a yellow background!
]

The recommended font for documents using this package is New Computer Modern (shipped with Typst).

The recommended sans-serif font (can be changed with the sans-fonts and title-fonts parameter) is New Computer Modern Sans (download at CTAN)

By default, thmboxes don’t break across pages. To enable that, you can use the rule #show figure: set block(breakable: true). Other set and show rules for figures can be used with thmboxes as well, as figures are used under the hood.

Installation

No steps are required when installing from @preview. To install this package locally, do

cd /typst/packages/local/thmbox
git clone https://github.com/s15n/typst-thmbox.git 0.2.0

where <data-dir> is

  • $XDG_DATA_HOME or ~/.local/share on Linux
  • ~/Library/Application Support on macOS
  • %APPDATA% on Windows

You might have to create the folder in the first line first.

Translations

Thmbox automatically translates to the language of your document (if translations are available for it).

Translations are found in src/translations.typ. You are welcome to contribute for languages you speak.