Re: TeXForm
- To: mathgroup at smc.vnet.net
- Subject: [mg132020] Re: TeXForm
- From: Roland Franzius <roland.franzius at uos.de>
- Date: Sun, 17 Nov 2013 18:22:35 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <l6528j$5c3$1@smc.vnet.net>
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 @@
Collect[
Expand@{Numerator[#], Denominator[#]} &[
((-1 + n + \[Phi] - n \[Phi]) a + (1 + (-1 + n) \[Phi]) b)/
((-1 + n + \[Phi]) a + b - \[Phi] b)],
\[Phi]]
(-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
Export[$UserDocumentDirectory<>"\\test.tex",TexForm[expr],"LaTeX"]
%% AMS-LaTeX Created by Wolfram Mathematica 9.0 : www.wolfram.com
\documentclass{article}
\usepackage{amsmath, amssymb, graphics, setspace}
\newcommand{\mathsym}[1]{{}}
\newcommand{\unicode}[1]{{}}
\newcounter{mathematicapage}
\begin{document}
\[\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$\}$}\]
\end{document}
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
TeX-texts.
--
Roland Franzius