# How to type a capital 'E' in Mathematica 9 using 'ToExpression' and 'TeXForm'? [duplicate]

I am trying to use Mathematica's ToExpression[] combined with TexForm to type the Einstein's famous result: E = mc^2. Now this is dead easy in LaTeX, the code is:

E = m c^2

and it should generate something like:

However, when I try to generate this in Mathematica using the following syntax:

ToExpression["E = m c^2 ", TeXForm]

Irritatingly:

1. 'E' is converted to the bold-faced natural exponential;
2. The order of the variables is changed in the output.

Does anyone know how to fix these two problems?

• The general topic of your question is addressed in this other question: Unable to convert TeX input into mathematica. The specific case of the letter E is addressed in ogerard's answer. – Jens May 19 '13 at 20:27
• In addition to the above link, I just remembered an extended version of the same answer that I posted later. – Jens May 19 '13 at 20:40
• As to the reversed order: use the third argument to TexForm as I mention in the second link above: ToExpression["U = mc^2", TeXForm, HoldForm]. I used a letter U that doesn't have a built-in meaning. – Jens May 19 '13 at 20:56

The variable name E isn't available in Mathematica because it's a built-in symbol, but you can define a new name for the energy and use Format to make it display as E. The compromise is that you then have to enter the $\LaTeX$ code using the new name - here I call it energy:

Format[energy, StandardForm] := "E"

ToExpression["energy = m c^2", TeXForm, HoldForm]

$\text{E} = \text{m} \text{c}^2$

Edit: In the $\LaTeX$ code, you can enter energy without wrapping it in \\text{} because Mathematica interpets it as a single word by default. I initially put in a wrapper \\text{energy} because that's how one defines a multi-letter word in $\LaTeX$ equations. This is a confusing discrepancy between $\LaTeX$ and Mathematica that works to our advantage here because it allows lazier $\LaTeX$ input.

If your ultimate goal is to display the formulas as TraditionalForm (e.g., as labels in Graphics), then change the last argument in Format from StandardForm to TraditionalForm.

• Many thanks @Jens, this is good enough for what I want to achieve! Also appreciate the little 'bonus track' on the amenities of TranditionalForm over StandardForm. – Calleniah May 20 '13 at 11:46
• Thanks - I was actually wrong about requiring \text{} wrappers. It works without that, so it's a little simpler than I wrote at first. – Jens May 21 '13 at 5:31

The reason of your troubles is the fact that E is not available as a variable in Mathematica but is assigned for the exp(1). A similar problem occurs when trying to use D (differential operator), I (imaginary unit), N (numerical evaluation), Pi (famous constant) as variables. This can often be frustrating, especially when using Mathematica for basic physics. Others here may have suggestions as how to accomodate this design decision. Here are my 2 cents.

ToExpression[" stuff ", TeXForm]

is used to produce a Mathematica expression from a TeX expression. E is automatically converted to the e constant (although E is a Mathematica convention, not a TeX one) and displayed accordingly.

ToExpression["Energy = m c^2", TeXForm]

should work as expected, but I do not know an efficient way to have a variable which looks correctly like a capital E without resorting to special characters. And in this case there is no much point to using ToExpression to convert it from TeXForm.

You can enter a special E, usable as a variable if you type ( is the Escape key at the upper left of your keyboard):

<esc>E<esc> == m c^2

for instance (after typing the second esc, you will see a capital E, slightly less bold than the normal font) or

<esc>E<esc> = 10

to assign an immediate value.

Then each time you will enter E in an equation it will be treated as a variable or as its value if you give it one.