-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change TeX-style math delimiters to LaTeX-style #18
Comments
Thanks for this suggestion! It seems from the StackOverflow discussion that providing a good solution to this problem is difficult; tex-fmt is based on pattern matching and regex, so likely is unable (at least in its current form) to handle the edge cases described. If a robust solution can be formulated, I would be happy to incorporate it, probably with an optional flag. |
Thanks, I'll keep my eyes open and my fingers crossed. |
@leingang |
It's doable using regular expressions, though I only managed to get it to work with pcre2. |
@PiotrSokol would you be able to share your implementation of this? It could be a good starting point. |
this doesn't cover all the corner cases, but should work with other regex flavors
and
|
I'm going to start a list here of potential pitfalls for implementing such ideas.
See the |
Hi, I dont know how this is works behind the scenes but wanted to give some ideas (sorry if it makes no sense). Also, really thankfull for all your work, hope everyone here the best. It seems like regex-matching arbitrary latex files is prone to fail in this scenario (see the pitfalls in previous comment from WGUNDERWOOD). I dont know if its just hard to implement or impossible at all, I never found a perfect solution so without technical background I bet the latter. IDEA: run only from STDIN I personally (just my preference) only run tex-fmt as a filter from nvim, using The rationale is that running it only as a filter, over a limited, known text should be a lot safer, even if the regex is limited for whatever reason (classical example with html). So for the user, It sould be easier to see if the formatting missbehaves if its only done over a couple lines/paragraphs, compared to a whole file. For example, if the above pitfalls aren't solved, and the formatting messes up indentation, inserts whatever symbols, or any random fail, the user will inmediatly see the error and could just ctrl-z back. If trying to use it over a whole file it could give a warn like It isnt perfect because it doesnt solve the issue, just tries to lessen the errors. But could be usefull to some extent. At least for me it would. Thanks for your time! |
Thanks for these thoughts @deivisCode ! I agree that we should take care when implementing these "risky" regexes, and I like the suggestion of adding a flag to substitute delimiters. I would probably prefer to do this than to have it coupled to existing flags such as |
Congrats on the new project! I just took it for a spin.
In addition to indenting, I'm looking for a formatter that changes TeX-style math delimiters (
$...$
and$$...$$
) to the LaTeX style (\(...\)
and\[...\]
). I've used the LaTeX style for display math mode for decades, but experience has taught me to prefer it for inline math mode too.I know a 100% perfect solution isn't possible with regular expressions only, so I'm hoping your project reads input files like TeX does natively. I've never done anything in Rust before so I can't tell from the source how it works.
See also:
The text was updated successfully, but these errors were encountered: