自定义辅助文件和 tex4ht 的问题

自定义辅助文件和 tex4ht 的问题

我有一个 LaTeX 文件,它与 配合得很好pdflatex。我想将其转换为 HTML,因此我使用tex4ht(在 Windows 7 上的 MiKTeX 2.9 下)。我已经解决了一些问题(例如,旧的图形问题),但仍然有几个问题。这是最奇怪的一个。

我有一些粗略的代码来创建自定义辅助文件并将其读回,以将整个文档中的要点合并到列表中。我使用\openoutputfile\addtostream和 来执行此操作\closeoutputstream

我的问题在于,写入其中的一些点包含百分比。这些代码当然带有反斜杠%,如\%。运行 时pdflatex,辅助文件会获得带有反斜杠的完整代码。运行 时xhlatex,反斜杠会被删除。请注意,只有在百分比的情况下才会这样 - 其他命令都可以正常通过。

因此,当读回此内容时,第一个内容之后的所有内容%都会被忽略(因为它们\textbf也都被包裹在内)

最小(我所能理解的)示例:

 \documentclass[a4paper,11pt,titlepage]{report}

\usepackage{newfile}
\usepackage{ifthen}

% stuff for automatic building of recommendation list
% Use \recommend{blah} for recommendations to appear in the key recommendations list. It also insets it in-place
%  with bold face.
% Use \reclist to insert the stored list. This should be done either before or after all \recommend commands in the document.
\newoutputstream{rec}
\newboolean{recstreamopen}
\setboolean{recstreamopen}{false}
\newcommand{\openrecstream}{%
\ifthenelse{\not\boolean{recstreamopen}}{
\openoutputfile{\jobname.rec}{rec}
\setboolean{recstreamopen}{true}}{}%
}
\newcommand{\closerecstream}{%
\ifthenelse{\boolean{recstreamopen}}{
\closeoutputstream{rec}
\setboolean{recstreamopen}{false}
}{}%
}
\newcommand{\reclist}{
\closerecstream
\begin{itemize}
\input{\jobname.rec}
\end{itemize}
}
\newcommand{\recommend}[1]{%
\openrecstream%
\textbf{#1}%
\addtostream{rec}{\noexpand\item \textbf{#1}}%
}
\newcommand{\reclistonly}[1]{%
\openrecstream%
\addtostream{rec}{\noexpand\item \textbf{#1}}%
}
\AtEndDocument{\closerecstream}

\begin{document}

\reclist

\recommend{This is recommendation one, with no percentage.}

\recommend{The is recommendation two, 74.3\% of statistics are made up on the spot.}

\recommend{This is recommendation three.}

\end{document}

由于它还很粗糙,您可能需要创建一个空的 filename.rec 文件来让它运行。pdflatex 按照预期运行,xhlatex 从 .rec 文件中的 % 中删除了反斜杠。

有人有任何想法吗?

答案1

尝试这个

\newcommand{\recommend}[1]{%
\openrecstream%
\textbf{#1}%
\begingroup
\def\%{\noexpand\%}
\addtostream{rec}{\noexpand\item \textbf{#1}}%
\endgroup
}

它似乎\%以某种方式被重新定义tex4ht,所以它不会通过文件写入操作,我们可以将它写入文件\def\%{\noexpand\%}

相关内容