Registry / devops / node-latex-compiler

node-latex-compiler

JSON →
library1.0.5jsnpmunverified

Node.js LaTeX compiler wrapper using Tectonic engine with automatic binary download. Current stable version 1.0.5, actively maintained. Key differentiators: zero system dependencies, cross-platform binary auto-detection (Windows, macOS Intel/ARM, Linux), automatic CTAN package management, multiple I/O formats (file, text, buffer), real-time stdout/stderr streaming, and full TypeScript definitions. Unlike traditional LaTeX distributions (MiKTeX, TeX Live) or other Node wrappers (node-latex, latex-js), this package requires no manual installation of LaTeX binaries and handles platform-specific binaries automatically.

npm install node-latex-compiler
INSTALL
IMPORT
SIG · NODE-LATEX-COMPILE
N
node-latex-compiler
devopsjavascriptv1.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compile
import { compile } from 'node-latex-compiler'
const compile = require('node-latex-compiler')
Default export is not available; only named export. CommonJS users must use destructuring require. This is an ESM-first package but supports both ESM and CJS.
compile
const { compile } = require('node-latex-compiler')
const compile = require('node-latex-compiler').default
For CommonJS, destructure from require. Using .default will result in undefined.
compile type
import type { CompileConfig, CompileResult } from 'node-latex-compiler'
TypeScript types for config and result are auto-generated and available as named exports. Use type imports for runtime-free type usage.

Compiles a LaTeX string to PDF buffer with real-time stdout/stderr streaming and writes the output file.

import { compile } from 'node-latex-compiler'; const tex = `\\documentclass{article} \\usepackage{amsmath} \\begin{document} Hello, World! This is a test document. \\[ E = mc^2 \\] \\end{document}`; async function main() { const result = await compile({ tex: tex, outputDir: './output', returnBuffer: true, onStdout: (data) => process.stdout.write(`[stdout] ${data}`), onStderr: (data) => process.stderr.write(`[stderr] ${data}`), }); if (result.status === 'success') { const fs = await import('fs'); fs.writeFileSync('./output.pdf', result.pdfBuffer); console.log('PDF generated as buffer'); } else { console.error('Compilation failed:', result.stderr); } } main().catch(console.error);
Debug
Known issues
gotchaAutomatic binary download occurs during npm install, which may fail in restricted environments (corporate proxies, CI with no outbound access).
fix
Pre-download the binary for your platform and set the TECTONIC_BIN environment variable to its path before running compile.
affects: >=1.0.0
breakingThe compile function returns different result shapes depending on whether returnBuffer is true or false. Ensure you check the correct property (pdfPath vs pdfBuffer).
fix
Always check result.status first, then access result.pdfPath (file output) or result.pdfBuffer (buffer output) accordingly.
affects: >=1.0.0
deprecatedThe texFile and tex parameters are mutually exclusive but no runtime validation is performed; passing both will cause undefined behavior.
fix
Pass exactly one of tex or texFile. Do not pass both.
affects: >=1.0.0
gotchaOn Linux, the auto-downloaded binary may require libfontconfig1 to be installed. Missing this library causes silent failure.
fix
Install libfontconfig1 on Debian/Ubuntu: sudo apt-get install libfontconfig1
affects: >=1.0.0
gotchaThe package does not support custom binary paths via environment variable (e.g., TECTONIC_BIN). You must use the auto-downloaded binary.
fix
If you need a custom binary, consider forking the package or pre-placing your binary at the expected location.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'node-latex-compiler'
Package not installed or failed to install (binary download may have failed).
fix
Reinstall: rm -rf node_modules && npm install node-latex-compiler
Error: spawn /path/to/tectonic ENOENT
The downloaded binary is missing, corrupted, or lacks execute permissions.
fix
Reinstall the package or manually set executable permissions: chmod +x node_modules/node-latex-compiler/bin/tectonic-*
TypeError: compile is not a function
Incorrect import: importing default instead of named export, or using require without destructuring.
fix
Use correct import: import { compile } from 'node-latex-compiler' (ESM) or const { compile } = require('node-latex-compiler') (CJS).
Error: tex and texFile are mutually exclusive
Passing both tex and texFile parameters to compile().
fix
Provide only one of tex (string content) or texFile (file path).
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources