Re: LaTex to Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg91466] Re: LaTex to Mathematica
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Fri, 22 Aug 2008 03:15:12 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <g8gj47$etf$1@smc.vnet.net> <200808201023.GAA18906@smc.vnet.net> <g8j88u$74i$1@smc.vnet.net>
Murray Eisenberg wrote: > I tried something similar, but using ToExpression[...,"TeXForm"], > likewise removing the trailing "\\" from the original. > > (I was surprised that Mathematica just ignored the "&", which is > evidently in the original expression because that expression is part of > a larger LaTeX construct such as a \begin{align}...\end{align). > > However, I was unable to see how to let Mathematica itself convert the > single backslashes, which of course are interpreted as escape symbols, > to the needed double-backslashes. The obvious thing, > > expr = "\ln{H}^{*} &= {X}_{1} {\beta}_{1} + {\alpha}_{1}lnE+ \ > {\varepsilon}_{1}"; > > expr/. "\"->"\\" > > does not work, of course. <snip> However, *StringReplace[expr, "\\" -> "\\\\"]* works. . Note, that expr needs some additional editing before being converted because "\b" is an ASCII escape sequence for "Bell" and it is converted -- more or less -- to its numeric value. Therefore "\beta" becomes "\.08eta" :) . Also, depending on your settings, Mathematica can automatically convert the escape character "\" into "\\" when pasting a string. In[2]:= expr = "\ln{H}^{*} &= {X}_{1} {\beta}_{1} + \ {\alpha}_{1}lnE+ {\varepsilon}_{1}" Out[2]= "\\ln{H}^{*} &= {X}_{1} {\.08eta}_{1} + {\\alpha}_{1}lnE+ {\ \\varepsilon}_{1}" . Finally, the string must start and end with a dollar sign "$" that denotes math mode in LaTeX. StringReplace[ "$" <> "ln{H}^{*} &= {X}_{1} {\\beta}_{1} + {\alpha}_{1}lnE+ \ {\varepsilon}_{1}\\" <> "$", "\\" -> "\\\\"] ToExpression[%, TeXForm] (Note that TeXForm is entered without double quotes.) Regards, -- Jean-Marc
- References:
- Re: LaTex to Mathematica
- From: Jens-Peer Kuska <kuska@informatik.uni-leipzig.de>
- Re: LaTex to Mathematica