Clew Manual

Reading mode

Math and theorems

Clew's mathematics is LaTeX mathematics. Inline and display math are written with the delimiters every mathematical writer already knows, rendered by a locally bundled MathJax that works entirely offline; on top of that, the jmarkdown engine adds what a note-taking app almost never has — numbered equations you can cross-reference from prose, and a full family of theorem environments with shared, stable numbering. The same source exports to LaTeX and PDF, where the engine's amsmath and amsthm machinery takes over natively.

Inline and display math

Inline math goes between single dollar signs (or, equivalently, \(…\)):

You write

Euler's identity, $e^{i\pi} + 1 = 0$, connects five constants.

Display math stands on its own line, between double dollars or \[…\]:

You write

$$
\int_0^\infty e^{-x^2}\,dx = \frac{\sqrt{\pi}}{2}
$$

Everything between math delimiters is handed to MathJax verbatim — subscripts, commands, matrices, the lot — so anything you would write in a LaTeX document works here. Display blocks written with $$…$$ and \[…\] are unnumbered; numbered equations are the engine's own construct, described next.

A bare AMS environment also works as a display block, without any dollar-sign wrapper at all:

You write

\begin{align}
f(x) &= x^2 - 1 \\
     &= (x-1)(x+1)
\end{align}

The engine recognizes a \begin{…}…\end{…} block at the start of a line, protects its contents from all Markdown processing, and passes it through for MathJax to typeset — nested environments such as a pmatrix inside an align are handled correctly. MathJax is configured with AMS numbering (tags: 'ams'), so environments that number their lines do, and MathJax-level \label/\eqref resolve between math blocks on the same page. For references you make from prose, though, use the engine's own equation environment below — those resolve at build time and survive LaTeX export.

The Math and Theorems demo note in reading mode: a numbered display equation, theorem and lemma environments with a proof, and a rendered alert box
The demo vault's Math and Theorems note: a numbered equation, a theorem, a lemma citing the equation by number, a proof, and an alert box — all from plain-text source.

Numbered equations

To number an equation and refer to it later, use the @begin(equation) environment:

You write

@begin(equation){#eq-euler}
e^{i\pi} + 1 = 0
@end(equation)

As @ref[eq-euler] shows, the five constants are not strangers.

The body is raw mathematics — no $$ delimiters; the environment supplies them — and the engine itself assigns the number, counting @begin(equation) blocks in document order and placing (1), (2), … beside each. Because the numbering is done by the engine at build time rather than by MathJax in the browser, a reference like @ref[eq-euler] resolves to a hyperlinked number exactly the way figure and section references do, and the HTML and LaTeX outputs agree on every number.

The {#eq-euler} attaches the label. Two spellings are accepted: the shorthand {#name}, and the explicit {id=name} — use the explicit form when your label contains a colon ({id=eq:euler}), which the shorthand cannot carry.

Cross-references

Three reference forms work anywhere in prose, for equations and theorems alike (and for figures, tables, and sections, which have labels of their own):

@ref[key]
The bare number, as a hyperlink to the target — LaTeX's \ref. An equation's is bare too ("2"); write the parentheses yourself, or use @cref.
@cref[key]
A typed reference: the kind word plus the number — "equation (1)", "theorem 2", "lemma 3" — LaTeX's cleveref \cref. The engine knows what kind of thing each label marks, so you never write the word yourself and it can never disagree with the target.
@Cref[key]
The same, capitalized for the start of a sentence: "Equation (1)", "Theorem 2".

A reference to a label that does not exist renders as ?? — the same mark LaTeX uses — so a broken reference is visible in the output rather than silently wrong. In LaTeX export these forms become native \ref and \cref, so the print document resolves them with the real machinery.

Note @ref[…] and :ref[…] are the same directive in two spellings — jmarkdown accepts both, and the same goes for cref, Cref, and label. This manual writes the @ forms throughout, matching the demo vault.

What gets a number

While you write

Live edit showing a numbered heading, 1.1 Cross-references, with its label shown as an anchor chip; below it prose whose references read 1, theorem 1, Lemma 2 and subsection 1.1 as links; the pointer rests on theorem 1 and a popover headed Theorem 1 — Fundamental Triviality shows the theorem's text
In live edit each reference shows the number reading mode will print; hovering one previews what it names.

In live edit, every @ref, @cref and @Cref shows the number the rendered note will print, a numbered environment's heading says "Theorem 2" or "Figure 1", an @begin(equation) carries its "(n)", and numbered headings their "1.2.". Click a reference to jump to what it names (⌘[ comes back); ⌥-click edits it; hover it to preview the target. A reference to a key this note does not define shows ?? in red, as the engine prints it. Typing @ref[ (or @cref[, @Cref[) lists the note's labels with their numbers, and the palette's Jump to label… lists them to go to.

Numbered within the note Clew numbers each note on its own. A project that includes chapters from other notes (the vault's jmarkdownProject option) is numbered as a whole by its export, and a reference to a label in another note shows ?? while you write.

An environment a plugin defines as numbered is counted only when the plugin's manifest declares it; any other environment with a label shows ? — Clew will not guess what the export will print.

Theorem environments

The engine provides seven theorem-like environments plus proof. Each is written as a block environment:

You write

@begin(theorem)[Pythagoras]{id=thm:pyth}
For a right triangle, $a^2 + b^2 = c^2$.
@end(theorem)

@begin(lemma)
If $x > 0$ then $\log x$ is defined.
@end(lemma)

@begin(proof)
By rearrangement. $\blacksquare$
@end(proof)

The optional bracket after the opener — [Pythagoras] — is the environment's name, rendered in parentheses after the number exactly as amsthm does: "Theorem 1 (Pythagoras)." The optional {id=…} attaches a cross-reference label, so @cref[thm:pyth] elsewhere produces "theorem 1".

The full set of kinds, and how each presents its body:

How numbering works

All seven numbered kinds share one sequential counter: if a theorem is followed by a lemma and then a definition, they are Theorem 1, Lemma 2, Definition 3. This is a deliberate choice, and the classical one for mathematical writing — with per-kind counters, "does Lemma 1 come before or after Theorem 2?" is a puzzle a reader has to solve on every reference; with a shared counter, the numbers alone give the document order. A typed reference still names each kind correctly: @cref to a lemma says "lemma 2", never "theorem 2".

The body of a theorem is ordinary jmarkdown, so wikilinks, citations, math, and even footnotes work inside it — the demo vault's Dialect Demo note puts an inline footnote inside a theorem to make the point.

MathJax under the hood

Clew ships MathJax with the app and loads it from local files — there is no CDN request, and mathematics renders identically with no network connection at all. The configuration accepts the four delimiter pairs described above ($…$, \(…\), $$…$$, \[…\]) with the AMS extension enabled, and output is SVG, so rendered math is crisp at any zoom. When you edit a note, the re-rendered preview patches in place and math is re-typeset without the page flashing back to raw TeX (see How rendering works).

Math in export

Because the source is already LaTeX mathematics, export is not a translation. In HTML export the same MathJax pipeline runs; in LaTeX and PDF export the delimiters pass straight through to the real engine, @begin(equation) becomes an amsmath equation environment, and each theorem kind is declared with amsthm/thmtools sharing the theorem counter, with cleveref resolving the typed references. The numbers in your PDF match the numbers in your preview because both sides count the same blocks in the same order. See Exporting notes.

Practical advice

The jmarkdown dialect and TeX use some of the same characters, and it pays to keep the boundary straight:

Caution Because _ and ^ are live in prose, an unintended subscript is the most common dialect surprise: a variable name like my_var in running text will render "var" as a subscript. Put identifiers in code spans (`my_var`) — which is better typography anyway — or switch the vault to standard Markdown syntax if your notes are code-heavy (see the dialect chapter). The same goes for money: two amounts in one paragraph — $5 and $10 — are a pair of delimiters, and everything between them becomes a formula. Escape them, \$5, or put them in code spans.
Obsidian compatibility Obsidian renders $…$ and $$…$$ with its own MathJax, so plain inline and display math round-trips between the two apps. The engine-level constructs — @begin(equation), the theorem environments, @ref/@cref — are jmarkdown features: in Obsidian those lines appear as the literal text you typed. Nothing breaks; the notes remain plain Markdown files.

Reference

ConstructSyntaxNotes
Inline math$…$ or \(…\)TeX inside; unnumbered
Display math$$…$$ or \[…\]Unnumbered display block
Bare AMS environment\begin{align} … \end{align}No wrapper needed; contents protected verbatim
Numbered equation@begin(equation){#key} … @end(equation)Engine-numbered; body is raw math
Theorem-like environment@begin(theorem)[Name]{id=key} … @end(theorem)Kinds: theorem, lemma, corollary, proposition, definition, example, remark
Proof@begin(proof) … @end(proof)Unnumbered; QED mark
Label{#key} or {id=key}Use id= when the key contains a colon
Reference (number)@ref[key]Hyperlinked number; ?? if unresolved
Typed reference@cref[key] / @Cref[key]"theorem 2" / "Theorem 2"; cleveref in LaTeX

See also