What can I leverage (from R) to convert expressions with nested fractions from infix-notation to LaTeX?

Viewed 19

I'd like something to convert pretty basic math expressions, having nested parentheses and fractions, to LaTeX notation. Like mathquill, but a function (or even the building blocks of one).

There seem to be some Lua and Haskell solutions in a pandoc/Rmarkdown context, but I can't use those, because (a) I'm scared of real languages, and (b) I'm generating PNGs (via webtex) to be featured in a flextable table, outside of a rendered document.

I'm inexperienced with regular expressions, so I don't know how to leverage something like this, but I'd appreciate any pointers if that seems like a productive path.

"Write a parser" is something best left to others, at least in my case!

Example expression below. Just a few levels of nesting, no big deal. I can bound it at, say, 5 levels, if that helps. And the input is parseable as an R expression—I can guarantee matched parentheses, for example.

(y0 - (y0/((1-y0)*exp(B*dx)+y0)))*Pop

Here's what I'd want in the case above. The \cdots are sugar; I can handle those.

\left(y0-\frac{y0}{\left(1-y0\right)\cdot\exp\left(B\cdot dx\right)+y0}\right)\cdot Pop

Visually:

(y0 - (y0/((1-y0)exp(Bdx)+y0)))*Pop

0 Answers
Related