A documentation generator for Typst in Typst.
137
stars
139
commits
Typst
primary language
Jul 9, 2026
updated
Keep it tidy.
tidy is a package that generates documentation directly in Typst for your Typst modules. It parses doc-comments and can be used to easily build a reference section for a module. Doc-comments use Typst syntax − so markup, equations and even figures are no problem!
[!IMPORTANT] In version 0.4.0, the default documentation syntax has changed. You can take a look at the migration guide or revert to the old syntax with
tidy.parse-module(old-syntax: true, ...).You can still find the documentation for the old syntax in the 0.3.0 user guide.
Features:
The guide fully describes the usage of this module and defines documentation syntax.
Using tidy is as simple as writing some doc-comments and calling:
#import "@preview/tidy:0.4.3"
#let docs = tidy.parse-module(read("my-module.typ"))
#tidy.show-module(docs, style: tidy.styles.default)
The available predefined styles are currently tidy.styles.default and tidy.styles.minimal. Custom styles can be added by hand (take a look at the user guide).
A full example on how to use this module for your own package (maybe even consisting of multiple files) can be found at examples.
/// This function computes the cardinal sine, $sinc(x)=sin(x)/x$.
///
/// ```example
/// #sinc(0)
/// ```
///
/// -> float
#let sinc(
/// The argument for the cardinal sine function.
/// -> int | float
x
) = if x == 0 {1} else {calc.sin(x) / x}
tidy turns this into:
The code in the doc-comments is evaluated through the eval function. In order to access user-defined functions and images, you can make use of the scope argument of tidy.parse-module():
#{
import "my-module.typ"
let module = tidy.parse-module(
read("my-module.typ"),
scope: (my-module: my-module, img: an-image)
)
let an-image = image("img.png")
tidy.show-module(
module,
style: tidy.styles.default
)
}
The doc-comments in my-module.typ may now access the image with #img and can call any function or variable from my-module in the style of #my-module.my-function(). This makes rendering examples right in the doc-comments as easy as a breeze!
With tidy, you can add a help command to you package that allows users to obtain the documentation of a specific definition or parameter right in the document. This is similar to CLI-style help commands. If you have already written doc-comments for your package, it is quite low-effort to add this feature. Once set up, the end-user can use it like this:
// happily coding, but how do I use this one complex function again?
#mypackage.help("func")
#mypackage.help("func(param1)") // print only parameter description of param1
This will print the documentation of func directly into the document — no need to look it up in a manual. Read up on setup instructions in the user guide.
It is possible to add simple doc-tests — assertions that will be run when the documentation is generated. This is useful if you want to keep small tests and documentation in one place.
/// #test(
/// `num.my-square(2) == 4`,
/// `num.my-square(4) == 16`,
/// )
#let my-square(n) = n * n
A few test assertion functions are available to improve readability, simplicity, and error messages. Currently, these are eq(a, b) for equality tests, ne(a, b) for inequality tests and approx(a, b, eps: 1e-10) for floating point comparisons. These assertion helper functions are always available within doc-comment tests.
Automatic locale support
show-module.local-names.Variables can now also be customized.Fixes and Improvements
<<<.tiling is now supported and it is shown with the new gradient.Fixes
"//" can now be used in default arguments.@section can now link to labels outside the documentation.Major redesign of the documentation syntax
tidy.parse-module(old-syntax: true). There is a migration guide for adopting the new syntax..with() function.Adds a help feature and more options
preamble option for examples (e.g., to add import statements).show-module: omit-private-definitions, omit-private-parameters, enable-cross-references, local-names (for configuring language-specific strings).show-example() as standalone.scale-preview is not auto.show-outlineraw(lang: none) for types and function names.color and gradient.show-reference().default theme).@@ syntax could omit the function parentheses. Now this is not possible anymore, since such references refer to variables now.show-outline(), show-parameter-list, and show-type() now take style-args arguments as well.Initial Release
Typst
100.0%
A documentation generator for Typst in Typst.
137
stars
139
commits
Typst
primary language
Jul 9, 2026
updated
Keep it tidy.
tidy is a package that generates documentation directly in Typst for your Typst modules. It parses doc-comments and can be used to easily build a reference section for a module. Doc-comments use Typst syntax − so markup, equations and even figures are no problem!
[!IMPORTANT] In version 0.4.0, the default documentation syntax has changed. You can take a look at the migration guide or revert to the old syntax with
tidy.parse-module(old-syntax: true, ...).You can still find the documentation for the old syntax in the 0.3.0 user guide.
Features:
The guide fully describes the usage of this module and defines documentation syntax.
Using tidy is as simple as writing some doc-comments and calling:
#import "@preview/tidy:0.4.3"
#let docs = tidy.parse-module(read("my-module.typ"))
#tidy.show-module(docs, style: tidy.styles.default)
The available predefined styles are currently tidy.styles.default and tidy.styles.minimal. Custom styles can be added by hand (take a look at the user guide).
A full example on how to use this module for your own package (maybe even consisting of multiple files) can be found at examples.
/// This function computes the cardinal sine, $sinc(x)=sin(x)/x$.
///
/// ```example
/// #sinc(0)
/// ```
///
/// -> float
#let sinc(
/// The argument for the cardinal sine function.
/// -> int | float
x
) = if x == 0 {1} else {calc.sin(x) / x}
tidy turns this into:
The code in the doc-comments is evaluated through the eval function. In order to access user-defined functions and images, you can make use of the scope argument of tidy.parse-module():
#{
import "my-module.typ"
let module = tidy.parse-module(
read("my-module.typ"),
scope: (my-module: my-module, img: an-image)
)
let an-image = image("img.png")
tidy.show-module(
module,
style: tidy.styles.default
)
}
The doc-comments in my-module.typ may now access the image with #img and can call any function or variable from my-module in the style of #my-module.my-function(). This makes rendering examples right in the doc-comments as easy as a breeze!
With tidy, you can add a help command to you package that allows users to obtain the documentation of a specific definition or parameter right in the document. This is similar to CLI-style help commands. If you have already written doc-comments for your package, it is quite low-effort to add this feature. Once set up, the end-user can use it like this:
// happily coding, but how do I use this one complex function again?
#mypackage.help("func")
#mypackage.help("func(param1)") // print only parameter description of param1
This will print the documentation of func directly into the document — no need to look it up in a manual. Read up on setup instructions in the user guide.
It is possible to add simple doc-tests — assertions that will be run when the documentation is generated. This is useful if you want to keep small tests and documentation in one place.
/// #test(
/// `num.my-square(2) == 4`,
/// `num.my-square(4) == 16`,
/// )
#let my-square(n) = n * n
A few test assertion functions are available to improve readability, simplicity, and error messages. Currently, these are eq(a, b) for equality tests, ne(a, b) for inequality tests and approx(a, b, eps: 1e-10) for floating point comparisons. These assertion helper functions are always available within doc-comment tests.
Automatic locale support
show-module.local-names.Variables can now also be customized.Fixes and Improvements
<<<.tiling is now supported and it is shown with the new gradient.Fixes
"//" can now be used in default arguments.@section can now link to labels outside the documentation.Major redesign of the documentation syntax
tidy.parse-module(old-syntax: true). There is a migration guide for adopting the new syntax..with() function.Adds a help feature and more options
preamble option for examples (e.g., to add import statements).show-module: omit-private-definitions, omit-private-parameters, enable-cross-references, local-names (for configuring language-specific strings).show-example() as standalone.scale-preview is not auto.show-outlineraw(lang: none) for types and function names.color and gradient.show-reference().default theme).@@ syntax could omit the function parentheses. Now this is not possible anymore, since such references refer to variables now.show-outline(), show-parameter-list, and show-type() now take style-args arguments as well.Initial Release
Typst
100.0%