TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:



% 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.
\addtostream{rec}{\noexpand\item \textbf{#1}}%
\addtostream{rec}{\noexpand\item \textbf{#1}}%



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


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?

share|improve this question
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

\addtostream{rec}{\noexpand\item \textbf{#1}}%

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

share|improve this answer
you are right, I edited the code – michal.h21 May 3 '12 at 16:48
Thanks, I shall try this when I get back to working on this - I'm away at a meeting all weekend. – SamBC May 4 '12 at 2:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.