TeX/ifx

      Synopsis

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

      Description

      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

      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.

      Last modified on 13 December 2012, at 21:28