Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tamuratak/latex-utensils
A LaTeX parser, a BibTeX parser, and utilities.
https://github.com/tamuratak/latex-utensils
bibtex javascript latex parser pegjs typescript
Last synced: 7 days ago
JSON representation
A LaTeX parser, a BibTeX parser, and utilities.
- Host: GitHub
- URL: https://github.com/tamuratak/latex-utensils
- Owner: tamuratak
- License: mit
- Created: 2019-05-25T02:03:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-09T23:23:03.000Z (4 months ago)
- Last Synced: 2024-10-10T22:31:10.406Z (2 months ago)
- Topics: bibtex, javascript, latex, parser, pegjs, typescript
- Language: TypeScript
- Homepage:
- Size: 1.49 MB
- Stars: 41
- Watchers: 6
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# latex-utensils
[![latex-utensils](https://img.shields.io/npm/v/latex-utensils)](https://www.npmjs.com/package/latex-utensils)
[![CI Tests](https://github.com/tamuratak/latex-utensils/workflows/CI%20Tests/badge.svg)](https://github.com/tamuratak/latex-utensils/actions)A LaTeX parser, a BibTeX parser, and utilities.
The LaTeX parser is based on the following libraries:
- https://github.com/michael-brade/LaTeX.js
- https://github.com/siefkenj/latex-parser## 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`](https://tamuratak.github.io/latex-utensils/modules/main.latexparser.html#parse) to parse LaTeX documents.
```typescript
import {latexParser} from 'latex-utensils';
const texString = 'a $x+y$ b';
const ast = latexParser.parse(texString);
console.log(JSON.stringify(ast, undefined, ' '));
```[`latexParser.parse`](https://tamuratak.github.io/latex-utensils/modules/main.latexparser.html#parse) returns an [`AstRoot`](https://tamuratak.github.io/latex-utensils/modules/latex_latex_parser_types.html#astroot) object if [`startRule`](https://tamuratak.github.io/latex-utensils/interfaces/main.latexparser.parseroptions.html#startrule) is `'Root'`,
```typescript
type AstRoot = {
kind: 'ast.root';
content: Node[];
comment?: Comment[];
}
```## Docs
- https://tamuratak.github.io/latex-utensils/
## Repository
- https://github.com/tamuratak/latex-utensils
## Development
To lint changes, run
npm run lint
To build, run
npm run build
To test, run
npm run test