-
-
Notifications
You must be signed in to change notification settings - Fork 8
Description
I have made some modifications since I became one of the maintainers, but I have not been able to actively participate in the development over the past few years.
I had discovered some problems but had put them off due to the complexity of the current code base.
Several major events have occurred during this time.
- latex-utensils releases additional 3 major releases.
- textlint-plugin-latex2e depends on v3.x. However, the latest is v6.1.
- There are known to be some difficulties in updating.
- Starting with textlint v13.0.0, all AST NodeTypes are now defined!
- LaTeX Workshop, the VSCode extension that led me to introduce latex-utensils, unified-latex started being used
This project is a viable solution for using textlint in LaTeX, even in the year 2024, with no alternative.
I began to think that it might be appropriate to rebuild the entire project once in order to maintain it on an ongoing basis.
This means building v2 from scratch.
Which parser library is better for us?
For v2 I re-evaluated several LaTeX parsers written in TypeScript or JavaScript.
Sample TeX source is as follows:
% This is the beginning of the document
\documentclass{article} % This is a comment
\begin{document}
This is a paragraph that contains inline math: $E=mc^2$.
This is a second line.
% This is the beginning of the nested document
\begin{itemize}
\item First item
\item Second item
\item Third item
\end{itemize}
\begin{tabular}{|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 \\
\hline
Row 1 & Row 1 & Row 1 \\
\hline
Row 2 & Row 2 & Row 2 \\
\hline
\end{tabular}
\end{document}latex-utensils v6.2.0
Generated AST of sample tex source is here.
- Pros
- We already know this parser
- Fast
- Less dependencies
- Cons
space,linebreak,softbreakdo not have location information.- Comments can be parsed, but it is not in AST. We should calculate the position of them in AST.
completeCommentfunc is implemented for this.
unified-latex v1.6.0
Generated AST of sample tex source is here.
- Pros
- Most
whitespacehas location information. - Comments are included in AST by default.
- Most
- Cons
whitespaceandparbreakaround\itemhas no location information- Parbreak between item environment has no position siefkenj/unified-latex#73
- Maybe, we should implement the feature to calculate position of them.
whitespacemay be asoftbreak- latex-utensils parses it as
softbreak: https://github.com/pddg/eval-js-latex-parsers/blob/88f3ed88f8da01540da3e73d64b4d076ad6c94fb/latex-utensils/output.json#L310-L312 - unified-latex parses it as
whitespace(softbreakis not defined in unified-latex): https://github.com/pddg/eval-js-latex-parsers/blob/88f3ed88f8da01540da3e73d64b4d076ad6c94fb/unified-latex/output.json#L514-L528
- latex-utensils parses it as
- Large dependencies
- Compatibility with ES module
- Cannot import any types in unified-latex-types with
"module": "Node16"siefkenj/unified-latex#72 - We can use it via
"module": "ESNext"and"moduleResolution": "Bundler", now.
- Cannot import any types in unified-latex-types with
- Slower than latex-utensils
completeBlank and completeComment is hard to maintain. I think it might be worth the transition.
LaTeX.js v0.12.6
(As far as I could tell) this could not be used as a mere parser.
It may be possible to define a Generator that generates textlint ASTs from LaTeX ASTs.
However, I do not know how to create a Generator. Document says TODO, now.
https://latex.js.org/api.html#class-generator
Create original one
Another option would be to make your own, but the reason other parsers produce such output in the first place is because that is the way TeX syntax is written.
Therefore, it is difficult to imagine that a home-built parser would be significantly easier for us to use.
Goal of v2
- Correct AST of textlint is constructed from LaTeX source.
- Add snapshot test.
- By verifying that the snapshot of expected output matches the actual output, we should be able to implement more tests more easily.
- Add integration test if possible.
- Ensure that violation of rule can be detected while using this plugin.
- Ensure that fixable problem provided by some rules can be fixed while using this plugin.
Non Goal
- Keep AST compatible with v1
- Enhance unit tests currently implemented
How do we do
As maintainers, we should work on one of the following
- Work on v2
- Continue to improve on v1
- Declare Deprecated and archive repository