logoalt Hacker News

kccqzy • today at 7:04 PM • 1 reply • view on HN

How do you even do it without actual TeXLive? Pandoc’s flavor of markdown allows embedding arbitrary TeX code. Would appreciate that you explain the software implementation a bit more.

EDIT: wait you don’t. Enabling the pandoc compat mode disables PDF output on your website.


Replies

deyvium • today at 7:11 PM

The short answer is that --pdf-engine=embedded does not try to reimplement TeX Live or arbitrary TeX macros. If a Markdown document depends on arbitrary LaTeX packages like TikZ or custom macro packages, you still pass --pdf-engine=lualatex, pdflatex, xelatex, typst, or any of the other 15 external engines, just like Pandoc.

When you opt into --pdf-engine=embedded, Weavon skips generating .tex completely and lays out the Pandoc AST directly into PDF 1.7 in pure Rust inside crates/weavon-pdf/src/embedded/. The layout pass paginates headings, paragraphs, tables, footnotes, callouts, and two column layouts straight into zlib-compressed content streams. It embeds TrueType subsets as CID fonts with Unicode maps, using bundled Croscore Arimo and Cousine by default alongside optional font packs or custom fonts. It also converts SVGs directly into PDF vector form XObjects and writes structure trees and metadata for PDF/UA-1 and PDF/A-2u.

For TeX math, weavon-math parses each formula and lays it out against the actual glyph metrics of the embedded fonts, then draws positioned glyphs, rules, and vector paths in crates/weavon-pdf/src/embedded/math.rs.

For embedded raw LaTeX inside Markdown, crates/weavon-pdf/src/embedded/latex_boundary.rs acts as an explicit boundary scanner. It handles the common commands people put in Pandoc Markdown natively, including \newpage, \clearpage, \pagebreak, \vspace, \bigskip, \noindent, \hfill, line breaks, \textbf, \emph, \textit, \texttt, geometry options, and bounded \newcommand expansion inside math.

When it hits raw LaTeX outside that subset, --pdf-fallback controls what happens. The default mode, --pdf-fallback=off, skips the unsupported block and emits a W_PDF_UNSUPPORTED_RAW_LATEX warning. With --pdf-fallback=fragment, Weavon compiles just that raw block as a standalone fragment using lualatex, xelatex, or pdflatex and imports the resulting page as a vector form XObject via page_import.rs. With --pdf-fallback=document, it returns E_PDF_FALLBACK_DOCUMENT so a caller or build script can route the whole file to an external TeX engine instead.