Skip to content
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

LaTeX to Emmy converter #13

Open
ronnyli opened this issue May 21, 2023 · 3 comments
Open

LaTeX to Emmy converter #13

ronnyli opened this issue May 21, 2023 · 3 comments

Comments

@ronnyli
Copy link

ronnyli commented May 21, 2023

You probably thought of this already and this repo might not be the right place to talk about it, but if Emmy translates to LaTeX then it could do the opposite, which would be insane. I could open any academic paper and turn their proofs and formulas into executable code...

@sritchie
Copy link
Member

I love this idea! I've done a bit of the work here already, and I'd love to hear how this experience looks /feels to you:

https://mathlive.mentat.org/

This is an equation editor like you're suggesting, with the ability to generate "MathJSON" out of the editable LaTeX: https://mathlive.mentat.org/#mathjson

The idea is that I can turn that MathJSON blob into an emmy function, so you could take that example of yours and define f using the equation editor. So where you had

(defn f [x] (* 3 (square x)))

And then (D f) below, you'd instead define f like f(x) := 3x^2, rendered as TeX.

Let me know what else you're thinking here for this experience and let's make it happen.

@sritchie
Copy link
Member

image looks like a katex bug there at the end, rendering `\coloneq` as `:-`...

@ronnyli
Copy link
Author

ronnyli commented May 21, 2023

Thank you for sharing! I think what you have is very useful for people who are already comfortable in LaTeX or with constructing equations in general. For a math noob like myself, I would be worried about making a mistake when trying to recreate something I saw in a paper.

I would be more confident in the MathJSON/Emmy output if I could copy-paste in LaTeX from somewhere else since I know there's no chance of human error. I have no idea how feasible that is!

Example: I'm reading a paper or Wikipedia article (example) and I come across a formula that I'd like to use in my own codebase:

Screenshot 2023-05-21 at 1 21 25 PM

I copy-paste the resulting string into a function that converts to Emmy:

(latex->emmy "\operatorname {Var} (X)=\sum _{i=1}^{n}p_{i}\cdot (x_{i}-\mu )^{2}")

Here's an example of GPT doing such conversion into Python. I chose Python since GPT is more likely to make mistakes in Clojure.

Screenshot 2023-05-21 at 1 24 41 PM

I like the idea of converting to Emmy for many reasons, one of which is that I can render it back into LaTeX which would be helpful to ensure that no mistakes were made in translation. When using GPT, I kind of have to hope that it worked unless I was already an expert in the formula / code.

Anyway, just an idea I had this morning. Glad you found it interesting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants