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:

  \ifx\@cdr\@empty #1#2: does not have at\else #1#2: has at\fi}

Now this works fine if the document is written with \makeatletter:

\test{\hasat{linear@ set@}}
\hasat{linear@ set@}
\hasat{linear set}

all work fine. But without the \makeatletter, this fails miserably. If instead I define:


then only the \hasat which is not in a \test works for some reason.

Any help welcome!

marked as duplicate by user11232, egreg, Stefan Kottwitz Nov 4 '12 at 23:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Dammit. Stackexchange now pops up the relevant related question: tex.stackexchange.com/questions/17393/… . Feel free to close this question as a duplicate. – Michaël Nov 4 '12 at 23:03
  • Don't define \@cdr as part of your macro; it's already a macro used in the kernel and redefining it can lead to obscure errors. – egreg Nov 4 '12 at 23:09
  • Strange, I would not consider this as a duplicate of the other one. If we really think they're "identical", I would say that this one is better and provides a better answer. – yo' Nov 5 '12 at 9:59

You can detect if the given string contains a character with the xstring package:



    #1 \IfEq{\Position}{0}{#3}{#2}%


\HasAt{ancd@foo.bar}{does}{does not} contains the @ symbol.

\HasAt{ancdfoo.bar}{does}{does not} contains the @ symbol.


Not the answer you're looking for? Browse other questions tagged or ask your own question.