
A Working Mathematician’s Guide to Parsing - imgabe
https://jeremykun.com/2019/04/20/a-working-mathematicians-guide-to-parsing/
======
OskarS
> _Our hero, a mathematician, is writing notes in LaTeX and needs to convert
> it to a format that her blog platform accepts. She’s used to using dollar
> sign delimiters for math mode, but her blog requires \\( \\) and \\[ \\]._

Unless our hero mathematician is writing, like, several blog posts a day,
using tools like parser generators and writing your grammar in BNF and the
like is WAY overkill. Just use search/replace and manually fix it up. Or,
like, maybe some kind of editor macro/multiple cursor nonsense in your fully-
featured text editor. If she really wants to go nuts, she should write a four-
line python script to do the search/replace a tiny bit smarter. Fixing it up
with some manual oversight takes like three minutes per blog post at most,
it's not worth trying to automate fully.

This is one of them "killing an ant with a nuclear bomb" situations.

~~~
acprog42
But killing an ant with a nuclear bomb is moar funnier! Don't stop the fun!

------
RiversHaveWings
My go-to library for parsing in Python is
[https://github.com/pyparsing/pyparsing](https://github.com/pyparsing/pyparsing),
a
[https://en.wikipedia.org/wiki/Parsing_expression_grammar](https://en.wikipedia.org/wiki/Parsing_expression_grammar)
-based
[https://en.wikipedia.org/wiki/Parser_combinator](https://en.wikipedia.org/wiki/Parser_combinator)
library. I generally find it _much_ easier to get my head around parser
combinators than parser generators.

~~~
vorg
As the author says:

> because the parser generator knows about all patterns you want to match in
> advance, it will match longer terminals before shorter—more
> ambiguous—terminals

If you don't mind manually ordering your choices in your alt operators, then
PEG and parser combinators are OK.

Oh, and you often need to restructure your grammar to avoid left recursion.

------
satyenr
Just use pandoc[1] — assuming the blog platform accepts a well known markup
language.

[1] [https://pandoc.org](https://pandoc.org)

------
kevinventullo
For converting LaTex to WordPress, I'm a fan of
[https://lucatrevisan.wordpress.com/latex-to-
wordpress/](https://lucatrevisan.wordpress.com/latex-to-wordpress/)

------
pgtan
Sadly, he don't understand what LaTeX is and what TeX is. And $$ is a TeX
macro, should not be used in LaTeX, the are much better math display
environments.

~~~
joppy
Regardless, this is a very common way of writing mathematics in LaTeX, and so
will need to be addressed in any solution to this problem.

