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?

  • I'd also like to tag this question with htlatex or tex4ht but don't have enough reputation. Commented Aug 10, 2010 at 21:42
  • Since there can be a maximum of 5 tags- I replaced the web tag with pdf and html as those are the output formats you are targeting.
    – Sharpie
    Commented Aug 10, 2010 at 21:45
  • One question- what kind of document are we talking about? A book? A report? Heavy on math? Heavy on figures? Does it document the source code of a software project? Some specifics may help the community suggest appropriate tools.
    – Sharpie
    Commented Aug 10, 2010 at 21:48
  • @Sharpie: You're right, I should have been more specific. The document is a 50 page introduction into studying at our university, and contains a lot of prose text, many figures, some tables and bullet point lists, but no formulars at all. Commented Aug 11, 2010 at 12:43
  • Based on the accepted answer, I think you should consider changing the title of this question. Commented Sep 8, 2010 at 3:41

4 Answers 4


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


%pdf specific stuff

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

  • Thanks, ifpdf did exactly what I was looking for and works great for our document. Commented Aug 11, 2010 at 12:44

tex2page usually produces stunning html pages.

  • 3
    Interesting - I'd never heard of tex2page. It appears that it cannot handle macros, is that right? Commented Aug 11, 2010 at 11:46
  • Unfortunately I have no idea. I know about this tool from many years ago from a friend and it just stuck to my head. But since it is written in scheme I'd expect it to be very flexible.
    – Leo Liu
    Commented Aug 11, 2010 at 11:56
  • Didn't know tex2page neither. Because the answer by Martin Heller worked for me, I did not try tex2page, but I added it to the list of Tex-HTML-converters in the German Wikipedia, where it was missing before. Commented Aug 11, 2010 at 12:52

Since the text is mainly prose + floats, you can consider writing your source in markdown and convert it to html and latex/context using pandoc, which does a fairly good job of creating predictable output.


Here's my main suggestion: use version control and have a branch for XHTML+MathML[1] and a branch for PDF. Let the version control system keep track of the changes and leave you to concentrate on making sure that both look as good as they can for the desired output.

Other possibilities spring to mind: as it's quite easy to go from XHTML to PDF (File->Print->Print_to_File!), concentrate on the XHTML version and leave the PDF to the reader.

And, slightly tongue-in-cheek, I'd consider adding a "don't do that" tag to this question (if it wasn't already at the maximum). The requirements for a document to be viewed on the screen are sufficiently different to that to be printed out that it's worth considering having two almost completely separate documents. (NB I know that PDFs are often viewed on the screen, but I'm thinking more about the interaction possible between reader and document that is possible with an XHTML document and is difficult with PDF.)

[1] I know you wrote HTML, but you meant XHTML+MathML.

  • Hmm... thanks for your answer, but none of the alternatives fitted my situation. The focus is: Some initial effort to set the two-way-conversion up, minimum contious effort (e.g. not maintaining two branches or two separate documents). On the other hand, I understand your arguments and they might in fact be useful for someone else in another situation. Commented Aug 11, 2010 at 12:59
  • @Brian Schimmel: Not to belabour the point, but the reason for using a version control system is so make it easy to keep two different versions of the same document. But if \ifpdf works for this situation then that's certainly the easier route. Commented Aug 11, 2010 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .