Possible Duplicate:
Changing catcode for commercial at (@) inside a macro to get it matched in pattern.
I want to test whether a string contains the @ sign. I came up with the following piece of code:
\makeatletter
\def\@testat#1@#2\@nil{%
\def\@cdr{#2}
\ifx\@cdr\@empty #1#2: does not have at\else #1#2: has at\fi}
\def\hasat#1{\@testat#1@\@nil}
\makeatother
Now this works fine if the document is written with \makeatletter:
\makeatletter
\newcommand\test[1]{#1}
\test{\hasat{linear@ set@}}
\hasat{linear@ set@}
\hasat{linear set}
all work fine. But without the \makeatletter, this fails miserably. If instead I define:
\def\@hasat#1{\@testat#1@\@nil\makeatother}
\def\hasat{\makeatletter\@hasat}
then only the \hasat which is not in a \test works for some reason.
Any help welcome!
\@cdras part of your macro; it's already a macro used in the kernel and redefining it can lead to obscure errors. – egreg Nov 04 '12 at 23:09