Skip to content

platex

Compile LaTeX to PDF in TypeScript, with output as accurate as your local TeX toolchain. One function, any framework, Node.js or the edge.

@nandan-varma/platex compiles LaTeX to PDF from TypeScript. It works in any framework that speaks the Fetch API — Next.js, TanStack Start, Astro, SvelteKit, Remix, Bun, Deno, Cloudflare Workers — on Node.js or the edge. Nothing is hardcoded: every engine, timeout, limit, auth token, and retry setting is an option with a sane default and an env-var fallback.

Terminal window
npm install @nandan-varma/platex
import { compile } from '@nandan-varma/platex';
const result = await compile(source, {
serviceUrl: process.env.PLATEX_SERVICE_URL, // omit — read automatically
});
if (result.pdf) {
// result.pdf is a Buffer — return, save, or stream it
}

Accurate PDF output

Standard engine flags, multi-pass logic, and rerun heuristics for faithful LaTeX-to-PDF rendering — as accurate as your local TeX toolchain.

Runs anywhere

Node.js or the edge. Three entry points: a full Node library, an edge-safe remote-only client, and a server factory to embed the API.

Two deployment targets

A remote service for Vercel (bundled Tectonic), or full TeX Live locally / self-hosted — the same library auto-selects.

Structured diagnostics

Errors and warnings parsed from raw TeX logs, with file, line, and category — plus per-pass raw logs for debugging.

A real CLI

The same pipeline as a platex binary — watch mode, extra files, remote compilation, stdin, and JSON output.

Zero config

Set PLATEX_SERVICE_URL and go. Every option is optional, overridable per call, per client, or per deployment.

The same handleCompileRequest handler — a standard RequestResponse function — works in every framework. Next.js also gets a dedicated page per rendering pattern:

  • Server Componentscompile() runs during the server render; the PDF ships in the initial HTML.
  • Client Components — edit LaTeX in the browser and compile on demand via fetch.
  • Server Actions — a form submits straight to a 'use server' function.
  • Route Handlers — the raw HTTP endpoint backing the other patterns.
  • Other frameworks — Astro, SvelteKit, Remix, TanStack Start, Bun, Deno, Hono, Cloudflare Workers.