[texhax] If ... else

Uwe Lueck uwe.lueck at web.de
Sun Mar 8 08:54:24 CET 2015

Clifford Weil wrote at 2015-03-08 18:03:00 +0100:
> I need to add an \if … else command to a class file I’ve written.
> The purpose is to determine how to enter a \addcontentsline
> command depending on whether or not hyperref has been loaded.
> What is the syntax for that \if … else command.

There are many kinds of \if..., the reference that seems 
most easily available to me is The TeXbook.
The syntax then is \if...<if>\else<else>\fi.

\addcontentsline indicates LaTeX, and it seems to me 
that hyperref needs LaTeX. With LaTeX, a direct \if...
construction often is more difficult than using available 
macros calling the tests. LaTeX \ifthenelse, on the other 
hand, just is doing simple things in a difficult way, in 
my view, and anyway it rather adresses LaTeX users rather 
than class writers. The most direct way to control expansion 
according to whether hyperref has been loaded, is 


(learnt from Heiko Oberdiek).

I do follow Reinhard's suggestion to always load hyperref, 
if only in draft mode when appropriate. I have this in a 
kind of personal standard package:

        <and more>

... because I like to run latex as a kind of syntax check 
before I run pdflatex, while non-draft hyperref with mere 
latex introduces other difficulties. Maybe there is a 
better way, but it works.

HTH -- Uwe L.

More information about the texhax mailing list