4
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ Try HoldForm: TeXForm[HoldForm[1 + x]] $\endgroup$ – Jonathan Shock May 1 '13 at 2:30
  • $\begingroup$ 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))] $\endgroup$ – Rene Duchamp May 1 '13 at 2:41
  • $\begingroup$ 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]) $\endgroup$ – Rene Duchamp May 1 '13 at 2:42
  • $\begingroup$ Try this link. $\endgroup$ – Rod May 1 '13 at 3:16
  • $\begingroup$ Please edit your question to include an example of the expressions you are working with, including the transformed output. $\endgroup$ – m_goldberg May 1 '13 at 3:21
6
$\begingroup$

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)} *)
$\endgroup$
  • $\begingroup$ Can you explain why Subscript[E,0] gave an TeXForm of \frac{e_0} ?? Why the change from Caps to Small. Just curious ... $\endgroup$ – Rene Duchamp May 2 '13 at 2:10
  • $\begingroup$ @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 $\endgroup$ – Rojo May 2 '13 at 11:36
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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` $\endgroup$ – Jonathan Shock May 1 '13 at 4:00
  • $\begingroup$ @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. $\endgroup$ – Jens May 1 '13 at 4:04
  • $\begingroup$ I don't think it's phrased incorrectly. He may be copying as LaTeX straight from his input $\endgroup$ – Rojo May 1 '13 at 4:14
  • $\begingroup$ @Rojo Ah, that could be. I'll wait for clarification. $\endgroup$ – Jens May 1 '13 at 4:29
  • $\begingroup$ @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. $\endgroup$ – Rene Duchamp May 2 '13 at 1:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.