Chapter 4
TeX4ht cheat sheet

4.1 my tex4ht setup using SVG for math
4.2 Showing where files needed by make4ht and tex4ht are on my PC
4.3 my tex4ht setup using mathjax for math
4.4 tex4ht themes
4.5 How to make tex4ht and pdflatex work in the same file?
4.6 Adding tex4ht configuration inside latex file instead of using .cfg
4.7 removing the extra TOC on main page
4.8 Changing the depth of the main toc in HTML
4.9 making local TOC at some units but not in others
4.10 how to use tikz picture with math in htlatex?
4.11 how to change font for HTML math when using tex4ht
4.12 tex4ht options
4.13 How to use tex4ht with pdf and latex in same document?
4.14 my setup for using htlatex on linux, installing make4ht
4.15 how to insert HTML code inside the body of a latex document?
4.16 How to control page margins in html
4.17 tex4ht and table of content issues
4.18 How to change magnification factor when using dvisvgm with make4ht?
4.19 using multicol package in htlatex?
4.20 How to use images with htlatex and pdflatex
4.21 adding white space
4.22 Avoid vref
4.23 Where are the 4ht files located?
4.24 Where is tex4ht.env located ?
4.25 Patch for report style
4.26 Watch out for Verbatim frame not showing in Chrome
4.27 How to use tex4ht with SVG for math and images
4.28 converting cropped pdf page to svg
4.29 How to change image size of svg for html generation?
4.30 How to include animated gif file in the HTML?
4.31 How to build using make4ht
4.32 remember to set TEXINPUTS
4.33 To make .bbx files
4.34 How to used fixed width table?
4.35 tex4ht references

4.1 my tex4ht setup using SVG for math

description of my tex4ht setup

4.2 Showing where files needed by make4ht and tex4ht are on my PC

4.3 my tex4ht setup using mathjax for math

This is updated on January 16, 2019. Using latest texlive, now mathjax is integrated in tex4ht. So the way to use mathjax is as simple as this

make4ht foo.tex "htm,mathjax"
 

The above is minimal call. My actuall call is this

make4ht -ulm default -e ~/new.mk4 -c ~/nma_mathjax.cfg 
      foo.tex "htm,0,mathjax,notoc*,p-width,charset=utf-8" " -cunihtf -utf8"
 

Where 0 above is split level, which can be 1 or 2 or 3 and so on.

And nma_mathjax.cfg is

 
\Preamble{xhtml} 
 
%This trick below is to allow using \DeclareGraphicsExtensions 
%only when the graphics package is loaded. Thanks to Michal Hoftich for 
%this work around. Updated Oct 10, 2018. 
 
\makeatletter 
\@ifpackageloaded{graphicx}{% ONLY use if graphics package is loaded. 
  \DeclareGraphicsExtensions{.svg,.png} 
  \Configure{Picture}{.svg} 
    %this below to make it resize the SVG image, if it is there, to 
    %what is in the includegraphics. 
    %thanks to @Michael.h21 for this trick 
    \newcommand\emwidth{10} 
    % convert pt to rem 
    \newcommand\CalcRem[1]{\strip@pt\dimexpr(#1)/\emwidth} 
    \Configure{graphics*} 
           {svg} 
            {\Picture[pict]{\csname Gin@base\endcsname.svg 
            \space style="width:\CalcRem{\Gin@req@width}em;" 
            }% 
            \special{t4ht+@File: \csname Gin@base\endcsname.svg} 
    } 
} 
{} 
\makeatother 
 
\begin{document} 
\edef\mymathjaxconf{\detokenize{MathJax.Hub.Config({ 
        TeX: { 
  MAXBUFFER: 40*1024, 
  Macros : { 
relax: "{}", 
setlength: ["{}", 2], 
allowbreak: "{}", 
}}, 
});}} 
 
\ExplSyntaxOn 
\regex_replace_all:nnN{ \x{23}\x{23}}{\x{23}}{\mymathjaxconf} 
\ExplSyntaxOff 
 
\Configure{@HEAD}{\HCode{<script 
type="text/x-mathjax-config"> \mymathjaxconf</script>}} 
 
\EndPreamble
 

And the file new.mk4 is

if mode == "draft" then 
  Make:htlatex {} 
else 
  Make:htlatex {} 
  Make:htlatex {} 
  Make:htlatex {} 
end
 

Remember NOT to use pic-align option in the above. This causes problems with mathjax. Also notice the extra space in " -cunihtf -utf8"

4.4 tex4ht themes

Before starting, here are rules of thumb to remember. Most of these rules will cover most of the common uses.

  1. If using the report class and if splitting is set to 2, then each chapter (and anything in it, such as sections and subsections) all go to separate one web page).
  2. If using the report class and if splitting is set to 3, then each section (and anything in it, such as subsections) all go to separate one web page).
  3. If using report class, to Force a table of content to show under each chapter add this \TocAt{chapter,section} %show sections only in chapters TOC
  4. To Force a table of content to show under each section add this \TocAt{section,subsection} %show subsections only in sections TOC
  5. If using article class, then using split 2 then each section is put on its own page (including all its subsections).
  6. If using article class, then using split 3 will put each section on its page, and each subsection (and everything inside subsections) on its own page.

The general outlines of the themes below are needed if one wants to do something more complicated than the above rules of thumb.

These themes were done using the command

htlatex foo.tex "htm,3"
 

And then adding the control of where to split pages to separate HTML pages or not, and controlling where table of contents show up right inside the latex file. This is needed since there is no other way to control which sections or chapters to split or not to split using global method, and so the logic has to be embedded inside the latex file.

All logic for both pdf and htlatex is inside the same file and is controlled using \ifdefined\HCode to tell if one is running in pdf or htlatex, since only generation to HTML and PDF is done here.

4.4.1 theme 1

report class, main TOC shows only chapters. Chapter 2 has TOC and all its sections in one web page, but chapter 1 has TOC but its sections are each on separate web pagebreak

This is compiled using

htlatex foo.tex "htm,3"
 

  1. HTML output of this theme is HTML
  2. PDF output of this theme is PDF

pict

\documentclass{report} 
\setcounter{tocdepth}{0} 
\setcounter{secnumdepth}{4} 
\usepackage{lipsum} 
\usepackage{titletoc} 
 
\begin{document} 
 
\title{my web site} 
\author{me} 
\date{\small\today} 
\maketitle 
 
%tell tex4ht to make main toc show only chapters 
%thanks to Radhakrishnan CV for this solution 
\ifdefined\HCode 
\Configure{tableofcontents*}{chapter} 
\fi 
 
\tableofcontents 
 
\ifdefined\HCode 
\TocAt{chapter,section} %show section only in chapters TOC 
\TocAt{section,subsection} %show subsection only in sections TOC 
\fi 
 
%--------------------- 
\chapter{chapter 1} 
\ifdefined\HCode 
\else 
{ 
\startcontents[chapter] 
\printcontents[chapter]{}{1}{\setcounter{tocdepth}{1}} 
} 
\fi 
  \lipsum[10] 
 
  \section{section 1 in chapter 1} 
  \lipsum[1-2] 
 
  \section{section 2 in chapter 1} 
  \lipsum[1-2] 
  \subsection{subsection 1 in section 2 in chapter 1} 
  \lipsum[1-2] 
 
  \section{section 3 in chapter 1} 
  \lipsum[1-2] 
 
%--------------------- 
 
\ifdefined\HCode 
\PauseCutAt{section} 
\fi 
 
\ifdefined\HCode 
\else 
{ 
\stopcontents[chapter] 
} 
\fi 
 
 
\chapter{chapter 2} 
  \lipsum[10] 
 
  \section{section 1 in chapter 2} 
  \lipsum[1-2] 
 
  \section{section 2 in chapter 2} 
  \lipsum[1-2] 
  \subsection{subsection 1 in section 2 in chapter 2} 
  \lipsum[1-2] 
 
  \section{section 3 in chapter 2} 
  \lipsum[1-2] 
 
\end{document}
 

4.4.2 theme 2

There seems to be an issue somewhere, I need to resolve. This is getting complicated.

  1. HTML output of this theme is HTML
  2. PDF output of this theme is PDF

pict

\documentclass{report} 
\setcounter{tocdepth}{0} 
\setcounter{secnumdepth}{4} 
\usepackage{lipsum} 
\usepackage{titletoc} 
 
\begin{document} 
 
\title{my course A} 
\author{me} 
\date{\small\today} 
\maketitle 
 
\ifdefined\HCode 
\Configure{tableofcontents*}{chapter} 
\fi 
 
\tableofcontents 
 
\ifdefined\HCode 
\TocAt{chapter} %turn off TOC 
\fi 
 
%--------------------- 
\chapter{chapter 1 my HWs} 
 
\begin{tabular}{|l|l|} 
\hline 
HW & grade \\\hline 
HW1 \ ref{sec:HW1}  & 100\% \\\hline 
HW2 \ ref{sec:HW2}  & 100\% \\\hline 
\end{tabular} 
 
\ifdefined\HCode 
\TocAt{section,subsection} %turn on TOC 
\fi 
\section{HW 1} 
\ifdefined\HCode 
\else 
{ %turn on local TOC 
\startcontents[section] 
\printcontents[section]{}{1}{\setcounter{tocdepth}{1}} 
} 
\fi 
 
\label{sec:HW1} 
\subsection{problem 1} 
  \lipsum[10] 
\subsection{problem 2} 
  \lipsum[10] 
\subsection{problem 3} 
  \lipsum[10] 
 
\section{HW 2} 
\label{sec:HW2} 
\subsection{problem 1} 
  \lipsum[10] 
\subsection{problem 2} 
  \lipsum[10] 
\subsection{problem 3} 
  \lipsum[10] 
 
\ifdefined\HCode 
\TocAt{chapter,section} %turn on TOC 
\PauseCutAt{section} % do not SPLIT this section 
\fi 
 
%------------------------------ 
\chapter{project} 
\ifdefined\HCode 
\else 
{ %turn on local TOC 
\startcontents[chapter] 
\printcontents[chapter]{}{1}{\setcounter{tocdepth}{1}} 
} 
\fi 
 
\section{introduction} 
\lipsum[10] 
\section{design} 
\lipsum[10] 
\section{appendix} 
\lipsum[10] 
 
 
\end{document}
 

4.5 How to make tex4ht and pdflatex work in the same file?

There are number of ways to add htlatex commands to latex document. But the document has to still work with pdflatex.

Here is one way to do it, using ifx

\documentclass{report} 
\usepackage{hyperref} 
\begin{document} 
\tableofcontents 
 
\ifx\HCode\undefined \else 
\href{foo.htm}{HTML} 
\TocAt{chapter,section,subsection,subsubsection} 
\fi 
 
\chapter{chapter 1} 
\section{section 1 in chapter 1} 
\subsection{subsection 1 in section 1 in chapter 1} 
\subsection{subsection 2 in section 1 in chapter 1} 
\subsubsection{subsubsection 1 subsection 2 in section 1 in chapter 1} 
 
\end{document}
 

Another way is to use HCode

\documentclass{report} 
\usepackage{hyperref} 
\begin{document} 
\tableofcontents 
 
%--------------------- 
\ifdefined\HCode 
\href{foo.htm}{HTML} 
\TocAt{chapter,section,subsection,subsubsection} 
\fi 
 
\chapter{chapter 1} 
\section{section 1 in chapter 1} 
\subsection{subsection 1 in section 1 in chapter 1} 
\subsection{subsection 2 in section 1 in chapter 1} 
\subsubsection{subsubsection 1 subsection 2 in section 1 in chapter 1} 
 
\end{document}
 

4.6 Adding tex4ht configuration inside latex file instead of using .cfg

One can use \Configure after \begin{document}

These are from Michal Hoftich.

(untested, just an idea): 
 
\documentclass{article} 
\ifdefined\HCode 
\newcommand\html[1]{% 
\HCode{#1}% 
}% 
\else 
\newcommand\html[1]{}% 
\fi 
\begin{document} 
\html{<div class="hello>world</div>} 
\end{document}
 

And

You don't need \Preamble and \EndPreamble in your document, they are 
useful only in config file. You can use \Css, \Tg or \ConfigureEnv, 
but only after '\begin{document}'. Something like this should work: 
 
\documentclass{article} 
\usepackage{somepackage} 
\begin{document} 
 \ifx\HCode\undefined \else 
 \Css{body{background-color:green;}} 
 \ConfigureEnv{quote}{\Tg<quote>}{\Tg</quote>}{}{} 
 \fi 
 
\ifx\HCode will ensure that this code run only when tex4ht is loaded.
 

4.7 removing the extra TOC on main page

Problem: Running this generates an extra TOC

 htlatex foo.tex "htm,2" 
 
%-------------- 
\documentclass{article}% 
\usepackage{ifpdf} 
\usepackage{lipsum} 
 
\begin{document} 
\title{test toc} 
\author{me} 
\date{\today} 
\maketitle 
 
\tableofcontents 
 
\section{section 1} 
    \lipsum{1} 
    \subsection{subsection 1} 
    text 
\section{section 2} 
    \lipsum{1} 
\section{section 3} 
    \lipsum{1} 
 
\end{document}
 

One solution is this:

htlatex foo_split.tex "htm,0" 
 
------------------------------------- 
\documentclass{article}% 
\usepackage{ifpdf} 
\usepackage{lipsum} 
 
\begin{document} 
\title{test toc} 
\author{me} 
\date{\today} 
\maketitle 
 
\ifx\HCode\undefined \else 
\CutAt{section}    % tell is to cut as if we did "htm,2", make 
\fi                % section separate 
 
\tableofcontents 
 
\section{section 1} 
     \lipsum{1} 
     \subsection{subsection 1} 
     text 
\section{section 2} 
     \lipsum{1} 
\section{section 3} 
     \lipsum{1} 
 
\end{document}
 

Another is (thanks to Radhakrishnan) is

 
htlatex foo.tex "html,2,notoc*" 
 
\documentclass{article}% 
\usepackage{ifpdf} 
\usepackage{lipsum} 
 
\begin{document} 
\title{test toc} 
\author{me} 
\date{\today} 
\maketitle 
 
\tableofcontents 
 
\section{section 1} 
    \lipsum{1} 
    \subsection{subsection 1} 
    text 
\section{section 2} 
    \lipsum{1} 
\section{section 3} 
    \lipsum{1} 
 
\end{document}
 

4.8 Changing the depth of the main toc in HTML

To change how deep the TOC is on the main page in HTML, do the following. Suppose we want to show chapter, section, subsection, and subsubsection in the TOC, then here is an example

\begin{document} 
 
\title{my dynamics cheat sheet} 
\author{{\small Nasser M. Abbasi}} 
\date{{\small \today}} 
\maketitle 
 
\ifdefined\HCode 
  \Configure{tableofcontents*}{chapter,section,subsection,subsubsection} 
\fi 
 
\tableofcontents
 

Splitting the document (html) based on section is different. This is handled as follows. Suppose we want to split by 2, then compile as

make4ht foo.tex "htm,2,charset=utf-8,pic-align,notoc*" " -cunihtf -utf8"
 

If you are using a htlatex .cfg file, say my.cfg, then change the above to be

make4ht foo.tex "my,htm,2,charset=utf-8,pic-align,notoc*" " -cunihtf -utf8"
 

Notice the use of notoc*

4.9 making local TOC at some units but not in others

tex4ht does not support minitoc. And could not make it to work with titletoc either.

One way to simulate it, is to use \TocAt{} inside the document, like this:

pdflatex foo.tex 
htlatex  foo.tex  "htm" 
htlatex  foo.tex "htm,2" 
 
\documentclass{report}% 
\usepackage{ifpdf} 
\usepackage{lipsum} 
\usepackage{minitoc} 
 
\begin{document} 
 
\title{test minTOC with tex4ht} 
\author{me} 
\date{\today} 
\maketitle 
 
\ifdefined\HCode 
\else 
\dominitoc  %only for pdf 
\fi 
 
\tableofcontents 
 
\ifdefined\HCode 
\TocAt{chapter,section,subsection}  %do it before chapter 
\fi 
 
\chapter{chapter 1} 
\ifdefined\HCode 
\else 
\minitoc 
\fi 
 
\lipsum{1} 
\section{section 1 under chapter 1} 
     text 
\subsection{subsection 1 under section 1 under chapter 1} 
        text 
\subsubsection{subsubsection 1} 
 
\ifdefined\HCode 
\TocAt{chapter}  %RESET it to NO TOC before chapter 
\fi 
 
\chapter{chapter 2} 
 
\lipsum{1} 
\section{section 1 under chapter 2} 
\end{document}
 

4.10 how to use tikz picture with math in htlatex?

Assuming the latex file is foo2.tex

\documentclass{article} 
\ifdefined\HCode 
\def\pgfsysdriver{pgfsys-tex4ht.def} 
\fi 
\usepackage{tikz,graphicx} 
% 
\usetikzlibrary{trees} 
\begin{document} 
\begin{tikzpicture} 
 \node {root} 
  child {node {$\frac{a}{b}$}}; 
\end{tikzpicture} 
\end{document}
 

The file is compiled as

htlatex foo2.tex "my.cfg,charset=utf-8" " -cunihtf -utf8"
 

where my.cfg is

\Preamble{xhtml,mathml} 
\Configure{VERSION}{} 
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}} 
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}} 
\Configure{@HEAD}{} 
\Configure{@HEAD}{\HCode{<meta charset="UTF-8" />\Hnewline}} 
\Configure{@HEAD}{\HCode{<meta name="generator" content="TeX4ht 
(http://www.cse.ohio-state.edu/\string~gurari/TeX4ht/)" />\Hnewline}} 
\Configure{@HEAD}{\HCode{<link 
         rel="stylesheet" type="text/css" 
         href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}} 
\Configure{@HEAD}{\HCode{<script type="text/javascript"\Hnewline 
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"\Hnewline 
></script>\Hnewline}} 
\Configure{@HEAD}{\HCode{<style type="text/css">\Hnewline 
  .MathJax_MathML {text-indent: 0;}\Hnewline 
</style>\Hnewline}} 
\begin{document} 
\EndPreamble
 

Now the file foo2.html will display in the browser as

pict

notice: The math does not show up in the HTML. This is a known issue with using math+tickz+htlatex see http://tex.stackexchange.com/questions/124682/error-usi ng-htlatex-with-tikz-forest-package-invalid-svg-generated

A better approach is this: Use separate latex file to make the diagram using tikz. Use standalone class. Then generate the pdf file using pdflatex.

Next convert the pdf to png, then using a separate latex file, include this image as png where it needs to go. This way htlatex and pdflatex will be able to process it ok. Here are the steps.

  1. make separate latex file for each diagram. For example diagram.tex

    \documentclass{standalone} 
    \usepackage{tikz 
    } 
    \usetikzlibrary{trees} 
    \begin{document} 
    \begin{tikzpicture} 
     \node {root} 
      child {node {$\frac{a}{b}$}}; 
    \end{tikzpicture} 
    \end{document}
     
    
  2. compile the above file to pdf

    pdflatex diagram.tex
     
    
  3. convert the pdf file to png

    pdftoppm -png diagram.pdf > diagram.png 
    or 
    convert -density 200 -limit memory 64MB -limit map 128MB -colorspace RGB diagram.pdf diagram.png 
    \begin{TEXTinline} 
    % 
    \item create the latex file which will use the above diagram, say \verb|main.tex| 
     
    \begin{TEXTinline} 
    \documentclass{article} 
    \usepackage{graphicx} 
     
    \begin{document} 
     
    The following diagram was generated using tikz+latex in 
    a separate file 
     
    \includegraphics{diagram.png} 
     
    and it is now in html 
    \end{document}
     
    
  4. now make pdf and html files from the above

    pdflatex main.tex 
    htlatex main.tex
     
    
  5. now the files main.pdf and main.html can be used.

    pict

added 020814Some examples with math do work in htlatex. Here is a nice picture in tikz with math on it, that htlatex was able to process with no error. This is using texlive 2013 version.

I did not have to use standalone as workaround as in the above example to make the math show up. I am using the code as shown in this post http://tex.stackexchange.com/questions/158668/nice-scientific-pictures-show-off by Paul Gessler. Here are the steps to convert this to HTML using htlatex and the result obtained

  1. make the foo.tex file using your editor (copy from the above link)

    \documentclass{standalone} 
    \usepackage{tikz}             % TikZ and PGF 
     
    % Vector Styles 
    \tikzstyle{load}   = [ultra thick,-latex] 
    \tikzstyle{stress} = [-latex] 
    \tikzstyle{dim}    = [latex-latex] 
    \tikzstyle{axis}   = [-latex,black!55] 
     
    % Drawing Views 
    \tikzstyle{isometric}=[x={(0.710cm,-0.410cm)},y={(0cm,0.820cm)},z={(-0.710cm,-0.410cm)}] 
    \tikzstyle{dimetric} =[x={(0.935cm,-0.118cm)},y={(0cm,0.943cm)},z={(-0.354cm,-0.312cm)}] 
    \tikzstyle{dimetric2}=[x={(0.935cm,-0.118cm)},z={(0cm,0.943cm)},y={(+0.354cm,+0.312cm)}] 
    \tikzstyle{trimetric}=[x={(0.926cm,-0.207cm)},y={(0cm,0.837cm)},z={(-0.378cm,-0.507cm)}] 
     
    \begin{document} 
      \begin{tikzpicture} 
        \node (origin) at (0,0) {}; % shift relative baseline 
        \coordinate (O) at (2,3); 
        \draw[fill=gray!10] (O) circle (1); 
        \draw[fill=white] (O) circle (0.75) node[below,yshift=-1.125cm] {Signpost Cross Section}; 
        \draw[dim] (O) ++(-0.75,0) -- ++(1.5,0) node[midway,above] {$d_i$}; 
        \draw[dim] (O) ++(-1,1.25) -- ++(2,0) node[midway,above] {$d_o$}; 
        \foreach \x in {-1,1} { 
          \draw (O) ++(\x,0.25) -- ++(0,1.25); 
        } 
      \end{tikzpicture} 
      \begin{tikzpicture}[dimetric2] 
            \coordinate (O) at (0,0,0); 
            \draw[axis] (O) -- ++(6,0,0) node[right] {$x$}; 
            \draw[axis] (O) -- ++(0,6,0) node[above right] {$y$}; 
            \draw[axis] (O) -- ++(0,0,6) node[above] {$z$}; 
            \draw[fill=gray!50] (0,0,-0.5) circle (0.5); 
            \fill[fill=gray!50] (-0.46,-0.2,-0.5) -- (0.46,0.2,-0.5) -- (0.46,0.2,0) -- (-0.46,-0.2,0) -- cycle; 
            \draw[fill=gray!20] (O) circle (0.5); 
        \draw (0.46,0.2,-0.5) -- ++(0,0,0.5) node[below right,pos=0.0] {Fixed Support}; 
        \draw (-0.46,-0.2,-0.5) -- ++(0,0,0.5); 
        \draw[fill=gray!10] (O) circle (0.2); 
        \fill[fill=gray!10] (-0.175,-0.1,0) -- (0.175,0.1,0) -- ++(0,0,4) -- (-0.175,-0.1,4) -- cycle; 
        \draw (-0.175,-0.1,0) -- ++(0,0,4); 
        \draw (0.175,0.1,0) -- ++(0,0,4) node[right,midway] {Steel Post}; 
        \draw (4,0,3.95) -- ++(0,0,-1); 
        \foreach \z in {0.5,0.75,...,5} { 
          \draw[-latex] (-2*\z/5-0.2,0,\z) -- (-0.2,0,\z); 
        } 
        \draw[load] (0,0,4) -- ++(0,0,-1.25) node[right,xshift=0.1cm] {$F_{z1}$}; 
        \draw[fill=gray!20] (-0.25,-0.25,5) -- (4,-0.25,5) -- (4,+0.25,5) -- (-0.25,+0.25,5) -- cycle; 
        \draw[fill=gray!50] (+4.00,-0.25,4) -- (4,+0.25,4) -- (4,+0.25,5) -- (+4.00,-0.25,5) -- cycle; 
        \draw[fill=gray!10] (-0.25,-0.25,4) -- (4,-0.25,4) -- (4,-0.25,5) -- (-0.25,-0.25,5) -- cycle; 
        \draw (4.05,0,4) -- ++(1,0,0); 
        \draw (4.05,0,5) -- ++(1,0,0); 
        \draw[dim] (4.5,0,0) -- ++(0,0,4) node[midway,right] {$h_1$}; 
        \draw[dim] (4.5,0,4) -- ++(0,0,1) node[midway,right] {$h_2$}; 
        \draw[dim] (0,0,3.4) -- ++(4,0,0) node[midway,below] {$b_2$}; 
        \coordinate (P) at (2,-0.25,4.5); 
        \draw (P) -- ++(0,0,0.25); 
        \draw (P) -- ++(0.25,0,0); 
        \draw[dim] (2.125,-0.25,4.5) -- ++(0,0,-0.5) node[midway,right] {$z_1$}; 
        \draw[dim] (2,-0.25,4.625) -- ++(-2,0,0) node[midway,below] {$x_1$}; 
        \draw[load] (2,-2.45,4.5) -- ++(0,2.2,0) node[pos=0.0,right,xshift=0.08cm] {$F_{y1}$}; 
        \draw[axis,dashed,-] (O) -- (0,0,5); 
        \draw (0,0,5.5) -- ++(4,0,0) node[midway,above] {$w_{z}$}; 
        \foreach \x in {0,0.25,...,4} { 
          \draw[-latex] (\x,0,5.5) -- ++(0,0,-0.5); 
        } 
        \draw (-0.2,0,0) -- ++(-2,0,5) node[above,xshift=0.5cm] {$w_{x}=\frac{z}{h_1+h_2} w_0$}; 
      \end{tikzpicture} % 
    \end{document}
     
    
  2. compile using this his command

    htlatex foo.tex "my.cfg,htm,charset=utf-8" " -cunihtf -utf8"
     
    

    it is important to use my.cfg because without it, you’ll get an error. The cfg file is the one shown above. Just copy that and put it in the same location as the tex file.

  3. here is the HTML generated by the above. HTML should display as

    pict

4.11 how to change font for HTML math when using tex4ht

To increase fonts in tex4ht

if using 12 pt in document class, add this line after the \document section in the .cfg file

\DeclareMathSizes{12}{14}{10}{8} 
\DeclareMathSizes{12}{16}{12}{10}  %----> for {\Large}
 

(note, \Large in a 12pt article is 17.28pt

The size of math’s font changes also with \Large

To make Math look better, see this

http://tex.stackexchange.com/questions/43772/latex-xhtml-with-tex4ht-bad-quality-images-of-equations

4.12 tex4ht options

Example The command htlatex myfile "mycfg,2" requests the compilation of a file named myfile.tex, in the presence of a configuration file named mycfg.cfg. The configuration file might have the following content.

 
\Preamble{html} 
\begin{document} 
  \Css{body { color : red; }} 
\EndPreamble
 

4.13 How to use tex4ht with pdf and latex in same document?

use this

 
\documentclass[titlepage]{article}% 
\usepackage{ifpdf} 
\usepackage{hyperref} 
 
\begin{document} 
 
\ifpdf 
        I am in pdf mode %  pdflatex code,will show up in pdf only 
\else 
      %  latex code, check if htlatex is loaded and use link only then 
      \ifdefined\HCode 
         \href{../../index.htm}{home} % show up in HTML only 
      \else 
       I am in latex mode %  shows up in dvi and .ps only but not in html 
      \fi 
\fi 
 
\end{document}
 

4.14 my setup for using htlatex on linux, installing make4ht

  1. typed kpsewhich -var-value TEXMFHOME

    to find where TeX will look for files.

  2. edits my .basrc and added this

       export TEXMFHOME=$HOME/texmf 
       export PATH=$HOME/texmf/scripts/lu/make4ht-master:$PATH
     
    
  3. I use now make4ht to build latex to html (new builder in place of htlatex). Downloaded it from

    https://github.com/michal-h21/make4ht

    and extracted the zip file below $TEXHMF/scripts/lua folder.

    >unzip make4ht-master.zip 
    Archive:  make4ht-master.zip 
    5417507d156b01aded3371efc2d5b71074bb0afe 
       creating: make4ht-master/ 
      inflating: make4ht-master/README.md 
      inflating: make4ht-master/lapp-mk4.lua 
      inflating: make4ht-master/make4ht 
      inflating: make4ht-master/make4ht-lib.lua 
      inflating: make4ht-master/mkparams.lua 
      inflating: make4ht-master/mkutils.lua 
    >cd make4ht-master/
     
    

    So the tree looks like this

     
    cd $HOME 
    tree texmf 
     
    texmf 
    |___+ scripts 
        |___lua 
            |___make4ht-master 
                |-- lapp-mk4.lua 
                |-- make4ht 
                |-- make4ht-lib.lua 
                |-- mkparams.lua 
                |-- mkutils.lua 
                |-- README.md
     
    
  4. make sure you have convert, if not do sudo apt-get install imagemagick
  5. make sure you have lua, if not do sudo apt-get install lua5.2 (may be not needed)
  6. the command to build latex to html is

             make4ht foo.tex "nma.cfg,htm,charset=utf-8" " -cunihtf -utf8"  "-dfoo"
     
    

    where nma.cfg is currently here nma.cfg

  7. in the latex files, I include one file in the preamble which has all the packages to use. Here it is commonlatex.tex
  8. example latex file will then be as this

             \documentclass[]{article} 
             \input{commonlatex} 
             \begin{document} 
     
             \end{document}
     
    
  9. when first installing, need to fix tex4ht.env so that .png images are better quality. See http://tex.stackexchange.com/questions/43772/latex-xhtml-with-tex4ht-bad-quality-images-of-equations Use the <dvipng> by erasing the space before it and add space before the <convert> section.

    >locate tex4ht.env 
    /usr/local/texlive/2013/texmf-dist/doc/latex/latex-web-companion/ch4/tex4ht.env 
    /usr/local/texlive/2013/texmf-dist/tex4ht/base/unix/tex4ht.env 
    /usr/local/texlive/2013/texmf-dist/tex4ht/base/win32/tex4ht.env 
     
    >cd /usr/local/texlive/2013/texmf-dist/tex4ht/base/unix 
    >sudo cp tex4ht.env tex4ht.env.SAVED 
    >sudo vi tex4ht.env 
    > 
     
    >diff tex4ht.env tex4ht.env.SAVED 
    153c153 
    < <convert> 
    --- 
    >  <convert> 
    170c170 
    < </convert> 
    --- 
    >  </convert> 
    183c183 
    <  <dvipng> 
    --- 
    > <dvipng> 
    185c185 
    < Gdvipng -T tight -x 1400 -D 96 -bg Transparent -pp %%2:%%2 %%1 -o %%3 
    --- 
    > Gdvipng -T tight -x 1400 -D 72 -bg Transparent -pp %%2:%%2 %%1 -o %%3 
    187c187 
    < Gdvipng -T tight -x 1400 -D 96 -bg Transparent -gif -pp %%2:%%2 %%1 -o %%3 
    --- 
    > Gdvipng -T tight -x 1400 -D 72 -bg Transparent -gif -pp %%2:%%2 %%1 -o %%3 
    192c192 
    <  </dvipng> 
    --- 
    > </dvipng> 
    >
     
    

4.15 how to insert HTML code inside the body of a latex document?

Here is an example to insert only ONE HTML line

 
\documentclass{article}% 
\input{commonlatex} 
 
\begin{document} 
 
\ifdefined\HCode 
 \Css{body{width:70\%;}}   %this will be inserted in the HTML, only when using htlatex 
\fi 
 
\end{document}
 

To insert large amount of HTML code, use Radhakrishnan CV method:

 
\documentclass{article} 
\begin{document} 
 
\ScriptEnv{html} 
 {\NoFonts\hfill\break} 
 {\EndNoFonts} 
 
\begin{html} 
<h2>This is HTML head 2 </h2> 
 
more HTML code 
\end{html} 
 
\end{document}
 

reference: http://tug.org/pipermail/tex4ht/2013q3/000823.html

4.16 How to control page margins in html

To control page margins in html, can do it in html or css.

HTML method (add code the BODY tag of your web page source code): 
 
<BODY LEFTMARGIN="10" TOPMARGIN="10" MARGINWIDTH="10" MARGINHEIGHT="10"> 
 
CSS method (add code to the BODY tag of your external style sheet): 
 
body {margin-top: 10px; 
margin-right: 10px; 
margin-bottom: 10px; 
margin-left: 10px;}
 

To change margins in html output of htlatex, use the following .cfg file for htlatex

\Preamble{html} 
\begin{document} 
\Css {body {margin-top: 10px; 
                 margin-right: 10px; 
                 margin-bottom: 10px; 
                 margin-left: 50px; 
                } 
         } 
\EndPreamble
 

and then type htlatex foo.tex "foo.cfg"

4.17 tex4ht and table of content issues

see http://tex.stackexchange.com/questions/44541/tex4ht-limit-toc

I use this command to get table of content to be full in tex4ht

htlatex index.tex "html,7" "" "" "\def\directbuild{}"
 

To make table of contents in HTML have more spaces and look better, use this in the .cfg file:

\begin{document} 
  \ConfigureToc{section} 
      {\tocNesting{1}\HCode{<li>}}{ }{}{ } 
   \ConfigureToc{subsection} 
      {\tocNesting{2}\HCode{<li>}}{ }{}{ } 
   \ConfigureToc{subsubsection} 
      {\tocNesting{3}\HCode{<li>}}{ }{}{ } 
   \Configure{tableofcontents} 
      {} {\tocNesting{0}} {} {} {} 
 
   \newcount\c 
   \def\tocNesting#1{% 
      \expandafter\ifx \csname level#1\endcsname\relax 
          \ifnum #1>0 \HCode{<ul>}\fi 
          \expandafter\def \csname level#1\endcsname{\HCode{</ul>}} 
      \fi 
      \c=#1 \advance\c by 1 
      \loop 
        \csname level\the\c\endcsname 
        \expandafter\let \csname level\the\c\endcsname\relax 
        \advance\c by 1 
      \ifnum \c<10   \repeat 
   }
 

The above will go in the cfg file. This makes the HTML table of content much nicer.

4.18 How to change magnification factor when using dvisvgm with make4ht?

When using the command

make4ht -ulm default -e ~/new.mk4 -c ~/nma.cfg -f html5+dvisvgm_hashes filename.tex "htm,0,pic-align,notoc*,p-width,svg"
 

Then make4ht defaults to using these options dvisvgm -v4 -n --exact -c 1.15,1.15

These options are set in this file /usr/local/texlive/2018/texmf-dist/scripts/make4ht/extensions/dvisvgm_hashes.lua

To change them, add this to your .mk4 file (Thanks to Michal for this hint)

filter_settings "dvisvgm_hashes" { 
  options = "-n --exact -c 1.5,1.5" 
}
 

4.19 using multicol package in htlatex?

update: 8/10/2013. This below is no longer needed. htlatex now includes support directly for multicols. I kept this below for archive purpose, do not use. See this instead

http://tug.org/pipermail/tex4ht/2013q3/000847.html

4.19.1 old method to use multicols

see http://tug.org/pipermail/tex4ht/2013q3/000828.html

Using this my.cfg.txt file as an example

\Preamble{ext=htm,pic-align} 
 
\begin{document} 
\EndPreamble 
 
\catcode`\:=11 \catcode`\@=11 
 
\Configure{HtmlPar} 
   {\EndP\HCode{<!--l. \the\inputlineno-->% 
<p \csname a:!P\endcsname 
          class="no\ifHCond par\else indent\fi" \a:LRdir>}} 
   {\EndP\HCode{<!--l. \the\inputlineno-->% 
<p \csname a:!P\endcsname 
         class="\ifdim \parindent=\z@ no\fi indent" \a:LRdir>}} 
   {{\Tg</p>}} 
   {{\Tg</p>}}% 
 
\renewenvironment{multicols}[1]{\IgnorePar\EndP% 
\HCode{<div class="newspaper}#1\HCode{">} 
\expandafter\ifx\csname .newspaper#1\endcsname\relax% 
\Css{.newspaper#1 p:first-child { margin-top: 0em; }} 
\Css{.newspaper#1 { 
    -moz-column-count:#1; /* Firefox */ 
    -webkit-column-count:#1; /* Safari and Chrome */ 
    column-count:#1; 
    -moz-column-gap:10px; /* Firefox */ 
    -webkit-column-gap:10px; /* Safari and Chrome */ 
    column-gap:10px; 
    -moz-column-rule:1px outset \#F8F8F8 ; /* Firefox */ 
    -webkit-column-rule:1px outset \#000000; /* Safari and Chrome */ 
    column-rule:1px outset \#000000; 
}} 
\expandafter\gdef\csname .newspaper#1\endcsname{1}% 
\fi% 
\ShowPar\par} 
{\EndP\HCode{</div>}} 
 
\ConfigureEnv{multicols} 
    {\par\IgnorePar\EndP% 
     \gHAdvance\MultiCols by 1\relax} 
    {\ifvmode\IgnorePar\fi\EndP} 
    {}{} 
 
 
\endinput
                                                                                    
                                                                                    
 

and using this Latex file as an example foo.tex

\documentclass{article}% 
\usepackage{lipsum} 
\usepackage{multicol} 
\setlength{\columnsep}{20pt} 
\setlength{\columnseprule}{0.01pt} 
\begin{document} 
 
\begin{multicols}{2} 
 
   \begin{enumerate} 
     \item A 
     \item B 
    \end{enumerate} 
    \lipsum[1-10] 
 
\end{multicols} 
 
\end{document}
 

and using this command htlatex foo.tex "my.cfg" then htlatex will generate multiple columns.

Thanks goes to Jagath AR for help in greatly improving the configuration file.

4.20 How to use images with htlatex and pdflatex

This is what I do. Here is an template example

\documentclass[12pt,notitlepage]{article} 
 
\usepackage{graphicx} 
\begin{document} 
\includegraphics[scale=0.4]{img} 
\end{document}
 

I have img.png to start with, since most apps I use can generate .png images. But since htlatex wants .eps, I convert the png to eps like this

convert img.png eps3:img.eps
 

Make sure to use level3 eps to reduce the size. Note, no space between eps3: and the target file name next to it. Have to use eps for htlatex, else it will not scale the png file. htlatex can read png files, but png files have no bounding boxes, so can’t change the size if needed as in the above example.

What if you do not have png image as the original? and only have eps? Then now pdflatex is not happy and htlatex is happy. Ok, no problem, use this package as below. So this solution below will work for all conditions

\documentclass[12pt,notitlepage]{article} 
\usepackage{epstopdf}% 
\epstopdfsetup{update} 
 
\usepackage{graphicx} 
\begin{document} 
\includegraphics[scale=0.4]{img} 
\end{document}
 

So what will happen now, is if the file was img.eps, then pdflatex will convert it to pdf automatically and use the img.pdf file for the graphics. htlatex see the eps file and is happy.

So rule of thumb: If it was img.png, convert to eps first to make htlatex happy. If it was .eps, then include the above packages to make pdflatex happy. And always leave the extension off the image name in the latex file as above.

It will be better to generate .eps image to start with from the app which created the images if possible, so do not have to remember to convert them each time to eps, But if not, do the above.

4.21 adding white space

tex4ht does not support \quad or \qquad out of the box, as it generates normal spaces in HTML for these which will be collapsed to single space. Replace this by something such as \hspace{5mm}

Another work around is found here

http://comments.gmane.org/gmane.comp.tex.tex4ht/86

4.22 Avoid vref

Watch out. Do not use \vref, and replace with \ ref. Using \vref caused me many hours trying to find out why the document was cut off in HTML. Tex4ht does not work with \vref and will cause many problems. As of texlive 2014

4.23 Where are the 4ht files located?

They are in /usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/*.4ht

4.24 Where is tex4ht.env located ?

This file is in /usr/local/texlive/2014/texmf-dist/tex4ht/base/unix/tex4ht.env

4.25 Patch for report style

added August 10, 2014

There is a bug in tex4ht as of texlive 2014. When using report style the table of content shows section even if told not to.

Use the patch shown in this link. Edit your report.4ht by the patch shown

here

The report.4ht file is located in

/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/report.4ht

This is until the fix is added to texlive.

Note: The above only work if the HTML page is not split. If you are splitting it, then the bug is stil there and not fixed.

4.26 Watch out for Verbatim frame not showing in Chrome

added August 14, 2014

To add frame around Verbatim, the framerule must be used to force the frame thickness to be at least 0.8pt else it will not show in Chrome. (Thanks for Michal Hoftich for finding why the frame was not showing in Chrome).

So to use a frame and having it show in all three major browsers, use something as follows (until Chrome can handle all rule thickness.

\documentclass[12pt]{article} 
\usepackage{fancyvrb} 
\begin{document} 
 
\begin{Verbatim}[frame=single,framerule=.8pt] 
text 
\end{Verbatim} 
\end{document}
 

4.27 How to use tex4ht with SVG for math and images

This is the best configuration to use. It makes the math use .svg for images instead of png, and also supports an includes pictures as svg.

First thing is to edit tex4ht.env

sudo vi /usr/local/texlive/2014/texmf-dist/tex4ht/base/unix/tex4ht.env
 

pict

The next step is to edit your .cfg and make it like this

\Preamble{ext=htm,charset="utf-8",p-width,pic-align} 
\Configure{VERSION}{} 
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}} 
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}} 
\Configure{@HEAD}{} 
\Configure{@HEAD}{\HCode{<meta charset="utf-8"/>\Hnewline}} 
\Configure{@HEAD}{\HCode{<meta name="generator" content="TeX4ht 
(http://www.cse.ohio-state.edu/\string~gurari/TeX4ht/)" />\Hnewline}} 
\Configure{@HEAD}{\HCode{<link rel="stylesheet" type="text/css" 
   href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}} 
 
\Configure{Picture}{.svg} 
 
\makeatletter 
\Configure{graphics*} 
{svg} 
{ 
  {\Configure{Needs}{File: \Gin@base.svg}\Needs{}} 
  \Picture[\csname a:GraphicsAlt\endcsname]{\csname Gin@base\endcsname.svg 
          \csname a:Gin-dim\endcsname} 
} 
% 
\makeatletter 
\Configure{graphics*} 
{eps}% 
{\Needs{"convert \csname Gin@base\endcsname.eps 
          \csname Gin@base\endcsname.png"}% 
          \Picture[pict]{\csname Gin@base\endcsname.png}% 
          \special{t4ht+@File: \csname Gin@base\endcsname.png} 
} 
 
 
\begin{document} 
\EndPreamble
                                                                                    
                                                                                    
 

Now compile your .tex file like this (where nma.cfg below is your tex4eht .cfg file.)

make4ht index.tex "nma,htm,pic-align,charset=utf-8,notoc*" " -cunihtf -utf8"
 

Make sure to inlcude \usepackage{graphicx} in your latex document! else you’ll get this error

(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)) 
l.34 --- TeX4ht warning --- \Configure{graphics*}? --- 
 
! LaTeX Error: Missing \begin{document} in `nma.cfg'.
 

Thanks goes to Michal-h21 for help in making the above instructions.

4.28 converting cropped pdf page to svg

After cropping part of pdf page and generating foo.pdf file, which is one page only, to convert this to svg file to include with tex4ht, do this

pdf2svg p.pdf p.svg

I found this works better than

inkscape --without-gui --file=p.pdf --export-plain-svg=p.svg

This can be used to do the conversion of all cropped pdf files in the folder

#!/bin/bash 
for file in *.pdf; do 
    filename=${file%.*} 
    pdf2svg "$filename.pdf" "$filename.svg" 
done
 

4.29 How to change image size of svg for html generation?

I can’t find out why \includegraphics[scale=0.5]{pic.svg} does not work with tex4ht as it does with pdf. So to change the svg image size, simply edit the svg file with text editor, and change the first line that says something like width="500pt" height="500pt" to just with="250px" for example, and save the .svg file.

4.30 How to include animated gif file in the HTML?

add this in Latex file, and use normal HTML coding in there. This will only show up in the HTML and not affect the pdflatex run

\ifdefined\HCode 
\HCode{ 
   <image src="movie.gif"  alt="movie" 
}
 

4.31 How to build using make4ht

This is what I use now to build things for tex4ht

make4ht -u -c ~/nma.cfg -e ~/main.mk4 index.tex "htm,pic-align,notoc*"
 

To split the document, say 3 levels, then the command is

make4ht -u -c ~/nma.cfg -e ~/main.mk4 index.tex "htm,3,pic-align,notoc*"
 

Make sure to have the main.mk4 build file in my home folder as well as the .cfg file. The main.mk4 I use now is written by michal.h21 main.mk4 and my .cfg is nma.cfg

You need to have latest make4ht installed, which does not come with texlive. You can get it from https://github.com/michal-h21/make4ht

see how-to-speed-up-tex4ht-image-generation-process for reference

Thanks to michal.h21 support for making the above possible.

4.32 remember to set TEXINPUTS

htlatex uses TEXINPUTS to find .cfg file if the file is not in the current directly. This is what I do. Edit $HOME/.bashrc$ and add the line export TEXINPUTS=.:$HOME:$TEXINPUTS

4.33 To make .bbx files

use ebb -x foo.pdf if you get an error like this

* WARNING ** Streams with DecodeParams not supported.
 

This convert the pdf to ps, then convert it back to pdf, it should now work

pdf2ps foo.pdf foo.ps 
ps2pdf foo.ps foo.pdf 
ebb -x foo.pdf
 

4.34 How to used fixed width table?

tex4ht does not support fixed width using the m{} option in tabular. So this will not work

\begin{tabular}{|m{2in}|m{2in}|m{2in}|}\hline
 

The width is ignored, even if one compiles with p-width option. One way is to change m to p. Another option is to look at this post

4.35 tex4ht references

  1. CVR web site, has lots of tex4ht information http://cvr.cc/?p=504
  2. main tex4ht page http://tug.org/applications/tex4ht/mn.html
  3. http://tug.org/applications/tex4ht/mn3.html
  4. http://www.cvr.cc/?p=362
  5. configure command
  6. tex4ht options by CVR http://www.cvr.cc/?p=504
  7. http://tug.org/applications/tex4ht/mn14.html#mn14-1
  8. http://newsgroups.derkeiler.com/Archive/Comp/comp.text.tex/2010-0 7/msg00585.html
  9. thread at http://tug.org/pipermail/tex4ht/2013q3/000856.html
  10. commits to tex4ht source tree http://tug.org/pipermail/tex4ht-commits/
  11. Michal-h21 tex4ht tutorial https://github.com/michal-h21/helpers4ht/wi ki/tex4ht-tutorial
  12. Tex4ht for SW http://facweb.knowlton.ohio-state.edu/pviton/support/ swpht.html#swphtpa4.html
  13. http://tex.stackexchange.com/questions/69063/tex4ht-includegraphicspage-10foo-pdf shows how to include pdf pages in HTML. But I could not get it to work in Tl 2015.