Folio Writer's compile pipeline covers the 99% — citations, cross-references, templates, formats. Lua filters are the escape hatch for the last 1%: the journal's odd house rule, your own shorthand, the thing no checkbox anticipates. A filter is a few lines of Lua that rewrite the document during compilation, and pandoc runs them natively — nothing to install.
When pandoc compiles your manuscript, it first parses the Markdown
into a document tree — paragraphs, headers, spans, citations. A Lua
filter is a set of functions named after those elements; each one gets
called with every matching element and may return a replacement. Return
nothing to leave it alone, return {} to delete it, return
new elements to transform it. That's the whole model.
Since 1.17 a filter can belong to the project — it runs on every compile and preview, on every device, and on the web — or to a compile profile on one Mac. Project filters are the ones to reach for.
.lua document kept in the binder under
Templates ▸ Lua Filters, editable in the editor and synced with
the project; Built-in — the filters that ship with Folio Writer
(below); or File… — a .lua anywhere on this Mac
(it stays on this Mac).
builtin:abstract-section.lua.These ship inside the app and are referenced in the project as
builtin:<name>.lua, so a project that lists one works
on every Mac, on iPhone and iPad, and on the Folio Writer server. The
academic templates come with the ones they need already switched on.
| Filter | What it does |
|---|---|
| abstract-section | A section headed Abstract —
the binder title of an Abstract document, or a # Abstract
you typed — is lifted out of the body into the abstract:
metadata, so it lands where each format keeps abstracts: the LaTeX
title block, elsarticle's abstract box, IEEEtran, Typst's and Word's
abstract slot. A Keywords section right after it becomes
keywords:. An abstract: already in the
metadata wins. |
| scholarly-authors | The structured author list
the templates use — name, email, orcid, corresponding, affiliations —
comes out right through plain pandoc: superscript affiliation
numbers, the affiliation lines and the corresponding author's e-mail
under the names, date: today as today's date; in PDF,
Word, HTML and Typst. |
| elsevier-authors | Elsevier's elsarticle
front matter — \author, \ead,
\corref, \affiliation, abstract, keywords,
and the journal in the preprint footer — from the same metadata, plus
the preamble elsarticle needs under pandoc. |
| ieee-authors | IEEEtran's author blocks and
\begin{IEEEkeywords} from the same metadata. |
| yaml-in-latex | A raw LaTeX block marked
% template may use pandoc template syntax —
$title$, $for(author)$…$endfor$ — with the
project's metadata, for a title page or a footer of your own. |

abstract-section and scholarly-authors.author:
- name: First Author
email: [email protected]
corresponding: true
affiliations:
- name: University
department: Department of Earth & Planetary Sciences
- name: Second Author
affiliations:
- name: Institute
date: today
Compile to PDF: the title block shows First Author1,*, Second Author2, the numbered affiliations, the corresponding author's address and today's date, and the abstract sits under them — no LaTeX typed anywhere. Switch the template to Elsevier or IEEE and the same metadata becomes that class's front matter instead.
small-caps-units.lua, and paste:-- Units like "150 GPa" or "2300 K." in small capitals.
local units = { GPa = true, MPa = true, K = true, kbar = true }
function Str(el)
local unit, tail = el.text:match("^(%a+)(%p*)$")
if not (unit and units[unit]) then return nil end
local out = { pandoc.SmallCaps({ pandoc.Str(unit) }) }
if tail ~= "" then out[#out + 1] = pandoc.Str(tail) end
return out
end
Then Project Settings ▸ Compile ▸ Lua filters ▸ Add ▸ From Templates. The preview updates at once, the filter syncs with the project to your other Macs, and because it is a document you can edit it in place — change the unit list and the next preview uses it.
Type @@today anywhere; the compiled document carries the
compile date — useful in cover letters and draft watermarks:
-- today.lua
function Str(el)
if el.text == "@@today" then
return pandoc.Str(os.date("%B %e, %Y"))
end
end
Write notes-to-self in a fenced div, visible while drafting, guaranteed absent from output:
::: draft Ask Wei whether the 2019 calibration applies here. :::
-- strip-draft.lua
function Div(el)
if el.classes:includes("draft") then
return {} -- deleted from every compiled format
end
end
Attach it only to your submission profiles and the notes still appear in your advisor-draft profile — per-profile filters are exactly for this.
Give [key result]{.highlight} a real meaning per format —
a yellow mark in HTML, a highlight in LaTeX PDFs:
-- highlight.lua
function Span(el)
if not el.classes:includes("highlight") then return nil end
if FORMAT:match("latex") then
local out = pandoc.Inlines(pandoc.RawInline("latex", "\\hl{"))
out:extend(el.content)
out:insert(pandoc.RawInline("latex", "}"))
return out
elseif FORMAT:match("html") then
local out = pandoc.Inlines(pandoc.RawInline("html", ""))
out:extend(el.content)
out:insert(pandoc.RawInline("html", ""))
return out
end
end
For the LaTeX branch, add the highlighting package once in the Format
metadata: header-includes: \usepackage{soul}.
Two habits make filter-writing painless. To see the tree you're
matching against, run pandoc -t native on a snippet in
Terminal — it prints exactly the elements your functions will receive.
And when a compile misbehaves, Compile & Preview Log shows the
full pandoc command line and its output, filter errors included. One
Folio-specific note: a filter whose file has moved is skipped rather than
failing the compile — check the log if a filter seems silently
inactive.
The pandoc Lua filter documentation lists every element and helper, and the community's filter collection is full of ready-made ones — abbreviation handling, table tweaks, diagram rendering. Anything there drops straight into the compile sheet.