latex-parser is a JavaScript/TypeScript library designed to build abstract syntax trees (ASTs) for LaTeX documents. As of version 0.6.2, its primary focus is on parsing a subset of 'canonical' LaTeX, specifically prioritizing text mode over comprehensive mathematical typesetting. It distinguishes itself from full TeX parsers by acknowledging the extreme complexity of a complete LaTeX grammar, similar to how KaTeX focuses on math typesetting within a subset. The project evolved from a TypeScript fork of TeXnous and is now modeled after the Haskell LaTeX library HaTeX. While no explicit release cadence is stated, its versioning and active GitHub suggest ongoing iterative development. Developers should be aware of its intentional scope limitations when choosing this parser for their projects.
npm install latex-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to install `latex-parser`, import the `latexParser` object, and use its `parse` method to generate an Abstract Syntax Tree (AST) from a LaTeX string, then logs the resulting AST.
Review the project's documentation and live demo to understand the specific subset of LaTeX syntax it supports. Do not expect it to handle complex TeX macros, custom environments, or advanced mathematical typesetting without potential parsing errors or incomplete ASTs. Consider alternative parsers if full LaTeX/TeX compatibility is required (e.g., those for math expressions or other languages).
Always import `latexParser` as the main object: `import { latexParser } from 'latex-parser';` and then call its method: `latexParser.parse(...)`.When upgrading from versions prior to 0.3.0, carefully review the AST structure and expected parsing behavior as the internal implementation and model significantly changed. Test existing parsing logic thoroughly.
Ensure you are using the correct ES Module import: `import { latexParser } from 'latex-parser';`. Then call `latexParser.parse(...)`. If in a CommonJS environment, ensure your bundler or runtime correctly resolves the ESM export.This is often a direct consequence of the library's intentional limitation to a subset of LaTeX. Simplify the input LaTeX, remove complex or unsupported commands/environments, or use a different parser that targets full TeX or specific complex LaTeX features if your document requires it.
Consult the `latex-parser` TypeScript declaration files (`.d.ts`) to verify available type exports. Ensure you are using `import type { CorrectTypeName } from 'latex-parser';` for type-only imports.No dependency data recorded yet.