{"id":20384,"library":"prettier-plugin-latex","title":"Prettier Plugin for LaTeX","description":"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.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/siefkenj/prettier-plugin-latex","tags":["javascript","latex","parser","prettier","typescript"],"install":[{"cmd":"npm install prettier-plugin-latex","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-latex","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-latex","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin requires Prettier to run.","package":"prettier","optional":false}],"imports":[{"note":"Prettier v3 is ESM-only; require() will fail.","wrong":"const prettier = require('prettier')","symbol":"default","correct":"import prettier from 'prettier'"},{"note":"The browser standalone function is in a separate module path.","wrong":"import { printPrettier } from 'prettier-plugin-latex'","symbol":"printPrettier","correct":"import { printPrettier } from 'prettier-plugin-latex/standalone'"},{"note":"For Prettier v3, use --plugin with ESM path (e.g., node_modules/prettier-plugin-latex/dist/index.js).","wrong":"const plugin = require('prettier-plugin-latex')","symbol":"plugin","correct":"import * as plugin from 'prettier-plugin-latex'"}],"quickstart":{"code":"import prettier from 'prettier';\nimport * as plugin from 'prettier-plugin-latex';\n\nconst code = `\\begin{enumerate}\n    \\item[55,4] Hi there\n\\end{enumerate}`;\n\nprettier.format(code, {\n  parser: 'latex',\n  plugins: [plugin],\n  tabWidth: 4,\n  printWidth: 80\n}).then(result => console.log(result));","lang":"javascript","description":"Shows how to format LaTeX using prettier-plugin-latex programmatically with Prettier v3 ESM import."},"warnings":[{"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.","message":"Prettier v3 removed automatic plugin resolution. You must explicitly pass --plugin=... or include plugins: [...] in config.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Switch to ESM imports or use dynamic import(). For scripts, change 'type': 'module' in package.json or use .mjs extension.","message":"Prettier v3 dropped CommonJS support (CJS). This plugin is now ESM-only.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your document follows typical LaTeX syntax. For complex macros, consider preprocessing or using a different formatter.","message":"The plugin cannot parse arbitrary TeX; it assumes standard LaTeX. Non-standard macros or unexpanded conditionals may cause formatting errors or no output.","severity":"gotcha","affected_versions":"*"},{"fix":"Use prettier.format() with the plugin loaded as shown in the quickstart.","message":"printPrettier from standalone may become unstable; prefer programmatic usage via prettier.format().","severity":"deprecated","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Change to import or use dynamic import. Ensure your project is ESM (type: module) or use .mjs files.","cause":"Using require() with an ESM-only package.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/prettier-plugin-latex/dist/index.js from /path/to/project not supported."},{"fix":"Add '--plugin=prettier-plugin-latex' or '--plugin=./node_modules/prettier-plugin-latex/dist/index.js' to the prettier CLI command.","cause":"Prettier v3 does not automatically resolve plugins; missing --plugin flag or plugins array in config.","error":"Cannot find module 'prettier-plugin-latex'"},{"fix":"Use dynamic import or switch to ESM: import prettier from 'prettier';","cause":"Using require() of default export from ESM module.","error":"TypeError: prettier.format is not a function"},{"fix":"Avoid using custom macros or non-standard LaTeX constructs. Simplify the document to match standard LaTeX.","cause":"The plugin expects standard LaTeX; non-standard syntax may cause parse failure.","error":"SyntaxError: Invalid or unexpected token (prettier-plugin-latex fails to parse file)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}