Roses are red
Violets are blue
I create my PDF
With boxes and glue
boxes and glue
boxes and glue is a family of tools and libraries for creating PDF documents. Everything is written in Go, built on the typesetting algorithms from TeX, and designed to handle the world’s scripts, from Latin to Arabic to CJK.
Documents are created in milliseconds, not seconds. The line breaking algorithm finds the optimum layout for each paragraph, hyphenation works across languages, and the output can meet accessibility standards like PDF/UA.
boxes and glue is created by Patrick Gundlach, with contributions from other developers who send bug reports, fixes and new features on GitHub. Patrick also develops the speedata Publisher, and boxes and glue grew out of that work. Curious why it exists when there is TeX? Read the story.
ZUGFeRD invoice
Logo, columns, line items — a real business document
Table of contents
Auto-numbered with leader dots and page references
Mixed scripts
Bidirectional Arabic + English with per-language hyphenation
Styled tables
Driven entirely by CSS3 :nth-child selectors
Color emoji
COLR/CPAL, SVG, sbix and CBDT all supported
Charts from data
Server-less: JSON → vector graphics inside the PDF
glu: Markdown to PDF
glu is the easiest way to get started. Write your content in Markdown, and glu turns it into a properly typeset PDF:
glu document.md # → document.pdfFor simple documents, that’s all you need: glu ships with sensible defaults for fonts, page size, and styling. When you need more control, there’s YAML frontmatter for metadata, custom CSS for styling, embedded Lua for calculations and dynamic content, and a callback system for things like page decorations and headers.
bagme: HTML/CSS to PDF in Go
bagme is for Go developers who want to generate PDF from HTML and CSS without learning the typesetting internals. Write your content as HTML, style it with CSS, and bagme handles line breaking, pagination, and optional PDF/UA accessibility tagging.
d, err := document.New("output.pdf", document.WithPDFUA())
d.RenderPages(`<h1>Hello</h1><p>Content goes here.</p>`)XTS: PDF from XML data
XTS creates PDF documents from XML data: product catalogs, price lists, data sheets, anything where the same layout is filled with changing content. A layout file in XML says which data goes where, on a grid of rows and columns, with CSS for the styling and XPath to reach into the data. Text, tables and HTML are set by the same engine as glu and bagme.
xts new helloworld # a layout.xml and a data.xml to start from
cd helloworld
xts # → xts.pdfXTS comes from speedata and is meant to become the successor of the speedata Publisher. It is young, still in its 0.x versions, and its manual lives at speedata.
Go API: Full control
If you want to build your own tools or need full control over every typesetting primitive (fonts, paragraphs, pages, nodes), the Go library gives you direct access to the boxes and glue engine.
See the getting started guide for the Go API.
Hobby: SVG vector graphics
Hobby creates SVG vector graphics from Lua scripts. It implements the Hobby-Knuth smooth curve algorithm from MetaPost: you specify the points, and Hobby finds beautiful curves through them. Useful for diagrams, illustrations, and anything that needs precise curves.
Building blocks
Under the hood, boxes and glue is assembled from specialized libraries that are each usable on their own:
| Library | Description |
|---|---|
| htmlbag | HTML/CSS rendering on top of the typesetting engine: the layer behind bagme and glu’s HTML mode, with floats, footnotes, and PDF/UA tagging |
| textshape | Pure Go text shaping engine (a HarfBuzz port) that handles ligatures, kerning, variable fonts, and complex scripts |
| baseline-pdf | Low-level PDF writer in pure Go with minimal dependencies |
Latest news
-
Four months of typesetting: floats, page breaks and a typography chapter
October 7, 2026
Since June, text flows around images, page breaks keep headings with their text, tab stops line up columns, and a new typography chapter and fourteen how-tos explain it all. Plus line models and breakers for Go programs, and a thank-you to the people who contributed.
-
Table lines that stay visible in Adobe Acrobat
October 7, 2026
A thin line next to a colored area can vanish in Adobe Acrobat when the area is painted after it. Tables now paint their borders after all of their backgrounds, and Go programs can paint any rule last.
-
Mathematical typesetting: MathML in, accessible Formula tags out
June 18, 2026
boxesandglue gains an OpenType-MATH engine and a native MathML reader. Write <math>…</math> in your HTML and get TeX-quality formulas — tagged as accessible Formula structure elements under PDF/UA, with the MathML embedded as an associated file under PDF/UA-2.