33

How to convert the $\LaTeX$ format to Mathematica input?

For example, if I have a formula:

$$ \sum_{m_{i}=0}^M\sum_{n_{j}=0}^N \frac{(z_{i}/2)^{m_{i}}(z_{j}/2)^{n_{j}}}{m!n!} $$

in terms of $\LaTeX$ format:

  \sum_{m_{i}=0}^M\sum_{n_{j}=0}^N \frac{(z_{i}/2)^{m_{i}}(z_{j}/2)^{n_{j}}}{m!n!}

How would we convert it to Mathematica input?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
wonderich
  • 923
  • 1
  • 8
  • 14
  • 2
    We have the MaTeX package that goes from Mathematica to LateX. Maybe you can make a package to go the other way, and call it TeXmA. – QuantumDot Dec 06 '16 at 01:14
  • 2
    Duplicates? http://mathematica.stackexchange.com/questions/95435/toexpression-not-accepting-standard-tex-strings, http://mathematica.stackexchange.com/questions/2794/unable-to-convert-tex-input-into-mathematica, http://mathematica.stackexchange.com/questions/76069/problem-with-converting-frac-into-mathematica-output, http://mathematica.stackexchange.com/questions/15884/how-to-use-latex-for-typesetting-labels-and-titles-in-mathematica – Simon Rochester Dec 08 '16 at 02:35

1 Answers1

51

You can use ToExpression.

ToExpression["string", TeXForm, HoldForm]

Paste your content inside quotes and click the button "yes", when the following dialog box opens, in order to escape backslashes and use them verbatim

enter image description here

In your example, Mathematica 12.1 produces the following output

enter image description here

divenex
  • 616
  • 5
  • 12
materia-nigra
  • 800
  • 6
  • 6
  • 1
    It works, but strangely \sum becomes \sum when I past into the "string"...? – wonderich Dec 06 '16 at 02:44
  • 5
    That's because the backslah of the TeX expression is not intended to be interpreted as Mathematica code, so it must be "escaped". The way to do this is to precede it by another backslash. Mathematica is aware of this and offers this transformation when you paste the string. – materia-nigra Dec 06 '16 at 02:49