With
\def\a#1{\ifx E#1\else \b\fi}
the call \a ABC
takes A
as the argument to \a
, so the input stream becomes
\ifx EA\else\b\fi BC
and, since the condition turns out to be false, what remains in the input stream is
\b\fi BC
Thus the arguments to \b
are #1<-\fi
and #2<-B
, so we get
[\fi:B]C
Now \fi
performs its duty of disappearing and you get
[:B]C
If instead you define
\def\a#1{\ifx E#1\else\expandafter\b\fi}
after the conditional we get
\expandafter\b\fi BC
The \expandafter
makes \fi
disappear before \b
is expanded, so we find
\b BC
and finally
[B:C]
In the case of \a EBC
, the first step would give
\ifx EE\else\b\fi BC
that turns into
\else\b\fi BC
The expansion of \else
throws out everything up to the matching \fi
and we simply get
BC
Looking at the log file with \tracingmacros=1
helps:
\tracingmacros=1
\def\a#1{\ifx E#1\else \b\fi}
\def\b#1#2{[#1:#2]}
\a ABC
will produce
\a #1->\ifx E#1\else \b \fi
#1<-A
\b #1#2->[#1:#2]
#1<-\fi
#2<-B
that shows precisely what I diagnosed without doing the experiment.
If you add also \tracingifs=1
(with an e-TeX based engine such as pdftex
), you get
\a #1->\ifx E#1\else \b \fi
#1<-A
{vertical mode: \ifx: (level 1) entered on line 4}
{\else: \ifx (level 1) entered on line 4}
\b #1#2->[#1:#2]
#1<-\fi
#2<-B
{horizontal mode: \fi: \ifx (level 1) entered on line 4}