@unified-latex/unified-latex-util-pgfkeys
TypeScript icon, indicating that this package has built-in type declarations

1.7.1 • Public • Published

unified-latex-util-pgfkeys

What is this?

Functions to help manipulate unified-latex Abstract Syntax Tree (AST) that contain pgfkeys-style arguments. Note that pgfkeys aren't built into Ast.Ast. Instead, parsing nodes as pgfkeys will produce a new (incompatible) AST.

When should I use this?

If you want to parse or manipulate macros/environments with pgfkeys-style arguments.

Install

npm install @unified-latex/unified-latex-util-pgfkeys

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

createMatchers()

function createMatchers(): {
  isChar: (node: Ast.Node, char: string) => boolean;
  isComma: (node: Ast.Node) => boolean;
  isEquals: (node: Ast.Node) => boolean;
  isWhitespace: (node: Ast.Node) => boolean;
  isParbreak: (node: Ast.Node) => boolean;
  isSameLineComment: (node: Ast.Node) => boolean;
  isOwnLineComment: (node: Ast.Node) => boolean;
};

parsePgfkeys(ast, options)

Parse the arguments of a Pgfkeys macro. The ast is expected to be a comma separated list of Items. Each item can have 0 or more item parts, which are separated by "=". If itemPart is undefined,

If options.allowParenGroups === true, then commas that occur inside groups of parenthesis will not be parsed as separators. This is useful for parsing tikz \foreach loops.

function parsePgfkeys(
  ast: Ast.Node[],
  options: { allowParenGroups: boolean }
): Item[];

Parameters

Param Type
ast Ast.Node[]
options Omitted

pgfkeysArgToObject(arg)

Parse arg as pgfkeys and return a JavaScript object with the results. The keys will be normalized to strings and the values will be arrays of nodes.

function pgfkeysArgToObject(
  arg: Ast.Node[] | Ast.Argument
): Record<string, Ast.Node[]>;

Parameters

Param Type
arg Ast.Node[] | Ast.Argument

Types

Item

export type Item = {
    itemParts?: Ast.Node[][];
    trailingComment: Ast.Comment | null;
    trailingComma?: boolean;
    leadingParbreak?: boolean;
};

Package Sidebar

Install

npm i @unified-latex/unified-latex-util-pgfkeys

Weekly Downloads

1,008

Version

1.7.1

License

MIT

Unpacked Size

19.4 kB

Total Files

7

Last publish

Collaborators

  • siefkenj