# Using tikz with both tex4ht and pdflatex

I found that in order to use tikz with tex4ht to produce HTML, I need to do the following:

\def\pgfsysdriver{pgfsys-tex4ht.def}
\usepackage{tikz}


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?

-

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.

\makeatletter
\def\pgfsysdriver{pgfsys-tex4ht.def}%
}{%
% only needed inside a class
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname HCode\endcsname\relax
\else
\def\pgfsysdriver{pgfsys-tex4ht.def}%
\fi
}
\makeatother
\usepackage{tikz}

-
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