11

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?

14

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
\@ifpackageloaded{tex4ht}{%
  \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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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