TeX/ifx

From Wikibooks, open books for an open world
< TeX
Jump to: navigation, search

Synopsis[edit]

\ifx \Macro1 \Macro2
<tex commands>
\else
<tex commands>
\fi

Description[edit]

With the \ifx command you can perform conditional compilation by testing for macro equivalence. It does not expand the given macros. The two macros are considered equal if

  • both are macros and
  • the first level expansion is equal and
  • they have the same state with regards to \long and \outer

See also the command \def.

Examples[edit]

For example, let's say we define a new macro just to do conditional compilation:

\def \myMacro {}

Then we can use \ifx to check if this macro is defined or not.

\ifx \myMacro \undefined
This will be processed if myMacro is not defined.
\else
This will be processed if myMacro is defined.
\fi

See also [1] on the use of this method for testing whether a macro is defined.