# Problem with custom auxiliary file and tex4ht

I have a LaTeX file that's working very well with pdflatex. I want to turn it into HTML, so I'm using tex4ht (under MiKTeX 2.9 on Windows 7). I've already gotten around some problems (the old graphics issue, for instance), but I have a couple of problems still. This is about the strangest one.

I have some rough-and-ready code to create a custom auxiliary file and read it back in, to consolidate key points from throughout the document into a list. I do this using \openoutputfile, \addtostream and \closeoutputstream.

My problem comes where some of the points written to it include a percentage. The code for these has the % backslashed, of course, as \%. When running pdflatex, the auxiliary file gets the code complete with backslash. When running xhlatex, the backslash gets stripped. Only in the case of the percentage, mind you - other commands are passed through fine.

So, when this is read back, everything after the first % gets ignored (as it's all wrapped in \textbf as well)

Minimal (as best I can make out) example:

 \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}%
}
\newcommand{\reclistonly}[1]{%
\openrecstream%
}
\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}


As it's rough-and-ready, you may need to create an empty filename.rec file to persuade it to run. pdflatex does what's expected, xhlatex removes the backslash from the % in the .rec file.

Anyone got any ideas at all?

-
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. –  diabonas May 2 '12 at 18:41
@diabonas: I can't see how to attach a file, so here it is verbatim: –  SamBC May 2 '12 at 19:09
No, can't add it verbatim, it's too long. Can you tell I'm new? ;) –  SamBC May 2 '12 at 19:10
Okay, example added inline. Thanks for the pointer, @diabonas –  SamBC May 2 '12 at 19:15

Try this

\newcommand{\recommend}[1]{%
\openrecstream%
\textbf{#1}%
\begingroup
\def\%{\noexpand\%}

it seems \% is redefined by tex4ht in some way so it doesn't pass by file writing operations, we can write it to the file with \def\%{\noexpand\%}