MathGroup Archive 2008

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

Search the Archive

Re: LaTex to Mathematica


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


  • Prev by Date: Re: Multifile search
  • Next by Date: Re: Re: Multifile search
  • Previous by thread: Re: Re: LaTex to Mathematica
  • Next by thread: Re: LaTex to Mathematica