description of my tex4ht setup
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"
Before starting, here are rules of thumb to remember. Most of these rules will cover most of the common uses.
\TocAt{chapter,section} %show sections only in chapters TOC
\TocAt{section,subsection} %show subsections only in sections TOC
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.
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"
\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}
There seems to be an issue somewhere, I need to resolve. This is getting complicated.
\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}
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}
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.
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}
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*
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}
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
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.
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}
compile the above file to pdf
pdflatex diagram.tex
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}
now make pdf and html files from the above
pdflatex main.tex htlatex main.tex
now the files main.pdf
and main.html
can be used.
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
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}
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.
here is the HTML generated by the above. HTML should display as
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
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
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}
typed kpsewhich -var-value TEXMFHOME
to find where TeX will look for files.
edits my .basrc
and added this
export TEXMFHOME=$HOME/texmf export PATH=$HOME/texmf/scripts/lu/make4ht-master:$PATH
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
sudo apt-get install imagemagick
sudo apt-get install lua5.2
(may be not
needed)
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
example latex file will then be as this
\documentclass[]{article} \input{commonlatex} \begin{document} \end{document}
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> >
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
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"
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.
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" }
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
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.
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.
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
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
They are in /usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/*.4ht
This file is in /usr/local/texlive/2014/texmf-dist/tex4ht/base/unix/tex4ht.env
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
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.
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}
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
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.
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
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.
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" }
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.
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
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
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