Registry / prettier-plugin-latex

prettier-plugin-latex

JSON →
library2.0.1jsnpmunverified

Prettier plugin for formatting LaTeX source files. Version 2.0.1 supports Prettier v3 (ESM) and requires Node >= 18. Uses the @unified-latex/unified-latex-prettier library for parsing LaTeX into an AST, enabling smart formatting of environments, math mode, and macros. Notable caveats: Prettier v3 dropped automatic plugin resolution (must specify --plugin), and the plugin cannot parse arbitrary TeX — it assumes standard LaTeX. Online playground available.

npm install prettier-plugin-latex
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-LA
P
prettier-plugin-latex
javascriptv2.0.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

default
✓ import prettier from 'prettier'
✗ const prettier = require('prettier')
Prettier v3 is ESM-only; require() will fail.
printPrettier
✓ import { printPrettier } from 'prettier-plugin-latex/standalone'
✗ import { printPrettier } from 'prettier-plugin-latex'
The browser standalone function is in a separate module path.
plugin
✓ import * as plugin from 'prettier-plugin-latex'
✗ const plugin = require('prettier-plugin-latex')
For Prettier v3, use --plugin with ESM path (e.g., node_modules/prettier-plugin-latex/dist/index.js).

Shows how to format LaTeX using prettier-plugin-latex programmatically with Prettier v3 ESM import.

import prettier from 'prettier'; import * as plugin from 'prettier-plugin-latex'; const code = `\begin{enumerate} \item[55,4] Hi there \end{enumerate}`; prettier.format(code, { parser: 'latex', plugins: [plugin], tabWidth: 4, printWidth: 80 }).then(result => console.log(result));
prettier --version
Debug
Known issues
breakingPrettier v3 removed automatic plugin resolution. You must explicitly pass --plugin=... or include plugins: [...] in config.
fix
Add --plugin=node_modules/prettier-plugin-latex/dist/index.js when running prettier on the command line, or include 'prettier-plugin-latex' in the plugins array of your config.
affects: >=2.0.0
breakingPrettier v3 dropped CommonJS support (CJS). This plugin is now ESM-only.
fix
Switch to ESM imports or use dynamic import(). For scripts, change 'type': 'module' in package.json or use .mjs extension.
affects: >=2.0.0
gotchaThe plugin cannot parse arbitrary TeX; it assumes standard LaTeX. Non-standard macros or unexpanded conditionals may cause formatting errors or no output.
fix
Ensure your document follows typical LaTeX syntax. For complex macros, consider preprocessing or using a different formatter.
affects: *
deprecatedprintPrettier from standalone may become unstable; prefer programmatic usage via prettier.format().
fix
Use prettier.format() with the plugin loaded as shown in the quickstart.
affects: >=2.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/prettier-plugin-latex/dist/index.js from /path/to/project not supported.
Using require() with an ESM-only package.
fix
Change to import or use dynamic import. Ensure your project is ESM (type: module) or use .mjs files.
Cannot find module 'prettier-plugin-latex'
Prettier v3 does not automatically resolve plugins; missing --plugin flag or plugins array in config.
fix
Add '--plugin=prettier-plugin-latex' or '--plugin=./node_modules/prettier-plugin-latex/dist/index.js' to the prettier CLI command.
TypeError: prettier.format is not a function
Using require() of default export from ESM module.
fix
Use dynamic import or switch to ESM: import prettier from 'prettier';
SyntaxError: Invalid or unexpected token (prettier-plugin-latex fails to parse file)
The plugin expects standard LaTeX; non-standard syntax may cause parse failure.
fix
Avoid using custom macros or non-standard LaTeX constructs. Simplify the document to match standard LaTeX.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
prettierrequiredPeer dependency; plugin requires Prettier to run.
Agent activity
4 hits · last 30 days
node
4
Resources
prettier-plugin-latex — npm install prettier-plugin-latex · libregistry