Reflow TeX
ReflowTEX
TEX typesetting on the web
Write LA TEX as usual and let LuaTEX typeset it. The page keeps TEX’s fonts, spacing and formulas; only the line breaks are left to the browser, so the text fits any screen.
ReflowTEX shows LA TEX documents in the browser. TEX typesets the text and formulas such as; the browser breaks each paragraph into lines with the Knuth–Plass algorithm, again whenever the width changes.
This column changes its width by itself. On every frame, your browser breaks the paragraph into lines again.
Examples
Each card below is a block of LA TEX in an ordinary web page.
Drag the edge
Drag the right edge of this box. The paragraph is broken into lines again for the new width, with TEX’s hyphenation and justification, and formulas such askeep their spacing. On a phone the same text fits the screen, with no zooming or scrolling sideways.
Displays
Displayed equations look as they do in the PDF.
TikZ pictures
Accessibility settings
Text size and colour scheme.
Collapsible proofs
Theorem 1. There are infinitely many primes.
Idea: were there finitely many, their product plus one would have a prime factor that is none of them. Proof
Proof (hide). Ifwere all of them,would have a prime factor that is none of them.
Exercise. Isprime?
Hint
No:.
Figures scaled to width
Tables scaled to width
Planet Mass Day Mercury 0.330 4222.6 Venus 4.87 2802.0 Earth 5.97 24.0 Mars 0.642 24.7
Footnotes and links
References such as (1) are links. Footnotes open where you are reading, when you point at the marker.1
1 Like this one.
Live text
The basket holds no apples at all. The page’s script sets these words, and the lines are broken again around them.
HTML widgets
The Moon is on average 384400 from the Earth. Pick another unit: the paragraph is broken again around it.
Boxed theorems
Theorem 1.is irrational.
Proof. Ifin lowest terms, then, sois even; thenis even too.
Lean beside a proof
Open the proof, the Lean code that checks it, or both.
Theorem 1. The sum of the firstodd numbers is.
Proof. By induction on. Forboth sides are. If the sum of the firstodd numbers is, adding the next one gives
theorem sum_odd (n : ℕ) :
∑ i ∈ Finset.range n, (2 * i + 1) = n ^ 2 := by
induction n with
| zero => simp
| succ k ih =>
rw [Finset.sum_range_succ, ih]
ringHow it works
TEX typesets
LuaTEX compiles your source. A Lua hook saves each paragraph’s node list before TEX breaks it into lines.
Stored in the page
The glyphs, kerns, glue and boxes, with their positions, are stored in the page as Protocol Buffers.
The browser breaks lines
A small script runs Knuth–Plass for the current width and draws the lines as SVG. When the width changes, it runs again.
At the width of its PDF, the browser puts every glyph of the AMS sample paper within a tenth of a point of where LuaTeX put it: Accuracy
Where to next
Getting started
Install the tools, then publish a static page, a Hugo site or a book.
Typesetting
What a block can contain, each example next to its source.
Companion package
Accordions, notes, hints, boxed theorems and environments of your own.
Showcase
Whole papers and books, including the AMS sample paper testmath.tex.