# @unified-latex/unified-latex-util-catcode

> Tools for manipulating unified-latex ASTs

Latest version **1.8.4** (published 2026-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @unified-latex/unified-latex-util-catcode
pnpm add @unified-latex/unified-latex-util-catcode
yarn add @unified-latex/unified-latex-util-catcode
bun add @unified-latex/unified-latex-util-catcode
```

## Health

**Score 60/100 (C)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.8.4 |
| Published | 2026-04-03 |
| First published | 2022-11-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 77.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 127 |
| Author | Jason Siefken |
| Maintainers | siefkenj |
| Keywords | pegjs, latex, parser, prettier, unified-latex, unified |

## Links

- npm: https://www.npmjs.com/package/@unified-latex/unified-latex-util-catcode
- Repository: https://github.com/siefkenj/unified-latex
- Homepage: https://github.com/siefkenj/unified-latex#readme
- Issues: https://github.com/siefkenj/unified-latex/issues
- npm.io page: https://npm.io/package/@unified-latex/unified-latex-util-catcode

## Dependencies (3)

- [@unified-latex/unified-latex-types](https://npm.io/package/@unified-latex/unified-latex-types.md) ^1.8.4
- [@unified-latex/unified-latex-util-match](https://npm.io/package/@unified-latex/unified-latex-util-match.md) ^1.8.4
- [@unified-latex/unified-latex-util-visit](https://npm.io/package/@unified-latex/unified-latex-util-visit.md) ^1.8.4

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.8.4 (latest) — 2026-04-03
- 1.8.3 — 2025-06-16
- 1.8.2 — 2025-02-09
- 1.8.0 — 2024-08-22
- 1.7.1 — 2024-03-19
- 1.7.0 — 2024-02-25
- 1.6.1 — 2024-02-18
- 1.6.0 — 2024-01-17
- 1.4.2 — 2023-09-30
- 1.4.0 — 2023-06-20
- 1.3.2 — 2023-04-26
- 1.3.1 — 2023-03-05
- 1.3.0 — 2023-02-06
- 1.2.2 — 2022-12-15
- 1.2.1 — 2022-11-23
- … 2 more at https://npm.io/package/@unified-latex/unified-latex-util-catcode/versions

## README

<!-- DO NOT MODIFY -->
<!-- This file was autogenerated by build-docs.ts -->
<!-- Edit the docstring in index.ts and regenerate -->
<!-- rather than editing this file directly. -->
# unified-latex-util-catcode

## What is this?

Functions to identify regions of a `unified-latex` Abstract Syntax Tree (AST) that need to be reparsed because of different
category codes. For example, regions between `\makeatletter` and `\makeatother`.

## When should I use this?

If you need to identify regions of the AST that need to be reparsed.

## Install

```bash
npm install @unified-latex/unified-latex-util-catcode
```

This package contains both esm and commonjs exports. To explicitly access the esm export,
import the `.js` file. To explicitly access the commonjs export, import the `.cjs` file.

# Functions

## `findExpl3AndAtLetterRegionsInArray(tree)`

Find regions between `\ExplSyntaxOn...\ExplSyntaxOff` and `\makeatletter...\makeatother`.
Returns an object containing regions where one or both syntax's apply.

```typescript
function findExpl3AndAtLetterRegionsInArray(tree: Ast.Node[]): {
  explOnly: Region[];
  atLetterOnly: Region[];
  both: Region[];
};
```

**Parameters**

| Param | Type         |
| :---- | :----------- |
| tree  | `Ast.Node[]` |

## `findRegionInArray(tree, start, end)`

Find all contiguous segments in the array that are between start and end blocks.
The `start` and `end` are functions that determine when a region starts and ends.

```typescript
function findRegionInArray(
  tree: Ast.Node[],
  start: (node: Ast.Node) => boolean,
  end: (node: Ast.Node) => boolean
): Region[];
```

**Parameters**

| Param | Type                          |
| :---- | :---------------------------- |
| tree  | `Ast.Node[]`                  |
| start | `(node: Ast.Node) => boolean` |
| end   | `(node: Ast.Node) => boolean` |

## `hasReparsableMacroNames(tree, allowedTokens)`

Checks whether `tree` has a macro that could be reparsed given the `allowedTokens` but
do not do any reparsing. This function can be used in auto-detection schemes to determine if
macro names should actually be reparsed.

```typescript
function hasReparsableMacroNames(
  tree: Ast.Ast,
  allowedTokens: string | Set<string>
): boolean;
```

**Parameters**

| Param         | Type                    |
| :------------ | :---------------------- |
| tree          | `Ast.Ast`               |
| allowedTokens | `string \| Set<string>` |

## `hasReparsableMacroNamesInArray(tree, allowedTokens)`

Checks whether the array has a macro that could be reparsed given the `allowedTokens` but
do not do any reparsing. This function can be used in auto-detection schemes to determine if
macro names should actually be reparsed.

```typescript
function hasReparsableMacroNamesInArray(
  tree: Ast.Node[],
  allowedTokens: Set<string>
): boolean;
```

**Parameters**

| Param         | Type          |
| :------------ | :------------ |
| tree          | `Ast.Node[]`  |
| allowedTokens | `Set<string>` |

## `reparseExpl3AndAtLetterRegions(tree)`

Find regions between `\ExplSyntaxOn...\ExplSyntaxOff` and `\makeatletter...\makeatother`
and reparse their contents so that the relevant characters (e.g., `@`, `_`, and `:`) become
part of the macro names.

```typescript
function reparseExpl3AndAtLetterRegions(tree: Ast.Ast): void;
```

**Parameters**

| Param | Type      |
| :---- | :-------- |
| tree  | `Ast.Ast` |

## `reparseMacroNames(tree, allowedTokens)`

Reparses all macro names so that they may optionally include characters listed in `allowedTokens`.
This is used, for example, when parsing expl3 syntax which allows `_` to be used in a macro name (even though
`_` is normally stops the parsing for a macro name). Thus, a macro `\foo_bar:Nn` would be parsed as having
the name `foo_bar:Nn` rather than as `foo` followed by the strings `_`, `bar`, `:`, `Nn`.

```typescript
function reparseMacroNames(
  tree: Ast.Ast,
  allowedTokens: string | Set<string>
): void;
```

**Parameters**

| Param         | Type                    |
| :------------ | :---------------------- |
| tree          | `Ast.Ast`               |
| allowedTokens | `string \| Set<string>` |

## `reparseMacroNamesInArray(tree, allowedTokens)`

Reparses all macro names in the array so that they may optionally include characters listed in `allowedTokens`.
This is used, for example, when parsing expl3 syntax which allows `_` to be used in a macro name (even though
`_` is normally stops the parsing for a macro name).

```typescript
function reparseMacroNamesInArray(
  tree: Ast.Node[],
  allowedTokens: Set<string>
): void;
```

**Parameters**

| Param         | Type          |
| :------------ | :------------ |
| tree          | `Ast.Node[]`  |
| allowedTokens | `Set<string>` |

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