1
$\begingroup$

I'm trying to parse a LaTeX representation of a Desmos calculator (like this one) via Mathematica.

Desmos exposes a JSON representation of its calculators, including a LaTeX representation of mathematical expressions.

I'm capturing and parsing the JSON via:

request = 
 HTTPRequest[
  "https://www.desmos.com/calculator/liypnrwjke", <|"Headers" -> {
     "Accept" -> "application/json"}|>]
response = 
  ImportString[URLRead[request, {"Body"}]["Body"], "RawJSON"];

I'm then extracting a particular LaTeX representation from the JSON, e.g.

testLatex = response["state"]["expressions"]["list"][[2]]["latex"];

And then trying to interpret this as an expression, as in,

ToExpression[testLatex, TeXForm]

Unfortunately, there doesn't seem to be a semantic way to distinguish a function call from multiplication from just the LaTeX, so when presented with "f\\left(x\\right)=m\\left(x-a\\right)+b", Mathematica yields f[x] == b + m[-a + x]

How might I avoid this to instead get f[x]==b+m(x-a)? Perhaps using the presence of x in f[x] to identify the parameters?

Thanks in advance!

$\endgroup$
  • 2
    $\begingroup$ Mathematica's LaTeX parser is not customizable, so your options are: 1. write your own parser 2. somehow post-process Mathematica interpretation and "fix" it. As you noticed, LaTeX is for typesetting, not for accurately representing mathematics. If at all possible, avoid trying to use it to represent mathematics—it simply can't do that. $\endgroup$ – Szabolcs Oct 28 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.