# @unified-latex/unified-latex-util-glue

> Parse TeX glue

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

## Install

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

## 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-05-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 29.8 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-glue
- 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-glue

## 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-pegjs](https://npm.io/package/@unified-latex/unified-latex-util-pegjs.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.1 — 2024-10-21
- 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.1 — 2023-03-05
- 1.3.0 — 2023-02-06
- 1.2.2 — 2022-12-15
- 1.2.1 — 2022-11-23
- … 10 more at https://npm.io/package/@unified-latex/unified-latex-util-glue/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-glue

## What is this?

Functions to parse TeX glue (e.g. `1in plus 3cm minus .2pt`).

## When should I use this?

If you need access to the values of glue to analyze `\setlength` commands or write
linters.

## Install

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

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

## `extractFormattedGlue(nodes, startIndex)`

Extract glue from a list of nodes returning a node array with
properly formatted glue as well as start/end indices where the glue was
"sliced out" of `nodes`.

Sometimes glue may end in the middle of a string node. If this happens, the
string node is split and the second half is returned in the `trailingStrings` array.

```typescript
function extractFormattedGlue(
  nodes: (Ast.Node | Ast.Argument)[],
  startIndex: Number
): {
  glue: Ast.Node[];
  span: { start: number; end: number };
  trailingStrings: Ast.String[];
};
```

**Parameters**

| Param      | Type                           |
| :--------- | :----------------------------- |
| nodes      | `(Ast.Node \| Ast.Argument)[]` |
| startIndex | `Number`                       |

## `findGlue(nodes, startIndex)`

Finds patterns matching TeX glue in `nodes`. A pretty-formatted version
of the glue is returned along with information about how many nodes were consumed.

The return object consists of

*   `printedGlue` - the pretty-printed version of the glue
*   `endIndex` - the index in `nodes` where the glue string terminates
*   `partialSliceLen` - how far into the `Ast.String` node the glue string finished. For example `1ptXX` would parse as `1pt`, and the parsing would terminate partway through the string node.

```typescript
function findGlue(
  nodes: (Ast.Node | Ast.Argument)[],
  startIndex: Number
): { printedGlue: Ast.Node[]; endIndex: number; partialSliceLen: number };
```

**Parameters**

| Param      | Type                           |
| :--------- | :----------------------------- |
| nodes      | `(Ast.Node \| Ast.Argument)[]` |
| startIndex | `Number`                       |

## `parseTexGlue(source)`

Parse a string that starts with TeX glue (e.g. `1pt` or `1pt plus 2em`).
It is assumed that all whitespace and comments have been stripped from the glue

```typescript
function parseTexGlue(source: String): Glue;
```

**Parameters**

| Param  | Type     |
| :----- | :------- |
| source | `String` |

## `printGlue(glue)`

Prints a `Glue` object to an AST. After printing, `glue`
is turned into a sequence of string and whitespace nodes.
All structural information about the glue is lost.

```typescript
function printGlue(glue: Glue): Ast.Node[];
```

**Parameters**

| Param | Type   |
| :---- | :----- |
| glue  | `Glue` |

where

```typescript
type Glue = {
  type: "glue";
  fixed: Dim;
  stretchable: Dim | null;
  shrinkable: Dim | null;
  position: { start: Position; end: Position };
};
```

# Types

## `Glue`

```typescript
export type Glue = {
    type: "glue";
    fixed: Dim;
    stretchable: Dim | null;
    shrinkable: Dim | null;
    position: { start: Position; end: Position };
};
```

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