Take the 2-minute tour ×
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.

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?

share|improve this question
add comment

1 Answer

up vote 12 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.

\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}
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
add comment

Your Answer

 
discard

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.