up
PDF letter size
PDF legal size

## Detailed description of my tex4ht setup

July 1, 2016 compiled on — Friday July 01, 2016 at 01:49 AM

### 1 Method that uses SVG for images and does not require eps to obtain image size

The general parts of the setup are illustrated in the following diagram, then a detailed description is given for each part

The above diagram shows the main files used. There are basically two important files: The file my.cfg and main.mk4. Since make4ht is used to build latex to html, the original tex4ht file tex4ht.env is no longer used. This is a good thing, as tex4ht.env is very hard to manage.

The file my.cfg in the diagram above is the configuration file for tex4ht. The file main.mk4 is used to customize the make4ht build process.

The setup described here uses .svg for both math and external images included using includegraphics when building the html pages, and uses .pdf for external images included using includegraphics when building to pdf file with pdflatex of lualatex.

Hence an initial step is to crop and then convert each pdf image file to svg file. This is done for each image file that is to be included using includegraphics

A small script is used to do this conversion. Here is the script called prep. This scipt will crop the pdf file (remove white spaces around the image) and then convert it to svg

I also use scour which is a python script to reduce the size of the svg images. Which does a very good image in reducing the size of SVG file. This is not needed, but if you need to use it, this is how the extended prep script above would be now

I had to make a temporary file x000.svg in the above, since scour does not allow one to overwrite the same file. To use scour, these are the commands to install it on Linux

Script prep is used as follows. To convert one pdf image file say image.pdf to image.svg", the command is

To convert all pdf image files in one folder to svg image files

After this prepration step, the latex file is compiled to html using the command

make4ht contains documentation on all the options it supports in addition to the ones shown above. For example to send all the output which includes the html file generated and all the images to a separate folder, the following command is used

A template latex file is given below. The \includegraphics command below does not include the image file extension. This is taken care of by the use of the configuration file described below. When compiling using pdflatex the pdf image file is read and when compiling using tex4ht, the svg file is read automatically.

The \includegraphics command must use a size specification in this setup, such as width=.8\textwidth or width=.8\linewidth or another exact value. It can not be without some size specification such as using scale or just \includegraphics[]{image1} as this will not work.

This is to remove the need to generate .xbb file for each svg. The setup here uses the width=scale\textwidth for all images.

#### 1.1 Template tex4ht configuration file

The tex4ht configuration file my.cfg is described below. This file tells texh4t to use SVG instead of png for images, as svg is vector graphics and it scales better at different resolution. This file can also be used to customize the HTML output more by adding direct CSS command in the section starting after \begin{document} in this configuration file. There is a \begin{document} in the configuration file, which is not to be confused with the \begin{document} in the latex file itself. There are not the same.

Here is the template for the file my.cfg used in the above command. (Thanks to Post by Michal Hoftich on Tex stackexchange

#### 1.2 Description of make4ht configuration file main.mk4

The above section described one of the main files used which was my.cfg. This section describes the other main file main.mk4 which is used to customize the make4ht build. Below is the listing of the current main.mk4 used in this setup.

This file comes with the make4ht installation. The first line was modified to make the math little larger. The command

Tells dvisvgm to make the math equations 1.15 larger than the default. This value can be adjusted as needed by editing this file.

The above file is located in the $HOME folder, as well as the file my.cfg. These files are kept in$HOME to make it easier to locate by make4ht. But these can also be in the same folder where the latex file is located.

#### 1.3 Post TexLive configuration

As of Texlive 2015, make4ht is now part of TexLive. There is nothing to do to install it.

The following are the relevant environment variables from the .bashrc file used in this setup. Change path to your texlive as needed.

And of course texlive itself has to be installed.

#### 1.4 Using makefile to build latex to HTML and PDF

The setup uses Make to build all latex files. It uses a recursive make that builds the whole tree. But here a small example of Make is given which builds only one directory.

It builds both pdf and HTML from the latex and converts all the pdf image files to svg if needed automatically. This means when the pdf image file is changed (may be due to updating the drawing itself, or running tikz again to generate new pdf image file), then the images that have changed are automatically converted to svg when running make and the pdf and HTML are build. This way the result always contains the correct latest images.

This is illustrated below using a template layout, which consists of one folder that contains the latex file, and a subfolder which contains all the images that are used by the latex file. In this example there are 2 image files. The images are kept in separate folder to make it easier to manage.

The output of the HTML is send to separate folder. Therefore the structure before the make is run is as follows:

source/
|-- images
|   |-- d1.pdf
|   |-- d2.pdf
|
|-- index.tex
|-- main.mk4
|-- Makefile
|-- my.cfg

After running make, the structure becomes like this

source/
|-- images
|   |-- d1.pdf
|   |-- d1.svg
|   |-- d2.pdf
|   |-- d2.svg
|
|-- index.pdf
|-- index.tex
|-- main.mk4
|-- Makefile
|-- my.cfg
|-- output
|-- images
|   |-- d1.svg
|   |-- d2.svg
|
|-- index.css
|-- index.htm

Notice that in the output, all the .svg images are copied over as well as the HTML file to the output directory.

The example latex file is.

The makefile is

From the source folder, issuing the following commands will build the index.tex file

The script prep used in the makefile is shown earlier above.