Module @unified-latex/unified-latex-util-glue - v1.6.0

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

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.

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.
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

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.

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

Parameters

Param Type
glue Glue

where

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

Types

Glue

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

Index

Type Aliases

Functions

Generated using TypeDoc