{"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,"search_vec":"'/unified-latex-prettier':27 '18':21 '2.0.1':13 'arbitrari':60 'assum':63 'ast':34 'automat':49 'avail':68 'cannot':58 'caveat':45 'drop':48 'enabl':35 'environ':39 'esm':17 'file':11 'format':8,37 'javascript':69 'latex':4,9,26,31,65,70 'librari':28 'macro':43 'math':40 'mode':41 'must':52 'node':20 'notabl':44 'onlin':66 'pars':30,59 'parser':71 'playground':67 'plugin':2,6,50,54,57 'prettier':1,5,15,46,72 'requir':19 'resolut':51 'smart':36 'sourc':10 'specifi':53 'standard':64 'support':14 'tex':61 'typescript':73 'unifi':25 'unified-latex':24 'use':22 'v3':16,47 'version':12","created_at":"2026-04-25T11:22:50.089897+00:00","updated_at":"2026-04-25T11:22:50.089897+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"prettier","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/siefkenj/prettier-plugin-latex","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/prettier-plugin-latex","openapi_spec":null,"status_page":null,"smithery":null,"categories":[],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}