MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: TeXForm

Am 15.11.2013 12:58, schrieb Themis Matsoukas:
> TeXForm seems to apply additional transformations to expressions
> before exporting into latex. Here is an example:
> ((-1 + n + \[Phi] - n \[Phi]) a + (1 + (-1 + n) \[Phi]) b)/((-1 + n +
> \[Phi]) a + b - \[Phi] b) // TeXForm
> \frac{a (n (-\phi )+n+\phi -1)+b ((n-1) \phi +1)}{a (n+\phi -1)+b
> (-\phi )+b}
> The exported expression has been manipulated by some unknown rules.
> The  (-\phi) in particular is especially annoying. Is there a way to
> export the expression in the form that pretty much matches the
> original expression?

The TeXForm is pretty clear, use FullForm. It does nothing. Its only the 
Output filter that translates to LaTeX. This works slightly different 
for screen or Export as TeX-file.

The same is true for import. The screen output converted to a string 
cannot be pasted as a TeX-expression in ToExpression.

Ordering before conversion can be accomplished by some tricks. Isolate 
numerator and denominator and order terms as a polynom in \[Phi] and put 
the fraction together again applying Divide

expr =
  Divide @@
    Expand@{Numerator[#], Denominator[#]} &[
    ((-1 + n + \[Phi] - n \[Phi]) a + (1 + (-1 + n) \[Phi]) b)/
     ((-1 + n + \[Phi]) a + b - \[Phi] b)],

    (-a + b + a n + (a - b - a n + b n) \[Phi])/(-a + b +
        a n + (a - b) \[Phi])

You can export it directly as a LaTeX document


%% AMS-LaTeX Created by Wolfram Mathematica 9.0 :

\usepackage{amsmath, amssymb, graphics, setspace}



\[\text{$\backslash \backslash $frac$\{\backslash \backslash $phi  (a 
(-n)+a+b n-b)+a n-a+b$\}\{\backslash \backslash $phi  (a-b)+a n-a+b$\}$}\]


Or replace the TeXForm  wrapper by String

str = ToString[TeXForm[ expr]]

  "\\frac{\\phi  (a (-n)+a+b n-b)+a n-a+b}{\\phi  (a-b)+a n-a+b}"

The main conversion problem is the total incompatiblity at the 
Mathematica level of the Mathematica string escape "\\" and the TeX 
escape "\", the different use of bracket types and the implicit 
multiplication with blanks " ".

But the cut and paste machine of Mathematica pretty good formates 


Roland Franzius

  • Prev by Date: Programming Fail
  • Next by Date: Animate cannot be combined?
  • Previous by thread: Re: TeXForm
  • Next by thread: Plot InverseSurvivalFunction