1.8.2 • Published 5 months ago

@unified-latex/unified-latex-util-glue v1.8.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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

ParamType
nodes(Ast.Node \| Ast.Argument)[]
startIndexNumber

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

ParamType
nodes(Ast.Node \| Ast.Argument)[]
startIndexNumber

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

ParamType
sourceString

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

ParamType
glueGlue

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 };
};
1.8.2

5 months ago

1.8.1

9 months ago

1.8.0

11 months ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.4.2

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.2.1

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.12

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.0

3 years ago