# Test for a character, no matter if active or not (futurelet token)

I'd like to test for a character, irrespective its current catcode (i.e. active or not). This is very similar to How do I test for a character, irrespective of catcode?, however I cannot use \pdf@strcmp because I might have "half" macros (e.g. \emph without a parameter yet).

\documentclass{minimal}
\usepackage[czech]{babel}% makes - active
\begin{document}
\def\aaa{%
(the letter a)%
(a minus)%
\else%
(special treatment)
\fi\fi%
}
\end{document}


Changing catcodes before and after is not really a solution in my case, because the original meaning would get lost just by futurelet-looking at things.

• Welcome to TeX.SX! Have a look here to know how to start. – karlkoeller Jun 1 '13 at 7:35

\ifx can be used for direct comparisons of the tokens. The following example stores the tokens in macros \aaaHyphenActive and \aaaHyphenOther. In the comparisons the hyphen tokens are unpacked via \expandafter.

\documentclass{minimal}
\usepackage[czech]{babel}% makes - active

\begingroup
\catcode\-=\active
\gdef\aaaHyphenActive{-}%
\catcode\-=12 %
\gdef\aaaHyphenOther{-}%
\endgroup

\begin{document}
\def\aaa{%
(the letter a)%
(an active minus)%
(a minus)%
\else
(special treatment)
\fi\fi\fi
}
\end{document}


You can use expl3. Here's a rough example.

\documentclass{article}
\usepackage[czech]{babel}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\dosomething}{m}
{
\martin_do_something:n {#1}
}
\cs_new_protected:Npn \martin_do_something:n #1
{
\peek_charcode:NTF a % test the first token against "a"
{
(the~letter~a)
}
{
\peek_charcode:NTF - % test the first token against "-" (charcode only)
{
(a~hyphen)
}
{
(special~treatment)
}
}
#1
}
\ExplSyntaxOff

\begin{document}

\dosomething{abc}

\dosomething{-abc}

\dosomething{\emph{abc}}

\the\catcode- % check that the hyphen was active

\catcode-=12  % make it non active and try again

\dosomething{-abc}

\end{document}