All Projects → tamuratak → latex-utensils

tamuratak / latex-utensils

Licence: MIT license
A LaTeX parser and utilities.

Programming Languages

typescript
32286 projects
PEG.js
56 projects

Projects that are alternatives of or similar to latex-utensils

Pegjs
PEG.js: Parser generator for JavaScript
Stars: ✭ 4,176 (+12554.55%)
Mutual labels:  pegjs
gpkeditor
markdown editor with peg.js
Stars: ✭ 15 (-54.55%)
Mutual labels:  pegjs
feel
Expression Language for creating and executing business rules in decision table based on DMN 1.1 specification for conformance level 3
Stars: ✭ 76 (+130.3%)
Mutual labels:  pegjs
mfm.js
An MFM parser implementation
Stars: ✭ 24 (-27.27%)
Mutual labels:  pegjs
rpgdice
A generic RPG dice roller syntax and library.
Stars: ✭ 24 (-27.27%)
Mutual labels:  pegjs
peggy
Peggy: Parser generator for JavaScript
Stars: ✭ 444 (+1245.45%)
Mutual labels:  pegjs

latex-utensils

latex-utensils CI Tests

A LaTeX parser and utilities.

The parser is based on the following libraries:

Getting started

You can see LaTeX AST calling the luparse command. Without the option -i, you can obtain the output as JSON format.

$ cat sample/t.tex
\documentclass{article}
\usepackage{amsmath}
\begin{document}
ab c
d $x + y$ e
\begin{align}
    i + j
\end{align}
\end{document}

$ luparse --color -i sample/t.tex
{
  kind: 'ast.root',
  content: [
    {
      kind: 'command',
      name: 'documentclass',
      args: [
        {
          kind: 'arg.group',
          content: [ { kind: 'text.string', content: 'article' } ]
        }
      ]
    },
    { kind: 'softbreak' },
    {
      kind: 'command',
      name: 'usepackage',
      args: [
        {
          kind: 'arg.group',
          content: [ { kind: 'text.string', content: 'amsmath' } ]
        }
      ]
    },
    {
      kind: 'env',
      name: 'document',
      args: [],
      content: [
        { kind: 'text.string', content: 'ab' },
        { kind: 'space' },
        { kind: 'text.string', content: 'c' },
        { kind: 'softbreak' },
        { kind: 'text.string', content: 'd' },
        { kind: 'space' },
        {
          kind: 'inlineMath',
          content: [
            { kind: 'math.character', content: 'x' },
            { kind: 'math.character', content: '+' },
            { kind: 'math.character', content: 'y' }
          ]
        },
        { kind: 'space' },
        { kind: 'text.string', content: 'e' },
        {
          kind: 'env.math.align',
          name: 'align',
          args: [],
          content: [
            { kind: 'math.character', content: 'i' },
            { kind: 'math.character', content: '+' },
            { kind: 'math.character', content: 'j' }
          ]
        }
      ]
    }
  ],
  comment: undefined
}

$ luparse --help
Usage: luparse [options]

Options:
  -i, --inspect            use util.inspect to output AST
  --color                  turn on the color option of util.inspect
  -l, --location           enable location
  -c, --comment            enable comment
  -s, --start-rule [rule]  set start rule. default is "Root".
  -h, --help               output usage information

Usage

A typical usage is calling latexParser.parse to parse LaTeX documents.

import {latexParser} from 'latex-utensils';
const texString = 'a $x+y$ b';
const ast = latexParser.parse(texString);
console.log(JSON.stringify(ast, undefined, '  '));

latexParser.parse returns an AstRoot object if startRule is 'Root',

type AstRoot = {
    kind: 'ast.root';
    content: Node[];
    comment?: Comment[];
}

Docs

Repository

Development

To lint changes, run

npm run lint

To build, run

npm run build

To test, run

npm run test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].