SOPHIA XT
texwright · MIT · version 0.3.4

Documents an agent can write, check and typeset.

texwright turns Markdown, LaTeX or a JSON document tree into PDF or HTML with its own TeX-style engine. Equations, cross-references, citations and footnotes come out the way LaTeX sets them. Mermaid diagrams and TikZ pictures are drawn in place. There is no TeX install and no browser, only one Node.js package with no dependencies.

zip 3.1 MB · Node.js 20+ · Windows and Linux

A model that writes a report should be able to read its own
proof sheet. texwright sets the page the way TeX does, by
choosing every line break in a paragraph together instead
of one at a time, so a single loose line near the top can
be paid for by two tight ones below it. The check runs
in milliseconds, tells the agent which line is at fault, and
hands back the edit that fixes it.
lines
7
loose lines
2
worst badness
281
total demerits
93,790

Real line breaking on a sample paragraph, without hyphenation

For agents

Give it to your agent in one line.

Paste this into any coding agent. The guide it points to is written for models: the syntax, the check, fix and render loop, and what each diagnostic means.

Read https://sophiaxt.com/texwright/AGENTS.md and use texwright to make PDFs from Markdown or LaTeX.

Install from this page

npm installs straight from the tarball here. Nothing to register.

npm install -g https://sophiaxt.com/texwright/texwright-latest.tgz
texwright doc.md -o doc.pdf

Or unzip and run

The zip is the same package. Unzip it anywhere with Node.js 20 or later.

node texwright/dist/cli.mjs doc.md -o doc.pdf

As an MCP server

Nine tools: render, check, fix, repair in one call, outline, preview a page as PNG, the schema, the guide, and new documents from templates.

{
  "mcpServers": {
    "texwright": { "command": "texwright", "args": ["mcp"] }
  }
}
The loop

Problems come back as data,
with the fix attached.

doc.md:3:5 E REF001 Reference to undefined label "sec:intr" | Did you mean "sec:intro"? | fix "sec:intr" -> "sec:intro" safe
01 · Check

Every stage but page layout, in milliseconds. One line per problem, with a code, a position and a hint.

texwright check doc.md --diagnostics compact
02 · Fix

Most diagnostics carry their fix as an edit. The unambiguous ones apply in one go.

texwright check doc.md --fix
03 · Render

The result says which page each heading, figure and table landed on.

texwright doc.md -o doc.pdf
04 · Look

The page as a PNG from texwright's own rasterizer, so the agent can see what it made.

texwright preview doc.md --page 2
What it sets

A paper, a homework set
or a report, from plain text.

  • Mathematics by TeX's rules. amsmath and amssymb, numbered rows in align and gather, siunitx, mhchem and physics commands without loading anything.
  • References that resolve. Sections, figures, tables, equations, theorems and listings numbered, with @fig:x, \ref, \eqref, \cref and exact page references.
  • Citations. BibTeX or CSL-JSON, numeric or author-year.
  • Pages like LaTeX's. Knuth-Plass line breaking, TeX hyphenation, footnotes at the foot of the page, floating figures, Latin Modern type.
  • Three inputs, mixed freely. Markdown with pandoc's extensions, LaTeX as models write it (article, report, book, IEEEtran, revtex, llncs, moderncv, exam, beamer and more), or a JSON document tree.
  • Layout and brand from the document. Paper, margins, size, theme, running heads, authors and brand fonts (mainfont, sansfont, monofont; TTF, OTF, WOFF or WOFF2) as pandoc's front-matter keys. No template to edit.
Page 1 of a texwright showcase: title, authors, abstract, a table of contents with page numbers, and numbered equations.
A page set by texwright: a theorem and proof, a numbered display equation, a plotted SVG figure with its caption, a tip callout and the start of a code listing.
Drawings, new in 0.3

3D plots, circuits, trees
and PSTricks, with no TeX.

These are the drawing packages models reach for when a document needs a figure, and the ones a converter without TeX drops. We wrote 56 documents the way models write them (13 pgfplots 3D, 14 trees and graphs, 14 circuits, 15 PSTricks). texwright draws the figure in all 56. Pandoc's HTML output, without a TeX install, keeps it in none. What is approximated comes back as a warning, and the rest of the picture is still drawn.

A Gaussian surface drawn by texwright from pgfplots source, in the viridis colour map.
pgfplots 3D. \addplot3 surfaces and meshes, colour maps, the default 25/30 view and pgfplots' box.
A common-emitter BJT amplifier drawn by texwright from circuitikz source.
circuitikz. Resistors to transistors, op amps and logic gates, with circuitikz's sizes and labels.
A constituency parse tree drawn by texwright from forest source.
forest and TikZ trees. forest's packed layout, TikZ child trees, \graph layouts and mind maps.
An inclined plane with force vectors drawn by texwright from PSTricks source.
PSTricks. pspicture with pst-plot, pst-node and pst-tree, including PostScript-code functions.
A paraboloid with a jet colour map and a colour bar, drawn by texwright.
Colour bars. jet, viridis, hot and more, with interp shading and a colour bar.
A machine-learning mind map drawn by texwright from TikZ mindmap source.
Mind maps. concept colours carried down each branch, with shaded connections.
Diagrams

Mermaid and TikZ,
drawn by texwright.

A fenced mermaid block becomes a numbered figure. texwright reads Mermaid's syntax with its own parsers and lays the diagram out itself: no browser, a few milliseconds per diagram, labels set in the sans companion of Computer Modern so they match the page. A mistake comes back as DIAG001 at its line, with a hint and usually the fix.

  • Flowcharts
  • Sequence
  • Class
  • State
  • ER
  • Gantt
  • Pie
  • XY charts
  • Quadrant
  • Timeline
  • Mindmap
  • Journey
```{.mermaid #fig:flow caption="Request handling"}
flowchart LR
  client([Client]) --> api[API] -->|query| db[(Database)]
```

TikZ and pgfplots go through texwright's own interpreter: paths, nodes and shapes, styles, \foreach, positioning and calc, automata, and axes with plots, bars, legends and log scales. Labels use the document's math, so they match the equations around them.

A page set by texwright with a Mermaid flowchart (a build pipeline with an Engine subgraph) and a gantt chart.
A Mermaid sequence diagram with an alt block, set by texwright.
A Mermaid xy chart with bars and a line, and a pgfplots least-squares fit, set by texwright.
TikZ pictures drawn by texwright: a triangle with marked angles and a coordinate plane with two functions.
SVG figures

SVG, drawn the way
a browser draws it.

Agents make their figures as SVG: charts, diagrams, Mermaid and draw.io exports. texwright draws gradients, transparency, masks, blend modes, filters, text on paths, HTML labels and full CSS selectors. Each pair is Chrome on the left and texwright's PDF on the right, the PDF drawn by poppler.

0.7average difference from Chrome, levels of 255 per pixel, page previews
0.9the PDF itself, drawn by poppler, same 30 figures
30test figures: gradients, masks, filters, text, diagram tools
Radial gradients, as Chrome draws it

Chrome

Radial gradients, as texwright's PDF shows it

texwright PDF

Radial gradients. Focal points and every spread method, as PDF shadings.
Fading stops, as Chrome draws it

Chrome

Fading stops, as texwright's PDF shows it

texwright PDF

Fading stops. Stops that differ in opacity, drawn through a soft mask.
Masks, as Chrome draws it

Chrome

Masks, as texwright's PDF shows it

texwright PDF

Masks. Luminance and alpha masks, in object or user units.
Drop shadows, as Chrome draws it

Chrome

Drop shadows, as texwright's PDF shows it

texwright PDF

Drop shadows. The shadow becomes an image; the shape stays vector.
Text on a path, as Chrome draws it

Chrome

Text on a path, as texwright's PDF shows it

texwright PDF

Text on a path. Each glyph placed and turned along the curve.
HTML labels, as Chrome draws it

Chrome

HTML labels, as texwright's PDF shows it

texwright PDF

HTML labels. Mermaid's foreignObject labels, wrapped and centred.
Blend modes, as Chrome draws it

Chrome

Blend modes, as texwright's PDF shows it

texwright PDF

Blend modes. mix-blend-mode as the PDF's own blend modes.
draw.io diagrams, as Chrome draws it

Chrome

draw.io diagrams, as texwright's PDF shows it

texwright PDF

draw.io diagrams. Shapes, arrows, labels and the shadow filter.
Measured

Tested on what models actually write.

80/80documents that render clean, written by models for a PDF, unchanged
1,903tests, passing on Windows and Linux
0runtime dependencies, Node.js built-ins only

We asked models for 80 documents (papers, homework, lecture notes, lab reports, CVs, letters, exams) written for pandoc or an ordinary LaTeX installation, then rendered them as they came. All 80 now render with no errors and no warnings; the last one to pass drew its figure in TikZ. A further 30 LaTeX documents in the classes and packages models reach for also check clean. A command starts in about 0.2 seconds, and through the MCP server repeat calls take 15 to 20 ms. The method and the held-out results are in the paper.

What it does not do yet. PSTricks' psmatrix and packages built far beyond TikZ are reported rather than drawn: export those figures as SVG. Beamer comes out as a document, not slides. Hyphenation is English only. Arabic, the Indic scripts and right-to-left text are not supported, the PDF is not tagged for screen readers, and PDF files cannot be used as figures.

Downloads

Everything, with one address that always works.

texwright-latest.zip and texwright-latest.tgz always hold the newest version, so an agent can keep one address. Only the current version is kept under its own name as well.

FileWhat it isSizeSHA-256
texwright-0.3.4.zipThe package as a zip. Unzip and run with Node.js.3.1 MBeeea43605e9111f7…
texwright-0.3.4.tgzThe same package for npm install.2.8 MBa91a9c923adc5ac5…
AGENTS.mdThe guide for agents: syntax, the loop, diagnostics.
CHEATSHEET.mdOne page of syntax.
texwright-paper.pdfThe paper: design, engine, benchmark, security.336 KB
release.jsonVersion, install line, sizes and full SHA-256 hashes.
llms.txtThis page for language models.

MIT texwright is written by Thomas Garren at SOPHIA XT. Its text is set in Latin Modern (GUST Font License) and its mathematics in the KaTeX fonts (SIL Open Font License); both ship inside the package.