Universe

Create project in app

Explanatory technical documents, written the way a good lecture explains: a picture of a running example first, then the idea in plain words, then the same idea in symbols. One source builds a paged PDF and a web page, where figures can come alive.

See the gallery: binary search, explained with every primitive of the package, as a web page with a live figure and as a PDF.

A document written with epiphany explains every idea three times, in this order:

  1. a picture of one running example, used throughout the document;
  2. words: a plain explanation of what the picture shows;
  3. symbols: the formal definition, lemma or theorem, in a tinted box.

The picture and the symbols say the same thing, so a reader can check either against the other. Each section opens with the question it answers and closes with its idea in one sentence. Algorithms are written once and then shown again beside each picture, with the lines that picture is about highlighted, so the reader never has to turn back to find “line 7”.

Getting started

typst init @preview/epiphany:0.1.0 my-explainer

starts a document from the template, with one section in the recommended order. Or import the package into a document of your own:

#import "@preview/epiphany:0.1.0": *

#show: report.with(
  title: [Binary search, explained],
  subtitle: [How to find a value among a million in twenty questions],
  authors: ((name: [Ada Lovelace], affiliation: [Analytical Engines]),),
  date: [November 2026],
  abstract: [What the method does, who this is for, and what it explains.],
)

Build the PDF with typst compile doc.typ, and the web page with typst compile --features html --format html doc.typ (Typst 0.15 or newer; HTML export is still marked experimental by Typst).

The package uses only Typst’s built-in functions and the fonts embedded in Typst (Libertinus Serif, New Computer Modern Math, DejaVu Sans Mono) unless you choose others.

The document: report

Parameter Meaning
title, subtitle, date, abstract The title block.
authors An array of (name: ..., affiliation: ...); affiliation is optional.
theme Overrides colours of default-theme, e.g. (accent: rgb("#5b3f8c")). On the web each one becomes a CSS custom property (--ep-accent).
fonts The body, math and mono font families, e.g. (body: "Hanken Grotesk"). The PDF is set in them; on the web they lead the font stacks (the reader’s browser needs the fonts, so a hosting page provides them).
lists Lists after the contents, as (kind, title) pairs: ((image, [Figures]), (table, [Tables]), ("algorithm", [Algorithms])). In the PDF they share a page in two columns; on the web they fold away under the contents.
url The web version’s address. Each live figure in the PDF links to its place there.
web Options for HTML: standalone (default true; see On the web), pdf (the PDF’s address, offered as a download under the title), styles and scripts (addresses of more stylesheets and module scripts, such as a document’s live figures).

#show: appendix after the main text makes every later section an appendix: lettered (A, A.1) and referred to as “Appendix A”.

A list shows each figure’s short title when its caption has one: caption: brief([Short title], [The full caption, as long as it needs to be.]). A table’s caption goes above the table.

Primitives

Opening and closing a section

Primitive Use
question[...] The question the section answers, asked before any answer. It stays on the same page as what follows it.
takeaway[...] The section’s idea in one sentence.

Pictures and words

Primitive Use
scene(visual, body, side: right, width: 44%) A picture beside the words that explain it, centred on each other. Alternate side between consecutive scenes. On a phone the picture goes under its words.
filmstrip((visual, label), ..., caption: none, arrows: true) Frames of one process in time order, with arrows between them. With a caption it is a numbered figure. arrows: false makes a side-by-side comparison.
cards((title, body), ..., columns: 3) Short items of equal weight, such as options or variants.
swatch(colour, shape: "dot") An inline colour key ("dot", "cross", "line", "dash"), so the text can name a figure’s marks: the #swatch(orange) probe.
drawing(body) A Typst drawing that also appears on the web, as an inline SVG. scene, step, filmstrip and live do this for their pictures already; use it for a drawing anywhere else, such as in a figure.

Words and symbols

Primitive Use
translate([words], [symbols], ..., caption: none) A two-column table with each idea in plain words beside its notation. Use it for notation, and before a definition. With a caption it is a numbered table.
definition, lemma, theorem, proposition, invariant Numbered formal statements: #theorem(title: [...])[...] <thm:x>, referred to with @thm:x.
proof[...] A proof or proof sketch, closed with a square.
note, pitfall, implementation Asides: context, a trap an implementation can fall into, engineering detail. callout(title, key, body) makes one coloured by any theme entry.

Algorithms

Pseudocode is data, so one algorithm can be drawn in full and again in focus:

#let search = (
  require[a sorted array $a$ and a target $t$],
  ensure[an index of $t$, or *none*],
  ln(0, [$l <- 0$ and $h <- n - 1$]),
  ln(0, [*while* $l <= h$ *do*]),
  ln(1, [$m <- floor((l + h) \/ 2)$], note: [the middle of what is left]),
  ln(1, [*if* $a_m = t$ *then return* $m$]),
)
#algorithm(caption: [Binary search.], pseudocode(search)) <alg:search>
  • pseudocode(lines, focus: none, notes: true, window: none): focus takes line numbers, plus "in" for the Require and Ensure lines. Lines in focus are highlighted; the others are dimmed and lose their notes. window: w shows only the lines within w of the focus and collapses each run of hidden lines into one “⋮”.
  • step(title, code: (label: <alg:search>, lines: search), focus: (...), window: none, width: 48%, visual)[narration]: a storyboard step. The algorithm is on the left with the focus lines highlighted and the narration under it; the picture of what those lines do is on the right. Steps are numbered within a story: story() starts a new one. code: none makes a step no pseudocode line covers.

A section, in order

= Title <sec:x>
#question[What problem does this section solve?]
#scene(picture)[What the picture shows, in words.]
#translate([the idea in words], $the idea in symbols$)
#definition(title: [...])[...]
#story()
#step([First step], code: alg, focus: (1, 2), picture)[What lines 1 and 2 do.]
#theorem(title: [...])[...]
#proof[...]
#takeaway[The idea in one line.]

On the web

In HTML export every primitive writes plain, semantic elements with ep- classes (ep-question, ep-scene, ep-step, ep-env ep-theorem, ep-algorithm, …), and the package styles them with its own stylesheet, web/epiphany.css: light and dark, readable on a phone. Drawings become inline SVGs; give them absolute sizes, since a relative width has nothing to resolve against in HTML.

  • Standalone (the default): the HTML file carries the stylesheet and the live-figure runtime inside it, and works on its own, from a folder or any static host.
  • Hosted: a site that shows documents in its own pages passes web: (standalone: false) and includes web/epiphany.css and web/live.js from the package itself. It restyles documents by overriding the custom properties on .ep-doc: the colours by role (--ep-accent, --ep-result, --ep-focus, …), --ep-ink, --ep-panel, --ep-page, the fonts (--ep-font-body, --ep-font-mono, --ep-font-math) and the widths (--ep-measure, --ep-wide).

Live figures

#live("search", props: (values: values, target: 23),
  caption: [Pick a target and step through the search.],
  still-picture) <fig:live>

On the web, live writes an <ep-live name="search" props="..."> element showing the still picture; in the PDF it is the still picture with a link to the figure on the web (report(url: ...)). Draw the still picture from the same data as props, so it is the live figure’s first frame. A page supplies the figure’s code by registering a widget under its name:

// A module listed in report(web: (scripts: ("search.js",))).
const { register, lightLines } = globalThis.epiphany; // or import them from web/live.js

register('search', {
  mount(stage, props, figure) {
    // Draw into `stage` and keep it interactive; `props` are the document's.
    lightLines('alg:search', [3, 4]); // light up lines 3 and 4 of @alg:search as they run
  },
});

A widget’s code can also be a loader, register('search', () => import('./search.js')), which runs only when the figure nears the screen. Once a widget mounts, its still picture is hidden. The gallery’s live figure (gallery/binary-search.js in the repository) is a complete example.

Theme

default-theme names every colour the primitives use in the PDF: accent, muted, comment, dimmed, focus, focus-rule, danger, definition, result, invariant and implementation. Override any of them with report(theme: (...)). The colours of a document’s own subject, such as which colour marks a probe, belong to the document: define them once and use them in its drawings, its swatches and its live figures, so text and pictures cannot disagree.

Versions

epiphany follows semantic versioning, and a published version never changes; the changelog says what each version adds and how to move to it. It needs Typst 0.15 or newer, and is tested with the latest Typst release as well.

License

MIT No Attribution (LICENSE): use, change and share the package and the template freely, with no notice to keep, so a document started from the template is entirely yours. The package is developed at github.com/Prajwal-Prathiksh/epiphany.