1.7.1-ems • Published 12 months ago

@ems-press/unified-latex-util-ligatures v1.7.1-ems

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

unified-latex-util-ligatures

What is this?

Functions to find and replace ligatures in a unified-latex Abstract Syntax Tree (AST) with their Unicode equivalents.

When should I use this?

If you are converting LaTeX to plain text or HTML.

Install

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

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(): { isMacro: (node: any) => node is Ast.Macro; isWhitespace: (node: any) => node is Ast.Whitespace; isRecognized: (nodes: Ast.Node[], whitespaceAllowed?: boolean) => Ast.String; isSplitable: (node: Ast.Node) => boolean; split: (node: Ast.String) => { ...; }[]; }

expandUnicodeLigatures(tree)

Turn all ligatures into their unicode equivalent. For example, --- -> an em-dash and \^o to ô. This only applies in non-math mode, since programs like katex will process math ligatures.

function expandUnicodeLigatures(tree: Ast.Ast): void;

Parameters

ParamType
treeAst.Ast

parseLigatures(ast)

Parse for recognized ligatures like --- and \:o, etc. These are replaced with string nodes with the appropriate unicode character subbed in.

function parseLigatures(ast: Ast.Node[]): Ast.Node[];

Parameters

ParamType
astAst.Node[]