# @latex2js/utils

> latex2js utilities

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

## Install

```sh
npm install @latex2js/utils
pnpm add @latex2js/utils
yarn add @latex2js/utils
bun add @latex2js/utils
```

## 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.2.0 |
| Published | 2026-08-24 |
| First published | 2025-07-05 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 65.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 625 |
| Author | Dan Lynch <pyramation@gmail.com> |
| Maintainers | pyramation |
| Keywords | latex, latex2html, latex2js, math, mathematics, mathjax |

## Links

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

## 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.2.0 (latest) — 2026-08-24
- 3.0.4 (next) — 2025-07-05
- 4.0.4 — 2026-08-24
- 4.0.3 — 2026-08-17
- 4.0.1 — 2026-08-17
- 3.0.12 — 2025-07-06
- 3.0.11 — 2025-07-06
- 3.0.10 — 2025-07-05
- 3.0.9 — 2025-07-05
- 3.0.8 — 2025-07-05
- 3.0.1 — 2025-07-05
- 3.0.0 — 2025-07-05
- 2.1.0 — 2025-07-05

## README

# @latex2js/utils

Core utility functions for LaTeX parsing, SVG manipulation, and mathematical computations used throughout the LaTeX2JS ecosystem.

## Installation

```bash
npm install @latex2js/utils
```

## Features

- **String Processing**: Advanced pattern matching and replacement utilities
- **Unit Conversion**: Convert between different measurement units (px, em, pt, cm, etc.)
- **Coordinate Transformation**: Mathematical coordinate system transformations
- **Mathematical Evaluation**: Safe evaluation of mathematical expressions
- **SVG Manipulation**: D3-like interface for SVG DOM manipulation
- **LaTeX Parsing**: Utilities for parsing LaTeX options and arrows

## API Reference

### String Utilities

```typescript
import { simplerepl, matchrepl } from '@latex2js/utils';

// Simple string replacement
const result = simplerepl(text, 'pattern', 'replacement');

// Pattern matching with capture groups
const result = matchrepl(text, /(\w+)=(\w+)/, (match, key, value) => {
  return `${key}: ${value}`;
});
```

### Unit Conversion

```typescript
import { convertUnits } from '@latex2js/utils';

// Convert units to pixels
const pixels = convertUnits('2cm'); // Returns pixel equivalent
const pixels2 = convertUnits('12pt'); // Returns pixel equivalent
```

### Coordinate Transformation

```typescript
import { X, Y, Xinv, Yinv } from '@latex2js/utils';

// Transform coordinates based on current coordinate system
const screenX = X(mathematicalX);
const screenY = Y(mathematicalY);

// Inverse transformations
const mathX = Xinv(screenX);
const mathY = Yinv(screenY);
```

### Mathematical Expression Evaluation

```typescript
import { evaluate } from '@latex2js/utils';

// Safely evaluate mathematical expressions
const result = evaluate('2 * pi + sin(pi/4)');
const result2 = evaluate('sqrt(16) + log(e)');
```

### SVG Manipulation

```typescript
import { select, SVGSelection } from '@latex2js/utils';

// D3-like interface for SVG manipulation
const svg = select(svgElement);

svg.append('line')
   .attr('x1', 0)
   .attr('y1', 0)
   .attr('x2', 100)
   .attr('y2', 100)
   .attr('stroke', 'black');

svg.append('circle')
   .attr('cx', 50)
   .attr('cy', 50)
   .attr('r', 25)
   .attr('fill', 'red');
```

### LaTeX Parsing Utilities

```typescript
import { parseOptions, parseArrows } from '@latex2js/utils';

// Parse LaTeX command options
const options = parseOptions('[linecolor=red, fillcolor=blue]');
// Returns: { linecolor: 'red', fillcolor: 'blue' }

// Parse arrow specifications
const arrows = parseArrows('->');
// Returns arrow configuration object
```

## Usage in LaTeX2JS Ecosystem

This package serves as the foundation for all other LaTeX2JS packages:

- **@latex2js/settings**: Uses utilities for option parsing and unit conversion
- **@latex2js/pstricks**: Heavily relies on coordinate transformation and SVG manipulation
- **latex2js**: Uses string processing utilities for LaTeX parsing
- **latex2html5**: Uses SVG utilities for rendering graphics

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