30

I use LaTeX to type up my homework, but as I work I often need to pop things into Mathematica (or manually type them in, or manually use my TI-89, etc.).

Currently, I've been manually translating things like \frac{a}{b} into (a/b) for Mathematica's consumption... is there a tool out there which does this automagically?

3
  • 1
    I'm also interested in whether proposed solutions work for Wolfram Alpha.
    – Rebekah
    Commented Sep 21, 2010 at 22:00
  • Is there a similar capability for Maple? All I can find in the documentation is the reverse - LateX export.
    – rogerl
    Commented Nov 5, 2010 at 13:20
  • @rogerl: That deserves a separate question, I think. Commented Nov 5, 2010 at 14:32

1 Answer 1

34

Mathematica can do this itself: ToExpression["\\frac{a}{b}", TeXForm].

The mathematica frontend will automatically perform the necessary doubling of the backslashes so long as you are pasting into a string (ie, put the cursor between quotes "" before pasting)

You didn't ask, but you can also go the other way mathematica->Tex: TeXForm[a/b] gives \frac{a}{b}.

You can also use a mixture of TeX and mathematica in a file document.mtex and use the mathematica Splice["document.mtex"] command to replace <*, *> delimited mathematica input by TeXForm mathematica output. Eg:

The derivative of $x^x$ is $<*D[x^x,x]*>$.

Splices to:

The derivative of $x^x$ is $x^x (\log (x)+1)$.
3
  • Too bad it doesn't work with intergals. Thanks +1 and checkmark. Commented Sep 23, 2010 at 15:58
  • 3
    It does work with integrals; try 'ToExpression["\\int \\sin(\\sin(x)) \\, dx", TeXForm]'
    – alfC
    Commented Oct 6, 2011 at 7:34
  • Is there a way to do this by reading a text file containing the expression, rather than copy-pasting? Commented Mar 8, 2023 at 10:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .