[texhax] How to test for existence of a macro?

Aditya Mahajan adityam at umich.edu
Sat Aug 29 03:02:55 CEST 2009


On Fri, 28 Aug 2009, D. R. Evans wrote:

> I couldn't find this in the TeXbook, but perhaps I was just looking in the
> wrong place.
>
> How should I test cleanly for the existence of a particular macro?
>
> The use case is that I have been using pdfTeX for quite some time, and
> hence using commands of the form \pdfxxx with impunity. Now that I'm trying
> to use tex4ht, the first thing that happens is that it halts with an error
> as soon as it hits the first of those commands.
>
> (Actually, I guess I'm making an assumption that the \pdfxxx commands are
> equivalent to macros, even though they're built-in.)
>
> Anyway, what I want to do is stuff like replacing:
>  \pdfoutput=1
> with something logically equivalent to:
>  if (exists(\pdfoutput))
>    \pdfoutput=1;
>  else
>    do something else;
>
> Presumably to do this one creates:
> \newif\ifpdf
> and then sets it to true or false depending on whether (say) \pdfoutput is
> defined... but I don't know how to perform the test to see whether
> \pdfoutput is defined in a way that doesn't cause an error if it's undefined.

See the ifpdf package. It does exactly this.

http://www.ctan.org/tex-archive/help/Catalogue/entries/ifpdf.html

Aditya


More information about the texhax mailing list