# latex2js

> LaTeX and PSTricks rendering & components for the Web

Latest version **4.5.0** (published 2026-08-25) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install latex2js
pnpm add latex2js
yarn add latex2js
bun add latex2js
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.5.0 |
| Published | 2026-08-25 |
| First published | 2018-03-06 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 250.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 625 |
| Author | Dan Lynch <pyramation@gmail.com> |
| Maintainers | pyramation |
| Keywords | latex, mathjax, latex2html, latex2js, math, mathematics, pstricks, graphics, diagrams, math diagrams |

## Links

- npm: https://www.npmjs.com/package/latex2js
- Repository: https://github.com/Mathapedia/LaTeX2JS
- Issues: https://github.com/Mathapedia/LaTeX2JS/issues
- npm.io page: https://npm.io/package/latex2js

## Dependencies (3)

- [@latex2js/utils](https://npm.io/package/@latex2js/utils.md) ^4.2.0
- [@latex2js/pstricks](https://npm.io/package/@latex2js/pstricks.md) ^4.2.0
- [@latex2js/settings](https://npm.io/package/@latex2js/settings.md) ^4.2.0

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 4.5.0 (latest) — 2026-08-25
- 3.0.4 (next) — 2025-07-05
- 4.4.1 — 2026-08-25
- 4.4.0 — 2026-08-25
- 4.3.1 — 2026-08-25
- 4.3.0 — 2026-08-24
- 4.0.8 — 2026-08-24
- 4.0.7 — 2026-08-18
- 4.0.3 — 2026-08-17
- 4.0.1 — 2026-08-17
- 3.1.4 — 2025-07-22
- 3.1.3 — 2025-07-06
- 3.1.2 — 2025-07-06
- 3.1.1 — 2025-07-05
- 3.0.11 — 2025-07-05
- … 45 more at https://npm.io/package/latex2js/versions

## README

# latex2js

The core LaTeX parsing and rendering engine for LaTeX2JS. This package provides the fundamental LaTeX-to-HTML conversion functionality with support for mathematical notation, environments, and PSTricks graphics.

## Installation

```bash
npm install latex2js
```

## Features

- **Mathematical Notation**: Seamless integration with MathJax for math rendering
- **PSTricks Graphics**: Support for interactive PSTricks diagrams
- **Environment Support**: Built-in support for common LaTeX environments

## API Reference

### LaTeX2HTML5 Class

The main parser class for converting LaTeX to HTML:

```typescript
import { LaTeX2HTML5 } from 'latex2js';

const parser = new LaTeX2HTML5();
const html = parser.parse(latexContent);
```

#### Methods

```typescript
// Parse LaTeX content to HTML
parse(latex: string): string

// Add custom macros
addMacros(macros: string): void

// Parse specific environments
parseEnvironment(envName: string, content: string): string

// Process headers and metadata
processHeaders(latex: string): HeaderInfo
```

## Usage Examples

### Basic Document Parsing

```typescript
import { LaTeX2HTML5 } from 'latex2js';

const parser = new LaTeX2HTML5();

const latexDocument = `
The quadratic formula is:
$$x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$$

\\begin{pspicture}(-1,-1)(1,1)
  \\pscircle(0,0){0.8}
  \\rput(0,0){Circle}
\\end{pspicture}
`;

const parsed = parser.parse(latexDocument);
```

### Custom Macros Integration

```typescript
import { LaTeX2HTML5 } from 'latex2js';
import macros from '@latex2js/macros';

const parser = new LaTeX2HTML5();

// Add predefined macros
parser.addMacros(macros);

// Add custom macros
const customMacros = `
\\newcommand{\\R}{\\mathbb{R}}
\\newcommand{\\norm}[1]{\\left\\|#1\\right\\|}
\\newcommand{\\abs}[1]{\\left|#1\\right|}
`;

parser.addMacros(customMacros);

const content = `
For any vector $\\vec{v} \\in \\R^n$, we have:
$$\\norm{\\vec{v}} = \\sqrt{\\sum_{i=1}^n v_i^2}$$

And for any real number $x \\in \\R$:
$$\\abs{x} = \\begin{cases}
x & \\text{if } x \\geq 0 \\\\
-x & \\text{if } x < 0
\\end{cases}$$
`;

const result = parser.parse(content);
```

---
_Source: https://npm.io/package/latex2js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
