TransWikia.com

Pasting $LaTeX$ into a Mathematica notebook

Mathematica Asked on April 3, 2021

I have read that $LaTeX$ source can be directly pasted into a Mathematica notebook. However, I have been unsuccessful in this regard. An example of the errors received are:

$frac{1}{2}$
Syntax::sntxb: Expression cannot begin with "$ frac{1}{2}$".
Syntax::tsntxi: "$ frac" is incomplete; more input is needed.
Syntax::sntxi: Incomplete expression; more input is needed .

This is not remediated by removal of the $ signs, placement of two $ signs ($$), or use of other $LaTeX$ math mode delimiters (e.g., [ ], begin{displaymath}end{displaymath}, begin{equation}end{equation}, etc). I do not wish to import an entire .tex file as I merely want to pass a few select equations. Please advise as to my error. Thank you.

Edit: I am using Mathematica 8.0.1.0.

3 Answers

I'm prompted by Mathematica when pasting (using 8.0.4) so I don't have this issue. The following seems to do the trick though..

ToExpression["frac{1}{2}", TeXForm]

I would expect others might have more illuminating responses to this.

EDIT:

The prompt I referred to is controlled via GlobalOptions > MessageOptions > TeXPasteWarning in the Options Inspector which can be found under Edit > Preferences > Advanced. If this is set to False you won't get prompted as to how you would like to paste the input.

Correct answer by Andy Ross on April 3, 2021

I find pasting $frac{1}{2}$ works but pasting frac{1}{2} does not. So the dollar signs seems necessary, although I realize that doesn't fix your problem it may be a useful hint to other users.

Answered by Virgo on April 3, 2021

Let's assume I have the following $LaTeX$ expression that I want to include in a Mathematica notebook

$frac{d P(r)}{d r}=-frac{G M rho}{r^2}$

If I copy the expression, including the $...$ (which are essential for Mathematica to recognize $LaTeX$) and paste it in a Mathematica notebook, the following dialog box appears

enter image description here

And after clicking the button "yes", the following expression appears in the notebook (using Mathematica 12.1), as described in the documentation

enter image description here

The related issue of converting $LaTeX$ into Mathematica input form is discussed in this answer.


EDIT for Mathematica 12.2

Mathematica 12.2 in December 2020 introduced a new menu "Inline TeX Input" to write $TeX$ or $LaTeX$ input directly. Selecting the option from the Insert menu (or typing Ctrl+4)

enter image description here

Produces the following box, where one can type $LaTeX$ directly

enter image description here

Clicking away from the box converts the $LaTeX$ into Mathematica input

enter image description here

Answered by divenex on April 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP