1.8.1 • Published 9 months ago

@unified-latex/unified-latex-util-pgfkeys v1.8.1

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

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) => node is Ast.String; isComma: (node: Ast.Node) => node is Ast.String; isEquals: (node: Ast.Node) => node is Ast.String; isWhitespace: (node: Ast.Node) => node is Ast.Whitespace; isParbreak: (node: Ast.Node) => node is Ast.Parbreak; isSameLineComment: (node: Ast.Node) => boo...

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

ParamType
astAst.Node[]
optionsOmitted

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

ParamType
argAst.Node[] \| Ast.Argument

Types

Item

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