Repository navigation
feat/LaTeX rendering - #17
Merged
Merged
Conversation
The reading view renders display math only through typst, and passes the
block to typst verbatim, so real LaTeX such as \frac{a}{b} falls back to
source. This adds the settings the LaTeX engine builds on: math picks
typst (the default) or latex, render_timeout bounds one external render
in seconds (default 10), and render_concurrency caps how many run at
once (default 2).
A bad value never stops zn from starting: an unknown engine reads as
typst and a non-positive number as the default. zn doctor reports it,
and under math = "latex" it also names a missing pdftex or pdftocairo.
Saving a setting stays strict, the way images already is. The starter
config.toml carries the keys with a comment naming the tools, and the
settings screen offers typst or latex.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
spirit-of-light
force-pushed
the
feat/latex
branch
from
October 27, 2026 04:12
f06d63b to
ce4b79a
Compare
With [terminal] math = "latex", display math renders through the user's own pdftex instead of typst, so full LaTeX works: amsmath environments, mhchem and TikZ. $$ blocks, \[ \] (one or many lines) and top-level equation, align, gather, multline, alignat, flalign, eqnarray (starred too) and tikzpicture blocks are detected; inside code fences, $$, lists, quotes and callouts they stay text, and under typst nothing changes. Each block is a standalone document over preamble.tex in the config dir. zn writes the default (amsmath, amssymb, mhchem, tikz with arrows.meta and calc) on the first render and never rewrites it. The preamble is dumped once into a pdftex format named by its hash, so a block only pays for itself; a changed preamble builds a new format. pdftex runs with -no-shell-escape and openin_any=p/openout_any=p, so a note cannot run commands or write outside the work dir. pdftocairo turns the PDF into a transparent PNG, cropped to the formula so its size does not shrink with the pane, coloured with the theme's text colour, and cached on disk under zn/tex. Every external render (mmdc, typst, pdftex, pdftocairo) now runs through one runner that kills it after render_timeout, and through one pool of render_concurrency slots. A TeX error shows its first line above the source and is remembered; a timeout is not, so the block renders again when its note is opened, without looping on every redraw. The editor highlights math bodies with chroma's tex or typst lexer to match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The editor already closes $$ and code fences on Enter. Under latex,
\[ now gets \] and \begin{name} gets \end{name} for any environment
name, with the cursor on the empty line between, and no closer is added
when one already follows. Under typst these lines get a plain Enter.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The note-writing instructions tell an AI to emit ```tikz fences, which
the latex engine does not render; it renders a top-level tikzpicture
and loads libraries from preamble.tex. Under math = "latex" the server
now serves a copy of the instructions with the TikZ guidance rewritten
for that: a bare \begin{tikzpicture} block, no \usetikzlibrary line.
The copy comes from six exact replacements, and a test fails if any of
them stops matching, so the typst text stays the single source. The
typst text and a user's override file are unchanged, and the setting is
read once when the server starts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The README's reading-view section and the in-app help describe the math engine choice, render_timeout and render_concurrency, where preamble.tex lives and what it loads. They also say what latex needs: pdftex from a basic TeX Live plus the packages zn uses, and pdftocairo from poppler. They warn that TeX can read any file by absolute path, so a note can show a readable file in the preview, and advise leaving latex off for untrusted vaults. The Homebrew formula gains caveats with the same install steps and no new dependency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
spirit-of-light
force-pushed
the
feat/latex
branch
from
October 27, 2026 04:32
ce4b79a to
40fea41
Compare
Contributor
|
Thank you for this, @spirit-of-light. It's a big, careful piece of work, and the real-TeX tests made reviewing it much easier. It landed unchanged in 844c19f (via #18) and shipped in zn v0.12.0. The review turned up a few things. They're fixed in separate follow-up commits so your commits stay as you wrote them:
Everything else is as you built it: the shared runner and pool, the format single-flight, the crop, timeout retry on open, the Enter closers, the doctor check and the docs. |
MichaelC001
pushed a commit
to MichaelC001/zennotes
that referenced
this pull request
Oct 28, 2026
The bundled CLI is the floor a desktop build guarantees, and 0.12.2 is the newest release (ZenNotes/tui#20). It brings LaTeX to the terminal preview: with [terminal] math = "latex", zn draws display math and TikZ through the TeX installed on the user's computer (ZenNotes/tui#17), says plainly that zn does not include TeX and prints the install commands in zn doctor, and fits preview pictures to the pane as it grows or shrinks. The pin is the release's terminal-release.json copied byte for byte after it verified against packaging/release-signing/zn-release-1.pub in ZenNotes/tui (source commit 3f1f638a, integration protocol 1, all four archives it names matching checksums.txt). Staged through `npm run terminal:stage`; the native darwin-arm64 binary reports zn v0.12.2. The in-app manual's CLI card says 0.12.2 and what 0.12.0 to 0.12.2 change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Functionality
This feature adds the (optional) functionality of rendering LaTeX.


Only content in display math environments (
$$and\[ \]), as well as package-defined environments, such asequation, align, gather, multline, tikzpicture, etc.is rendered. Content inside list items, code fences, quotes, or callouts is not rendered.To accelerate compilation speed, a precompiled preamble is stored in the same directory as config.toml. If a user wishes to use a package which is not included by default they may add it to the preamble, along with any other settings.
Inline rendering is not implemented, as it affects individual line height and requires more complex implementation.
Settings added
[terminal] math = "typst" | "latex"(default = "typst")[terminal] render_timeout = n seconds(default = 10)[terminal] render_concurrency = n(default = 2)Behavior changes
Dependencies
These dependencies are not included in the base zn installation. Users who wish to use LaTeX rendering must install these themselves.
On macOS: