String comparison

With \let\TokenIsIn=a, the control sequence \TokenIsIn becomes an unexpandable token; more precisely, it becomes an “implicit a”.

The tests \if\TokenIsIn a and \ifx\TokenIsIn a return true, but \ifthenelse makes the comparison in a different way; basically, \ifthenelse{\equal{X}{Y}} does something like

\edef\first{X}\edef\second{Y}\ifx\first\second

and this test returns false when X is \TokenIsIn and Y is a, because \first and \second don't have the same first level expansion: an implicit token is not the same as the token.

For \IfBeginWith the situation is a bit more complicated, but essentially the test fails because something like \edef\first{\TokenIsIn} is performed as well and, in \edef, \TokenIsIn is not changed into a.

With \ifthen and \IfBeginWith only explicit token should be used.

The three tests return true if you do

\newcommand{\settok}[1]{\gdef\TokenIsIn{#1}}