Thanks to everyone's input. Here is the work around that was suggested to me to use and I thought to document it here.
Even though this is a workaround, it is a very good work around. The idea is to use a separate latex file to make the diagram(s) using tikz+math using standalone
class.
Hence, there will be one latex file for each one diagram.
Then generate the pdf file using pdflatex.
Next these pdf file(s) are converted to png. Using a separate latex file, this png is included where it needs to be. This way htlatex and pdflatex will be able to process the final document ok.
Here are the steps.
1) make separate latex file for each diagram. For example diagram.tex
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\begin{tikzpicture}
\node {root}
child {node {$\frac{a}{b}$}};
\end{tikzpicture}
\end{document}
2) compile the above file to pdf
pdflatex diagram.tex
3) convert the pdf file to png
pdftoppm -png diagram.pdf > diagram.png
4) create the latex file which will use the above diagram, say main.tex
\documentclass{article}
\usepackage{graphicx}
\begin{document}
The following diagram was generated using tikz+latex in
a separate file
\includegraphics{diagram.png}
and it is now in html
\end{document}
5) now make pdf and html files from the above
pdflatex main.tex
htlatex main.tex
6) now the files main.pdf and main.html can be used.
![enter image description here](https://i.stack.imgur.com/Ceewy.jpg)
Thanks again for everyone's help. I will use this method from now one.
While you could check if a bool is defined by using \ifcsundef{if...}
(see comment from moewe), it looks as if you actually want a boolean which is always false if you are in a chapter tex file.
This can be archived by using \providebool
, which defines the bool as false, iff is is not defined already:
Use
\newbool{is_single_book}
\booltrue{is_single_book}
in your main file and
\providebool{is_single_book}
\ifbool{is_single_book}{}{%
\externaldocument{volume1}[http://mybook.com/volume1.pdf]%
}
in your chapter files.
Even better would be to use toggles. They are almost the same but avoid name clashes and provide slightly better performance:
To use them, insert
\newtoggle{is_single_book}
\toggletrue{is_single_book}
in your main file and
\providetoggle{is_single_book}
\iftoggle{is_single_book}{}{%
\externaldocument{volume1}[http://mybook.com/volume1.pdf]%
}
in the chapters.
Best Answer
There is always this:
Suitable for other packages of interest as well, of course. (Usual caveats about @ character apply.)