TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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 found that in order to use tikz with tex4ht to produce HTML, I need to do the following:


I also need to produce PDF from the same tex file using pdflatex, but that gives me an error with the \def above.

Is there a way to exclude the def from pdflatex?

share|improve this question
up vote 13 down vote accepted

htlatex loads package tex4ht at the end of the class. Therefore \@ifpackageloaded can be used to detect TeX4ht. Inside a class tex4ht is not yet loaded if htlatex is used. Then TeX4ht can be detected via \HCode that is defined by htlatex.

  % only needed inside a class
  \expandafter\ifx\csname HCode\endcsname\relax
share|improve this answer
Works great - thanks! One question, @Heiko - where can I learn these tex programming commands? Is The TexBook by Knuth the right place? Right now, the only book I have is The Latex Companion. – M-V Oct 12 '12 at 4:40
Experience, answering bug reports, the stuff with \HCode was a recent addition to hyperref, ... – Heiko Oberdiek Oct 12 '12 at 13:51

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.