[Tex/LaTex] How to create PDF and HTML output from the same source

conversionhtmlmakefilepdfpdftex

I'm working on a document that has been published only as a PDF file until now. To utilize some of PDF's features, it uses the packages pdfpages and pdftex and commands like includepdf{}.

But soon that document shall be available in both PDF an HTML format. I figured out I can use htlatex / tex4ht to convert it, but it seems that this tool is not compatible with the special pdf features and packages. Once I remove them, it works.

Removing the pdf stuff, converting to html and then putting it in again manually is not an option (This is an evolving document that has been worked on for over 10 years by a large number of contributors and is still edited by several people, so we rely on an automated build process using make).

Is there any way similar to conditional compilation to ignore some \usepackage directives on some of the make runs, or do you have any other hint on how to do this?

Best Answer

You can use package ifpdf and enclose pdf-specific stuff in \ifpdf ... \fi

\usepackage{ifpdf}

\ifpdf
%pdf specific stuff
\fi

Alternatively, you can make the pdf-file and convert to html using a tool like pdftohtml.

Related Question