Working examples for boxes and glue, a PDF typesetting library in Go that brings TeX's line breaking and page layout to HTML, Markdown, XSL-FO, Lua and Go programs. Every example holds its source, and most also the PDF it makes and a preview of the first page.
The examples are sorted by what they show below. Most of them use glu, the command line tool, and need nothing but a text editor; the others are Go programs. Where an example has a how-to on the website, the how-to walks through it step by step.
![]() Scientific paper Two columns, equations, figures, PDF/UA-2, from Markdown |
![]() Multi-column layout CSS columns with a spanning title and balanced columns |
![]() Margin notes Notes in the outer margin of a book page |
![]() Business letter DIN 5008 letter with fixed address fields |
![]() Electronic invoice ZUGFeRD / Factur-X as PDF/A-3 with the invoice XML attached |
![]() Right-to-left text Arabic paragraphs with alignment, floats and indents |
- Articles, reports and books
- Business documents
- Page layout
- Tables and tab stops
- Mathematics
- Text, fonts and languages
- Images, charts and barcodes
- Accessible PDF (PDF/UA)
- Smallest programs and PDF internals
The second column names the input: glu reads Markdown, HTML, XSL-FO (through a Lua walker), JATS XML or a Lua script. bagme is a Go package that typesets HTML and CSS, the Go API is boxes and glue itself, and baseline-pdf is the low-level PDF writer beneath it.
| Example | Made with | Shows |
|---|---|---|
| Scientific paper | glu, Markdown | Two-column article with an abstract across both columns, numbered equations, figures, a table, footnotes and references; PDF/UA-2 (how-to) |
| JATS article | glu, JATS XML | A journal article in JATS, the XML of PubMed Central, with MathML formulas, figures and references |
| Accessible report | glu, Markdown | A report tagged as PDF/UA-2 by one line in the frontmatter (how-to) |
| Table of contents | glu, Markdown | A contents list whose page numbers and dot leaders come from CSS (how-to) |
| Cross references | glu, Markdown | References to headings and inline anchors with their text and page number filled in by CSS |
| Numbered sections | glu, HTML | Section numbers hanging in the left margin, as in rule books and legal texts |
| Numbered sections with counters | glu, HTML | The same layout with the numbers counted by CSS counters |
| Highlighting | glu, Markdown | Highlighter marks and strikethrough in a draft (how-to) |
| Slides | glu, Markdown | A 16:9 slide deck with curves drawn by Lua |
| Example | Made with | Shows |
|---|---|---|
| DIN 5008 letter | glu, Markdown | A German business letter with fixed fields for sender, recipient, date and fold marks (how-to) |
| Letterhead | glu, HTML | A PDF letterhead behind the text, different on the first page (how-to) |
| ZUGFeRD invoice | glu, Markdown | An EN 16931 invoice as PDF/A-3 with the XML attached, set up by a companion Lua file (how-to) |
| ZUGFeRD invoice | glu, Lua | The same kind of invoice built entirely with the Lua API |
| ZUGFeRD invoice | bagme | The invoice from a Go program with WithZUGFeRD |
| Accessible ZUGFeRD invoice | bagme | PDF/A-3b and PDF/UA-1 in one document |
| Example | Made with | Shows |
|---|---|---|
| Multi-column layout | glu, HTML | Two columns with a title across both and balanced columns on the last page |
| Lines in register | glu, HTML | Lines that stand level across columns with line-snap, past headings, a table and a top float (how-to) |
| A PDF for the print shop | glu, HTML | PDF/X-4 with bleed, crop marks, a spot color and overprinting black text (how-to) |
| Margin notes | glu, HTML | Notes in the outer margin with float: outside, on the right of right pages and the left of left pages (how-to) |
| Text around images | glu, HTML | Pictures and a box of facts floated left and right, with the text flowing around them (how-to) |
| Floats next to each other | glu, HTML | Several floats on one side, standing next to each other |
| Running footer | glu, HTML | A footer repeated on every page with CSS running elements (how-to) |
| Top and bottom floats, footnotes | glu, HTML | Floats at the top and bottom of the page and footnotes, in five steps |
| Floats in XSL-FO | glu, XSL-FO | fo:float and fo:footnote on one page; see also 02 and 03 |
| Page breaks | bagme | Automatic page breaks and forced ones with page-break-before |
| Placing at a position | bagme | HTML set at absolute coordinates with OutputAt |
| Example | Made with | Shows |
|---|---|---|
| Table column widths | glu, Markdown | Column widths for HTML tables and Markdown pipe tables (how-to) |
| Zebra-striped table | glu, HTML | Striped rows and a totals footer from CSS structural selectors, no classes needed |
| SVG in table cells | glu, HTML | A dashboard table with an SVG chart in every cell, sized to the cell |
| Table with repeating header | bagme | A table over several pages that repeats its header |
| Simple table | Go API | Rows and columns with the table builder |
| Table with cell spans | Go API | colspan and rowspan |
| Tab stops | glu, Markdown | Columns without a table: dot leaders, decimal alignment and centered captions (how-to) |
| Tab stops | Go API | Left, right, center and decimal stops with leaders |
| Example | Made with | Shows |
|---|---|---|
| TeX math in Markdown | glu, Markdown | Formulas in TeX dollar syntax, tagged for PDF/UA-2 (how-to) |
| MathML | glu, HTML | Inline and display MathML with accessible formula tagging |
| MathML | bagme | The same from a Go program, as PDF/UA-2 |
| Math engine | Go API | Formulas built directly with the OpenType MATH engine, without MathML or TeX |
| Example | Made with | Shows |
|---|---|---|
| Right-to-left paragraphs | glu, HTML | Arabic with all text-align values, floats, indents and a Latin run inside an Arabic line |
| Arabic | glu, XSL-FO | Arabic shaping and right-to-left order without any setting |
| Mixed directions | glu, XSL-FO | English and Arabic in one paragraph, each hyphenated in its own language |
| Alignment and hyphenation | glu, Markdown | Heading classes, German hyphenation and fine tuning of the line breaker |
| Soft hyphens | glu, XSL-FO | The hyphens modes side by side |
| Font fallback | glu, HTML | Latin, emoji and Arabic from one font-family list, the font chosen per character |
| Color emoji (COLR) | glu, HTML | Layered color glyphs |
| Color emoji (CBDT) | glu, HTML | Bitmap color glyphs |
| List markers | glu, HTML | Bullets and numbers styled with ::marker |
| Text shaping | glu, Lua | The glyphs, clusters and advances shaping returns, printed to the console |
| Example | Made with | Shows |
|---|---|---|
| Chart from data | glu, Markdown | A Lua block turns a data table into an SVG bar chart (how-to) |
| Barcodes | glu, Markdown | EAN-13, Code 128 and QR codes with the <barcode> element (how-to) |
| Barcodes | bagme | The same barcodes from a Go program |
| Inline image alignment | glu, HTML | An image in a line of text with vertical-align |
| Transparency in SVG | glu, HTML | A poster with fog from stop-opacity, a reflection in a transparency group and glass panels with alpha |
| Image with percentage width | glu, HTML | A raster image sized to its container |
| SVG with percentage width | glu, HTML | One SVG in three containers of different widths |
| Image in the flow | glu, XSL-FO | A PDF placed as an image, kept as vectors |
| Image in a float | glu, XSL-FO | A figure with caption at the top of the page |
| Borders and backgrounds | bagme | Borders, rounded corners and background colors |
| Example | Made with | Shows |
|---|---|---|
| Accessible report | glu, Markdown | PDF/UA-2 from Markdown (how-to) |
| PDF/UA-1 | glu, XSL-FO | A tagged PDF/UA-1 document |
| PDF/UA-2 | glu, XSL-FO | The same as PDF/UA-2 on PDF 2.0 |
| Accessible PDF | bagme | Structure tags from HTML for screen readers |
| Accessible ZUGFeRD invoice | bagme | PDF/UA-1 together with PDF/A-3b |
The scientific paper, TeX math and MathML examples are tagged as PDF/UA-2 too.
| Example | Made with | Shows |
|---|---|---|
| Simple page | bagme | HTML with CSS, lists and code blocks to PDF |
| Hello world | Go API | Load a font, set a paragraph, write a page |
| XSL-FO walker | glu, XSL-FO | The smallest XSL-FO document: page master, blocks, inline markup, footnotes |
| Simple PDF | baseline-pdf | A two-page PDF from the raw page tree |
| Font | baseline-pdf | A font loaded and a line of text written without the layers above |
| Image | baseline-pdf | A PDF page imported as a Form XObject |
| Hyperlink | baseline-pdf | A clickable link annotation |
| Bookmarks, direct | baseline-pdf | A bookmark tree pointing at pages |
| Bookmarks, named | baseline-pdf | A bookmark tree pointing at named destinations |
- glu: all glu examples by input format, and how to install glu
- bagme: the Go package for HTML and CSS
- Go API examples are in frontend, baseline-pdf examples in baseline.
- glu: inside the example's directory, run glu on the source file,
for example
glu multi-column.html -o out.pdf. The Readme of each example gives the exact command. - bagme, Go API, baseline-pdf: inside the example's directory, run
go run .
Fonts used by several examples are in fonts, images in images.
- boxes and glue: https://boxesandglue.dev/
- glu: https://boxesandglue.dev/glu/
- bagme: https://boxesandglue.dev/bagme/
- htmlbag: https://boxesandglue.dev/htmlbag/
- Go API: https://boxesandglue.dev/goapi/





