Convert latex to wolframalpha.com compatible expression

372 Views Asked by At

I have latex

\frac{-\left(2\left(b_{x}-a_{x}\right)\right)+\sqrt{\left(2\left(b_{x}-a_{x}\right)\right)^{2}-4\left(a_{x}-2b_{x}+c_{x}\right)\left(a_{x}-g_{x}\right)}}{2\left(a_{x}-2b_{x}+c_{x}\right)}

It's not malformed and renders as:

$$ \frac{-\left(2\left(b_{x}-a_{x}\right)\right)+\sqrt{\left(2\left(b_{x}-a_{x}\right)\right)^{2}-4\left(a_{x}-2b_{x}+c_{x}\right)\left(a_{x}-g_{x}\right)}}{2\left(a_{x}-2b_{x}+c_{x}\right)} $$

Wolfram Alpha is ignoring it though:

enter image description here

How can I convert latex in general into a representation of an expression that wolframalpha will accept?

1

There are 1 best solutions below

0
On BEST ANSWER

Here are some functions I use to convert $\LaTeX$ expressions to regular math expressions and vice versa:

from sympy import latex
from sympy import sympify
from sympy.parsing.latex import parse_latex
from pyperclip import copy

def LatexToMath(expr):
    # Input a string written in latex format. Have the math format copied to clipboard
    return copy(str(parse_latex(expr)))
def MathToLatex(expr):
    # Input a string written in regular math format. Have the corresponding latex format copied to clipboard
    return copy(latex(sympify(expr, evaluate=False)))