4

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:

1

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:

output on PDF Thanks

Rene Duchamp
  • 1,419
  • 10
  • 20

2 Answers2

6

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)} *)
Rojo
  • 42,601
  • 7
  • 96
  • 188
  • 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 02 '13 at 02: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 02 '13 at 11:36
1

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Jens
  • 97,245
  • 7
  • 213
  • 499
  • 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 01 '13 at 04: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 01 '13 at 04:04
  • I don't think it's phrased incorrectly. He may be copying as LaTeX straight from his input – Rojo May 01 '13 at 04:14
  • @Rojo Ah, that could be. I'll wait for clarification. – Jens May 01 '13 at 04: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 02 '13 at 01:45
  • @Rojo: Yes I was copying straight from my input, what would be the correct way to copy to LaTeX directly then ? – Rene Duchamp May 02 '13 at 02:21
  • @abhilashsukumari I think what you are doing is just fine – Rojo May 02 '13 at 11:42