siefkenj / unified-latex

Utilities for parsing and manipulating LaTeX ASTs with the Unified.js framework
MIT License
85 stars 20 forks source link

Add getParser() to inject plugin options #33

Closed James-Yu closed 1 year ago

James-Yu commented 1 year ago

This PR adds a getParser() function to unified-latex-util-parse package.

This PR partially resolve the issue in #32 . The actual use case is that, it seems not possible to avoid directly importing unifiedjs when trying to pass plugin options of unifiedLatexFromString to the parser. When working on platforms without ESM support (e.g., electron), this becomes almost impossible to customize the LaTeX parser.

With this new function, user can indirectly invoke the use() of unified to create a LaTeX parser with custom macros and envs. A possible use case is illustrated at https://github.com/James-Yu/LaTeX-Workshop/blob/unified-latex/src/components/parser.ts#L163-L200 .

This PR will have full effect with another PR shortly on bundling ESM dependencies when creating .cjs distributions.