LuaTeX online
Run LuaTeX online in your browser: plain TeX with a Lua interpreter inside the engine, so \directlua computes while the page is set.
Open in LaTeX.to Download the example (zip)
- Recommended Active, 2007
- Magic comment:
% !TeX program = luatexon the first line of main.tex, which is how the example picks it under Auto. - License: Public domain, use freely.
- Files:
main.tex
% !TeX program = luatex % Plain LuaTeX: plain TeX with an embedded Lua interpreter; ends with \bye. \font\titlefont=cmbx12 at 18pt \centerline{\titlefont Plain TeX, powered by Lua} \medskip \centerline{Type, compute, and typeset in one pass} \bigskip \noindent LuaTeX pairs the minimalism of plain TeX with a complete Lua interpreter. Whenever TeX meets \string\directlua, the code inside it runs and its output is typeset right there. Plain TeX lays out the page; Lua does the arithmetic. \medskip \noindent The first eight square numbers, produced by a Lua loop rather than typed by hand, are: \directlua{ local sq = {} for n = 1, 8 do sq[n] = n * n end tex.print(table.concat(sq, ", ")) }. \medskip \noindent The sum of the integers from one to one hundred, computed the same way, comes to \directlua{ local s = 0 for k = 1, 100 do s = s + k end tex.print(s) }. Nothing about those numbers is stored in the source. \medskip \noindent This blend of a tiny, transparent format with a real programming language is what draws people to LuaTeX for generative and data-driven work. \bye
How to compile with LuaTeX on LaTeX.to
Everything runs in your browser: nothing to install, no login, no compile timeout.
- Click Open in LaTeX.to. The example opens as a project with main.tex in the editor and its finished PDF in the preview.
- Edit, then press Ctrl+Enter (Cmd+Enter on a Mac). The first compile downloads what this engine needs; after that a compile takes seconds.
What LuaTeX is
LuaTeX is the engine underneath LuaLaTeX. Loaded with the plain format instead of LaTeX, it is Knuth's plain TeX, \bye and all, with a Lua interpreter compiled into the binary. Wherever TeX meets \directlua, the code inside runs and whatever it prints is typeset in place.
The example on this page computes the first eight square numbers and the sum from one to a hundred that way. None of those numbers is in the source; a loop produces them every time the file compiles.
When to use it
- A plain TeX file that has to compute: a table from data, a list from a loop, a number from a formula.
- Macro work that reaches into the engine. From Lua you can read TeX's registers, walk the node list of a paragraph before it is broken into lines, and hook into the font loader, which is how
luaotfload,luatexjaand the LaTeX team's tagging code do their work. - Package testing for LuaLaTeX with nothing else loaded.
- Not for a file with
\documentclass, which is LuaLaTeX, and not for a plain file that only wants a nice font and no code: XeTeX or pdfTeX start faster.
LuaTeX vs LuaLaTeX vs XeTeX
- LuaLaTeX: the same engine with the LaTeX format. A file that starts with
\documentclasswants LuaLaTeX, a file that ends in\byewants this page. In TeX Live, lualatex runs theluahbtexbinary, which adds HarfBuzz shaping. - XeTeX: also reads Unicode and loads OpenType fonts, with HarfBuzz built in and a quoted font syntax, but no interpreter, XDV instead of direct PDF, and no longer developed.
Auto picks LuaTeX for a \bye file that uses \directlua, and the example pins it with % !TeX program = luatex on the first line.
More engines: pdfTeX, XeTeX and all engines.