Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #16232 > unrolled thread

TeXForm

Started byThemis Matsoukas <tmatsoukas@me.com>
First post2013-11-15 11:58 +0000
Last post2013-11-17 09:24 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  TeXForm Themis Matsoukas <tmatsoukas@me.com> - 2013-11-15 11:58 +0000
    Re: TeXForm Roland Franzius <roland.franzius@uos.de> - 2013-11-17 09:24 +0000

#16232 — TeXForm

FromThemis Matsoukas <tmatsoukas@me.com>
Date2013-11-15 11:58 +0000
SubjectTeXForm
Message-ID<l6528j$5c3$1@smc.vnet.net>
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?

Thanks.

[toc] | [next] | [standalone]


#16244

FromRoland Franzius <roland.franzius@uos.de>
Date2013-11-17 09:24 +0000
Message-ID<l6a203$hd4$1@smc.vnet.net>
In reply to#16232
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web