oolatex and tex4ht

Installing tex4ht under cygwin?

I came across the famous tex4ht, a highly configurable TeX/LateX to other format converter and tried to install itunder cygwin on my laptop. Well, it went fine up to a certain point and this blog are notes of the steps to follow (and some corrections / additions to the default package probably valid for any installation).

I have inspired myself of the initial installation instructions from Richard Hollos and Stefan Hollos indicating on how to install tex4ht on SuSE and have re-used most of their text below. The instructions from Eitan Gurari could be found here.

The details described below, are only of value if you want to install tex4ht on specific Unix versions having similar infrastructure (SuSE seem to qualify, cygwin as well to some extent).

Download and unpack

To start, downloaded the 2.8 MB file tex4ht.zip from the tex4ht setup for unix environments page, (direct link is here) and:

% mkdir -p /usr/local/src/tex4ht
% mv tex4ht.zip /usr/local/src/tex4ht
% cd /usr/local/src/tex4ht
% unzip tex4ht.zip
% mkdir tmp

The basic directory structure is in place.


Assuming you are still in /usr/local/src/tex4ht

% cp src/*.c  temp/
% cd temp/

You have copied the sources into temp and ready to copile. Note that the compilation requires an in-situ compile-time file location which will be loaded at run-time so, if you ever change the directory structure, you will need to rec-compile once again using the proper path.

% gcc -o tex4ht tex4ht.c -DENVFILE='"/usr/local/src/tex4ht/texmf/tex4ht/base/unix/tex4ht.env"' -DHAVE_DIRENT_H
% gcc -o t4ht t4ht.c -DENVFILE='"/usr/local/src/tex4ht/texmf/tex4ht/base/unix/tex4ht.env"'

Note there are double quotes and single quotes on the command lines above. If you copy and paste this command from the web into your console, you may get complaints from gcc like "error: stray \342 in program". In that case, just type it. The compilation above may produce lsome warnings but no errors, which is OK as long as an executable is produced. At the end, you should have two executables. Under cygwin, executables are post-fixed with .exe extension (this will not happen under standard Linux versions).

You need to add those executables to the global unix based executable directory. The below should take care of moving whatever executable you may have generated.

% test -e tex4ht     && mv tex4ht     /usr/local/src/tex4ht/bin/unix/
% test -e tex4ht.exe && mv tex4ht.exe /usr/local/src/tex4ht/bin/unix/

% test -e t4ht       && mv t4ht       /usr/local/src/tex4ht/bin/unix/
% test -e t4ht.exe   && mv t4ht.exe   /usr/local/src/tex4ht/bin/unix/

Configure env file

The core of the configuration for h4ht is in the file located at /usr/local/src/tex4ht/texmf/tex4ht/base/unix/tex4ht.env.

Using your preferred editor (with global replace capabilities), open this file. One of 

% emacs /usr/local/src/tex4ht/texmf/tex4ht/base/unix/tex4ht.env
% gvim /usr/local/src/tex4ht/texmf/tex4ht/base/unix/tex4ht.env
% jed /usr/local/src/tex4ht/texmf/tex4ht/base/unix/tex4ht.env

will do. Replace the line that starts with "t":


with the following line:


On the next line, add the following line:


This specifies the two locations where the tfm fonts are found on Cygwin or SuSE Linux.
ATTENTION: the "!" at the end, says to search subdirectories and should be present.


Global replace the string ~/tex4ht.dir with the string /usr/local/src/tex4ht which occurred on every line that started with an i.For example, the line in tex4ht.env which starts with:


was changed to:


This specifies where the bookkeeping file is kept. I also verified that users have write privileges in that directory.

If you do not want to use an editor, you may also use sed to globally replace the string occurances. In such case, use the following (% indciates a new command, copy all lines until a new % on the same Unix command line even if the Web document shows multiple lines):

% cp /usr/local/src/tex4ht/texmf/tex4ht/base/unix/tex4ht.env 
% sed 's/~\/tex4ht.dir/\/usr\/local\/src\/tex4ht/' 

Sub-sequent changes of the configuratio file should be done on the .env now and not on the .init (it was only to keep an original copy of the configuration file).

Most versions of tex4ht have a bug in the directory creation so you ALSO need to globally replace all mkdir commands with mkdir -p commands. You could use your editor to do so and if you chose to use sed again:

% cp /usr/local/src/tex4ht/texmf/tex4ht/base/unix/tex4ht.env  
% sed 's/mkdir sxw/mkdir -p sxw/'  /usr/local/src/tex4ht/texmf/tex4ht/base/unix/tex4ht.env.tmp  

You are not done yet.

Cygwin: on cygwin, the java commands will execute the Windows installed java version which will not understand path in relative path syntax. The commands will hence need to be modified. I have cygwin installed on the F: drive and hence, I executed the following sequence:

% cp /usr/local/src/tex4ht/texmf/tex4ht/base/unix/tex4ht.env  
% sed 's/%%~\/texmf-dist\//f:\/cygwin\/usr\/local\/src\/tex4ht\/texmf\//g' 

In other words, I have replaced all


you can make this replacement in your text editor as well.

Modify the binary scripts

In the directory /usr/local/src/tex4ht/bin/unix  which contains about a hundred different scripts, I replaced every occurrence of the string

with the string

by running the following command:

% cd /usr/local/src/tex4ht/bin/unix % perl -p -i -e 's/~\/tex4ht\.dir/\/usr\/local\/src\/tex4ht/' *

Notice the "/" and "." characters are escaped with a "\" character. The general form of such global replace using perl is perl -p -i -e 's/stringtoreplace/newstring/' *  and this could be used for massive string replacement. Note that this command will also create backup files post-fixed with the extension .bak . To avoid namespace polution (the bin/ directory will be added to your unix $PATH), move them to the tmp/ directory.

% cd /usr/local/src/tex4ht/bin/unix
% mv -f *.bak /usr/local/src/tex4ht/tmp 

Install necessary etc/ files

For SuSE, this will be done by editing the /etc/profile.local file. Under Cygwin and most version of Linux, you may add a /etc/profile.d/tex4ht.sh setup file and this will be automatically executed upon new logons. The following lines need to be added to either:

export PATH=${PATH}:/usr/local/src/tex4ht/bin/unix
export TEXINPUTS=".:/usr/local/src/tex4ht/texmf/tex/generic/tex4ht:"

The first adds the path for the executable and the second adds the necessary style files to TEX.

Under cygwin, you are likely a priviledged user. Under SuSe, now switch to the root account and run the command:

% texhash

which tells latex about the new software. Now, revert to a normal user account.

Further logins will be defined properly but the current shell has not loaded yet the definitions. Do this by typing either

% source /etc/profile
% source /etc/profile.d/tex4ht.sh

to read the changes to either profile.local or load what you just defined in profile.d/tex4ht.sh .

Test the installation

Copied the example files to a new directory and try them out. Here is the sequence:

% cd
% mkdir test
% cp /usr/local/src/tex4ht/temp/testa.tex .
% cp /usr/local/src/tex4ht/temp/testb.tex .

Now test using the htlatex command

% ht latex testa.tex
% htlatex testb.tex

The examples should run with no problems.

Testing oolatex follows a similar testing:

% oolatex testa.tex
% oolatex testb.tex

If all is well, this should succeed as well althogh the package is not well maintained and it may be that the generation fails. In such case, and if you still need a OO format, I would recommend

  • use htlatex generating a single html
  • open the html using sweb (OpenOffice Web editor)
  • save in OPenOffice text document and start changing