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-latexVerified import paths — ran on the pinned version, not inferred.
Shows how to format LaTeX using prettier-plugin-latex programmatically with Prettier v3 ESM import.
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.
Switch to ESM imports or use dynamic import(). For scripts, change 'type': 'module' in package.json or use .mjs extension.
Ensure your document follows typical LaTeX syntax. For complex macros, consider preprocessing or using a different formatter.
Use prettier.format() with the plugin loaded as shown in the quickstart.
Change to import or use dynamic import. Ensure your project is ESM (type: module) or use .mjs files.
Add '--plugin=prettier-plugin-latex' or '--plugin=./node_modules/prettier-plugin-latex/dist/index.js' to the prettier CLI command.
Use dynamic import or switch to ESM: import prettier from 'prettier';
Avoid using custom macros or non-standard LaTeX constructs. Simplify the document to match standard LaTeX.