Files & bibliography
Real documents are more than one .tex file — they pull in bibliographies,
images, and included sub-documents. The files option carries all of them into
the compilation sandbox.
Attaching files
Section titled “Attaching files”files is a Record<string, Buffer>. Each key becomes a filename inside the
sandbox, so your LaTeX references them by exactly that name.
import { readFile } from 'node:fs/promises';import { compile } from '@nandan-varma/platex';
const result = await compile(source, { bibliography: 'bibtex', files: { 'refs.bib': await readFile('refs.bib'), 'figures/logo.png': await readFile('logo.png'), 'chapters/intro.tex': await readFile('intro.tex'), },});Given the keys above, your source uses them directly:
\includegraphics{figures/logo.png}\input{chapters/intro}\bibliography{refs}Which maps to this sandbox layout:
- main.tex (your
source) - refs.bib
Directoryfigures/
- logo.png
Directorychapters/
- intro.tex
Over HTTP
Section titled “Over HTTP”When sending files to the remote service (or through a request handler),
Buffer values are transported as base64 strings on the wire:
files: { 'refs.bib': bibBuffer.toString('base64'), 'logo.png': logoBuffer.toString('base64'),}The library handles this conversion for you when you call compile() with real
Buffers; you only base64-encode manually when constructing an HTTP request
body by hand. See the HTTP API.
Bibliography
Section titled “Bibliography”The bibliography option chooses the engine used when your document cites
sources:
| Value | Engine | When to use |
|---|---|---|
'bibtex' (default) |
BibTeX | Classic \bibliography{} + .bst styles |
'biber' |
Biber | biblatex-based documents |
'none' |
— | No bibliography processing |
const result = await compile(source, { bibliography: 'biber', files: { 'refs.bib': await readFile('refs.bib') },});With local system TeX Live, platex runs the bibliography tool between LaTeX
passes: it detects \citation{} entries in the .aux file, runs bibtex/biber,
then re-runs LaTeX so citations and the reference list resolve. With
Tectonic (remote/bundled), multi-pass compilation and bibliography are
handled internally by the engine.
A complete example
Section titled “A complete example”import { readFile } from 'node:fs/promises';import { compile } from '@nandan-varma/platex';
const source = await readFile('main.tex', 'utf-8');
const result = await compile(source, { bibliography: 'bibtex', files: { 'refs.bib': await readFile('refs.bib'), 'figures/plot.pdf': await readFile('figures/plot.pdf'), },});
if (result.pdf) { await writeFile('out.pdf', result.pdf);}The CLI walks directories recursively and keys files relative to the input’s directory:
platex main.tex -f refs.bib -f figures/ -b bibtexSee CLI & watch mode for the details.