Packages and the search path
Documents of one kind, such as offers, letters or reports, share their page setup, fonts, colors and a few Lua helpers. A package keeps those in one place, and every document loads it with a single line in the frontmatter, the way a LaTeX document says \usepackage{offer}:
---
title: Offer 2026-117
use: offer
---What a package is
A package is a directory named after the package that holds a stylesheet, a Lua file or both, with the same name:
offer/
offer.css the stylesheet (optional)
offer.lua the Lua part (optional)
offer_format.lua further Lua modules of the package
logo.pdf anything the stylesheet or the Lua refers to
fonts/At least one of offer.css and offer.lua must exist. Everything else in the directory is up to you: the stylesheet and the Lua file find their files next to themselves.
Where glu looks
glu looks for a package next to the document first, then in the directories of the environment variable GLUPATH, in order. The first match wins, so a package next to the document overrides a shared one of the same name.
GLUPATH is a list of directories, separated like PATH (with : on macOS and Linux, ; on Windows), the counterpart of TEXINPUTS. Set it once in your shell profile:
export GLUPATH="$HOME/glu-packages"or for a single run:
GLUPATH=~/glu-packages:/srv/company-styles glu offer.mdA package that is found nowhere stops the run with an error that names every directory glu searched:
io error: use: package ofer not found (searched /home/me/offers, /home/me/glu-packages for ofer/ofer.css or ofer/ofer.lua)glu doctor shows the search path and the packages in it:
== Search path ($GLUPATH) ==
[OK] /home/me/glu-packages, packages: letter (css), offer (css+lua)
[WARN] /srv/company-styles does not existLoading packages
use: takes one package, a comma-separated list or a YAML list:
use: offer
use: offer, fonts
use: [offer, fonts]Packages load in the order given; a name that appears twice loads once. The --use flag adds packages from the command line, after those of the frontmatter. It is the way to load packages for an HTML document, which has no frontmatter:
glu --use offer page.htmlA Lua script does not take --use; it loads what it needs with require(), see Shared files without a package.
The stylesheet
The package stylesheet loads after glu’s default stylesheet and before everything that belongs to the document: papersize, the css: file and the document’s own styles. A document can therefore override any rule of a package, and --css still comes last. The complete order is listed under Add your own CSS.
@import and url() inside the stylesheet resolve next to the stylesheet, not next to the document, so a package can bring its own fonts and images:
/* offer/offer.css */
@font-face {
font-family: "Company Sans";
src: url("fonts/CompanySans-Regular.otf");
}
@page {
size: a4;
margin: 25mm 20mm;
background-image: url("logo.pdf");
}
body { font-family: "Company Sans"; }The Lua file
The Lua file of a package runs before the companion file of the document, in every pass. It works like a module that require() loads:
- It receives the package name and its directory as
.... - It can
require()further modules from its own directory. - Its return value becomes
package.loaded[name], so the companion file, Lua blocks and inline expressions reach it withrequire("offer"). A package that returns nothing is loaded astrue.
Options for a package go in the frontmatter under the package name, the counterpart of \usepackage[options]{offer}. The Lua file reads them from the _frontmatter table:
---
use: offer
offer:
customer: ACME Corp
currency: CHF
---
# {= require("offer").title() =}-- offer/offer.lua
local name, dir = ...
local format = require("offer_format") -- offer/offer_format.lua
local options = _frontmatter[name] or {}
return {
title = function()
return "Offer for " .. (options.customer or "?")
end,
price = function(amount)
return format.money(amount, options.currency or "EUR")
end,
}The package can also register callbacks, for example to draw a letterhead on every page, exactly like a companion file.
Give the modules of a package names of their own, such as offer_format.lua rather than format.lua. Every package that loads puts its directory in front of package.path, so two packages with a module format.lua would find each other’s.
Shared files without a package
The search path is not only for packages. glu looks up these files next to the document first and then in GLUPATH as well:
- the
css:file of the frontmatter:css: company.cssfinds~/glu-packages/company.css; - the files of
attachments:, for example a shared terms and conditions PDF; - Lua modules:
require("money")finds~/glu-packages/money.luaor~/glu-packages/money/init.lua. This works in companion files, Lua blocks and Lua scripts. An existingLUA_PATHstays in effect behind theGLUPATHdirectories.
A plain shared stylesheet is enough when a document needs only styling. A package pays off as soon as styling and Lua belong together.
Safe mode and watch mode
With --safe, require() cannot load files from disk, so GLUPATH does not extend package.path. The Lua file of a package still runs, inside the same sandbox as the companion file: without io and os, and require("offer") returns the package.
--watch rebuilds the document when the stylesheet or the Lua file of a package changes.