MiKTeX下的Tex4ht:如何转换多个tex文件

MiKTeX下的Tex4ht:如何转换多个tex文件

我使用的是 MiKTeX 2.9,并安装了 miktex-tex4ht-base2.9,以便将我的 LaTeX 文件转换为 HTML。我在开始之前更新了所有内容,因此我应该拥有所有内容的最新软件包。我也在使用 Windows 7。

我的 LaTeX 文件通过命令包含其他 LaTeX 文件\include。这是一本包含章节的书,这些章节存储在单独的文件夹中,并带有自己的 tex 文件。

例如,我有 Main.tex,其中包含 Chapter1.tex、Chapter2.tex……等等,它们包含在整个文档中\include

是否可以调用htlatex Main.tex并编译所有必需的文件,或者是否有一些逐步的程序来执行每个文件?当我尝试它时,我得到了 100 个错误(pdflatex 编译时没有任何错误,我有一个输出 pdf 文件,htlatex 甚至可以在一个简单的单个文件上工作,所以我知道 htlatex 工作正常)。我本来会粘贴错误,但错误实在太多了,其中大多数与某个部分缺少花括号或缺少一个有关,end{document}这就是为什么我认为它与命令有关\include

我在下面粘贴了一些错误,

?
! 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}{}}

以下是运行后我收到的第一个错误htlatex Main.tex

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

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

这是 main.tex 文件,

\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}

以下是示例章节,

\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}

答案1

问题似乎是

\usepackage[all]{hypcap}

一旦我删除了此特定行,删除*.aux*.xref文件,运行htlatex Mainbook就会生成一个没有错误的 HTML 文件。请记住删除*.aux,以便 tex4ht 不会拾取包含上次运行中错误的辅助文件。

另一件事是,默认情况下,当 tex4ht 看到 时\includegraphics,它会尝试将 转换.eps.png。这通常是非常不理想的,当你无论如何,已经使用 PNG 文件了。诀窍是将以下内容放在myconfig.cfg与 相同的路径上的文件中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 

并运行以下命令,告诉 tex4ht 使用您的配置文件:

$  htlatex Mainbook "myconfig"

<img>您生成的 HTML 文件中的标签现在应该链接到您现有的 PNG 图形。

相关内容