Tex conversions

This page is a bit of a crib sheet. I've had to do a silly conversion from Latex to Word for a journal, and had lots of trouble, so here is what I found. If anybody has more experience with these, please tell me and I'll add some info. The best option so far is TeX4ht, which translates to html with gifs which OpenOffice (but not Word) reads.

Macros

In my experience, macros such as \renewcommand{a}{b} tend to break all of the packages listed below (although TtM seems to have given it more thought than others). However, it's easy to use sed, or emacs or so to substitute the macros. Personally, I use a header file, which is included at the beginning of the tex file using \input{texinput.tex} which uses lots of definitions. I then use sed, for example to backsubstitute all commands like \bfa with {\mathbf a} and \bfb with {\mathbf b} sed 's/\\bf\([a-zA-Z]\)/{\\mathbf \1}/g'

I only just discovered this way of referring to matched patterns with \( ...\) and \1 and find it very useful.

Latex to Word / RTF conversion

This option is unhappily of interest, as many journals now demand word files.
  • Scientific Word is a commercial package which is now on acorn. It manages most equations fine (it has minor trouble, eg gets double lines || wrong, and has problems with \mathcal). It manages the multiline equations fine (which latex2rtf messes up). Maneesh mentioned that some random equations were replaced by pictures, which didn't happen to me. It seems to get plain references such as \cite right, but fails to understand \citep or \citet. I had eliminated all macros from my tex file.
  • latex2rtf does not go directly to Word, but Word can read rtf. It has lots of bugs, in fact on the webpage, it says something like: "don't expect it to work at all". It converts all the text all right, and converts many of the inline equations. It doesn't understand \graphicspath{...}, so if you use that, you can do something like the following to move them all to one directory, at which point it gets some of them: mkdir figs
    grep '\\includegraphics' paper.tex | sed 's/.*{\(.*\)}.*/\1/g' | sed 's/}//g' | cat > figs/figindex
    for a in `less figs/figindex`; do
       cp graphicspath/$a figs/. ;
    done
  • tex2word runs under Windows only, and has a 30 days evaluation license. The nice thing is that it converts all the equations to MathType (4 or later). Unhappily, with our Office 2003 installation, this only works randomly with very simple files and mostly crashes. I haven't tried it for older versions of Word.

Latex to HTML conversion

The hope was that some latex to html conversion might produce code that can then be loaded into Word. I haven't found this to work straightforwardly.
  • TeX4ht produces by far the best output for me. It correctly converted all equations either into text for the simples ones, or into gifs. Unlike latex2html, these were without any funny gray backgrounds, but unhappily were cropped to tightly many times, and also produces a set of gifs from the figures (and correctly interpreted the \psfrag{} replacements), albeit of rather random size. Unhappily these figures are not clickable links to higher-resolution verions.
    Openoffice can read the html produced and displays everything nicely -- unhappily Word doesn't, even after loading into OpenOffice and exporting to doc or rtf. This seems to be a problem with the gifs produced, which gimp and gqview, like Word, are not happy with. So unhappily this doesn't really seem to be a solution. TeX4ht also is quite configurable, for example you could try (not that on our system you have to add .sh): htlatex.sh file.tex "xhtml,soffice" or the following, which is supposed to give outputs geared towards word: htlatex.sh file.tex "html,word" "/symbol/" both of which give sensible output in konqueror and OpenOffice, but again not in firefox or Word. This is supposed to generate output more geared towards mozzila browsers: htlatex.sh file.tex "xhtml,mozilla" " -cmozhtf" which produces mostly mathml equations, but again the gifs are messed up. Konqueror won't display any of this, Word complains about a missing file etc...
  • Latex2HTML will produce lots of pngs, one for each equation (this includes the inline equations). This didn't work perfectly for me. It didn't manage the figures, and a random set of equations were on gray background.
  • TtM converts tex to MathML. Unlike latex2html, this is then true markup language, without any bitmaps for the equations. Now the rendering depends on the browser, which may or may not be a good thing. Firefox 1.5 has native support for MathML. My installation of firefox doesn't seem to want to use the truetype fonts required. More importantly, Word can't make sense of it either.
  • If you really are after producing maths for the web, then itex2mml might be of interest to you. This is a version of tex which is made to be converted to MathML. However, the itex2mml converter does not convert latex to html.

Latex equation editor in OpenOffice

OOolatex is a macro for OpenOffice, which provides a way of adding latex equations to openoffice files -- as pngs. It's a bit like the Word equation editor, just that you get to type in latex code. It simply runs latex on whatever equation you provide and then uses ImageMagick convert to convert it to a png file. They provide a standalone script that does this too. It's not practicable at all to do on any sensible-size file.

Word to Latex conversion

Not of much interest at the moment, however, there is word2tex, which does a 30 day free evaluation license.