[Tex/LaTex] Tex4ht under MiKTeX: How to convert multiple tex files

miktextex4ht

I'm using MiKTeX 2.9 and installed the miktex-tex4ht-base2.9 in order to convert my LaTeX files into HTML. I just updated everything before starting so I should have the latest packages for everything. I am also using Windows 7.

My LaTeX file contains other LaTeX files via the \include command. It is a book with chapters that are stored in a separate folder with their own tex files.

For example, I have Main.tex with Chapter1.tex, Chapter2.tex… and so forth which are included in the whole document using \include.

Is it possible to call htlatex Main.tex and it will compile all the required files or is there some step by step procedure to do each file? When I tried it, I got 100s of errors (pdflatex compiles without any errors and I have an output pdf file, htlatex even worked on a simple single file so I know htlatex is working properly). I would have pasted the errors but there are just so many and most of them relate to missing curly brackets for a section or missing an end{document} which is why I am thinking it has something to do with the \include command.

I have pasted below some errors,

?
! Extra }, or forgotten \endgroup.
l.22 ...lax }}\par \let \reserved@d =*\def \par }}
                                                  {section.1}{}}
?
! Extra }, or forgotten \endgroup.
l.22 ...t \reserved@d =*\def \par }}{section.1}{}}

Below is the first error I recieve after running htlatex Main.tex

! Undefined control sequence.
<argument> )Qfigure.\theHfigure

l.40 \:CrossWord{)Qfigure.\theHfigure }{1}{5}
                                             %

This is the main.tex file,

\documentclass[11pt,a4paper,oneside]{article}

\usepackage{hyperref}
\usepackage[all]{hypcap}    %for going to the top of an image when a figure reference is clicked
\usepackage{draftwatermark}
\usepackage{url}

\usepackage{fullpage}

\SetWatermarkText{INTERNAL}
\SetWatermarkFontSize{5cm}
\SetWatermarkScale{4.5}
\SetWatermarkLightness{0.9}

%For toggling between print pdf and electronic pdf
%change the reference style.
\newif\ifelectronic

%\electronicfalse
\electronictrue

\ifelectronic
\newcommand{\xyzref}[1]{\nameref{#1}}
\else
\newcommand{\xyzref}[1]{\ref{#1}}
\fi

%For switching between stand alone APPlication and plugin
\newif\ifapp

%\apptrue
\appfalse

%to NOT print the subsection numbers in the table of contents
\newcounter{sectocnonumdepth}
\setcounter{sectocnonumdepth}{2}

\renewcommand{\familydefault}{\sfdefault}

\hypersetup{colorlinks=true}

\usepackage{listings}

\begin{document}

\ifapp
    \title{\textbf{XYZ Quick Start} \\ (For stand-alone application users)}
\else
    \title{\textbf{XYZ Plug-in Quick Start} \\ (For Plug-in users)}
\fi

\author{Company XYZ}
\maketitle

\tableofcontents

\input{Chapters/Chap1}
\input{Chapters/Chap2}
\input{Chapters/Chap3}
\input{Chapters/Chap4}

\end{document}

Below is a sample chapter,

\section{Creating a New Project}
\label{sec:newProject}

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

\begin{enumerate}
\item Go to `File' menu.
\item Select `New'.

\ifapp  %if its the standalone

\item And click the XYZ Project option. Note: If you do not see this option then check whether you are in the XYZ perspective via Window$\rightarrow$Open Perspective.

\else %if its plugin

\item Select `Project...'.
\item A New Project dialog will open which will ask you to select a project wizard\index{Wizard}. Choose the XYZ project under the XYZ category (see figure \ref{fig:XYZWizard}) and then click `Next'.
\begin{figure}[hp]
    \centering
        \includegraphics[width=0.50\textwidth]{Images/XYZWizard.PNG}
    \caption{Eclipse New Project Dialog}
    \label{fig:XYZWizard}
\end{figure}

\fi

\item Give the project a name. You can either choose the default workspace location, or browse for another location. The Mod-Dat-Run style folder structure just creates the three respective folders in your project, if you check it (figure \ref{fig:XYZWizard2}); You can always create the folders later. These folders are independent of the files you put in them.
\begin{figure}[hp]
    \centering
        \includegraphics[width=0.50\textwidth]{Images/XYZWizard2.PNG}
    \caption{XYZ New Project Wizard Dialog}
    \label{fig:XYZWizard2}
\end{figure}

\ifapp

\else
\item After clicking `Finish', Eclipse will ask you if you want to change to the XYZ perspective, click yes.

\fi

\item The project has been created and you will be able to see it in the Project Explorer.

\end{enumerate}

Best Answer

The problem seems to be

\usepackage[all]{hypcap}

Once I removed this particular line, delete the *.aux and *.xref files, running htlatex Mainbook produced an HTML file without errors. Remember to delete the *.aux, so that tex4ht doesn't pick up the auxiliary files containing the errors from the previous run.

Another thing is that by default, when tex4ht sees an \includegraphics, it tries to convert an .eps to a .png. This is often highly undesirable when you are already using PNG files anyway. The trick is to put the following in a myconfig.cfg file, on the same path as Mainbook.tex:

\Preamble{html}
\begin{document}
% Upper case PNG file extensions
\Configure{graphics*}
   {PNG}
   {\Picture[pict]{\csname Gin@base\endcsname.PNG}}

% Lower case png extensions
\Configure{graphics*}
   {png}
   {\Picture[pict]{\csname Gin@base\endcsname.png}}
\EndPreamble 

And run the following command, to tell tex4ht to use your configuration file:

$  htlatex Mainbook "myconfig"

The <img> tags in your generated HTML file should now link to your existing PNG graphics.

Related Question