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

Synopsis[edit | edit source]

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

Description[edit | edit source]

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 | edit source]

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.
This will be processed if myMacro is defined.

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