# Override Equation structure change in mathematica - CopyToLaTeX

I am writing my thesis, and when I do copy to LaTeX from Mathematica, it changes the equation variables and also it rearranges the structure of the original equation.

How can I override that ??

New information and further reading : http://pages.uoregon.edu/noeckel/computernotes/Mathematica/EquationEditing.html

Its really annoying especially when I have to get the exact same form.

EXAMPLE:

# 1: Mathematica code:

TeXForm[HoldForm[E^(-I k( (\[Xi]/Subscript[z, 1]+u/Subscript[z, 2]) x+ (\[Eta]/Subscript[z, 1]+v/Subscript[z, 2]) y))]]


# 2: How it looks in Mathematica: # 3 Mathematica Output:

\exp \left(-i
k\left(\left(\frac{\xi
}{z_1}+\frac{u}{z_2}\right)
x+\left(\frac{\eta
}{z_1}+\frac{v}{z_2}\right)
y\right)\right)


# 4 Copy paste #3 into LaTeX, the result: Thanks

• Try HoldForm: TeXForm[HoldForm[1 + x]] – Jonathan Shock May 1 '13 at 2:30
• Dint work , Could you please try on your mathematica : HoldForm[U[x, y] = Subscript[E, 0]/(4 \[Pi]) E^(I k Subscript[z, 1])/Subscript[z, 1] E^(I k/(2 Subscript[z, 1]) ((\[Xi] - x)^2 + (\[Eta] - y)^2))] – Rene Duchamp May 1 '13 at 2:41
• HoldForm on the equation I wanted itself gave me rearraged one: U[x, y] = ( Subscript[E, 0] E^(I k Subscript[z, 1]) E^(( I k ((\[Xi] - x)^2 + (\[Eta] - y)^2))/( 2 Subscript[z, 1])))/((4 \[Pi]) Subscript[z, 1]) – Rene Duchamp May 1 '13 at 2:42
• Try this link. – Rod May 1 '13 at 3:16
• Please edit your question to include an example of the expressions you are working with, including the transformed output. – m_goldberg May 1 '13 at 3:21

## 2 Answers

Perhaps something like this could help?

SetAttributes[copyAsLatex, HoldFirst];
copyAsLatex[sth_] := CopyToClipboard[ToString[HoldForm[sth] /.
x_ /y_ :> Divide[x, y], TeXForm]]


So

copyAsLatex[
U[x, y] =
Subscript[E, 0]/(4 \[Pi]) E^(I k Subscript[z, 1])/
Subscript[z,
1] E^(I k/(2 Subscript[z, 1]) ((\[Xi] - x)^2 + (\[Eta] - y)^2))]


copies the following to the clipboard

(* U(x,y)=\frac{e_0}{4 \pi } \frac{e^{i k z_1}}{z_1} e^{i \frac{k}{2 z_1} \left((\xi -x)^2+(\eta -y)^2\right)} *)

• Can you explain why Subscript[E,0] gave an TeXForm of \frac{e_0} ?? Why the change from Caps to Small. Just curious ... – Rene Duchamp May 2 '13 at 2:10
• @abhilashsukumari E has the built in meaning of "euler's number", the base of the natural log. In standard math that's written in lowercase – Rojo May 2 '13 at 11:36

If you want the exact same formatting as in the StandardForm output of your Mathematica session, then you could do the following:

U[x, y] = (Subscript[E,
0] E^(I k Subscript[z,
1]) E^((I k ((\[Xi] - x)^2 + (\[Eta] - y)^2))/(2 Subscript[z,
1])))/((4 Pi) Subscript[z, 1]);

TeXForm[StandardForm[U[x, y]]]


\frac{\exp \left(\frac{i k \left((-y+\eta )^2+(-x+\xi )^2\right)}{2 z_1}+i k z_1\right) e_0}{4 \pi z_1}

Here, I added StandardForm because usually TeXForm goes via a conversion to TraditionalForm which re-arranges some terms, for example the -y + η.

This is described under "Generalizations and Extensions" in the help page for TeXForm.

• If I understand correctly @abhilash sukumari wants the answer to include multiple \frac{}{} elements multiplied together, not everything collected into a single \frac{} as happens in this example. ie. something that has a/b c/d as is the form of the input – Jonathan Shock May 1 '13 at 4:00
• @JonathanShock I understood it differently. The question is explicitly about TeXForm rearranging things. What you mention already happens in StandardForm`. If you're right, the question is phrased incorrectly. – Jens May 1 '13 at 4:04
• I don't think it's phrased incorrectly. He may be copying as LaTeX straight from his input – Rojo May 1 '13 at 4:14
• @Rojo Ah, that could be. I'll wait for clarification. – Jens May 1 '13 at 4:29
• @Rojo : Yes, I am trying to get multiple fraction terms instead of self-arranging to compact single fraction. I shall edit the question with a simple Equation that has very different looks in standard and TeXForm. – Rene Duchamp May 2 '13 at 1:45