• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

tamuratak/latex-utensils: A LaTeX parser and utilities.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

tamuratak/latex-utensils

开源软件地址(OpenSource Url):

https://github.com/tamuratak/latex-utensils

开源编程语言(OpenSource Language):

TypeScript 80.2%

开源软件介绍(OpenSource Introduction):

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



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap