# Detect markers in macro arguments

I'd like to find a way to define a command which would work like this

\mycommand{This +is+ a +simple example+.}


and give

This is a simple example.

i.e a command which looks for words surrounded by a particular symbol (here a +) and changes the formatting (here in bold) of these words.

-

This is easy:

\def\mycommand{\begingroup\setupplus\mycommandaux}
\def\setupplus{%
\catcode+=\active
\begingroup\lccode~=+\lowercase{\endgroup\def~##1~}{\textbf{##1}}%
}
\newcommand\mycommandaux[1]{#1\endgroup}


You open a group and in this group you set up + to be active; its action is to gather everything up to the next + and to print it in boldface. The important thing is to gather the argument after the setup has been performed. So the action is split into two and \mycommandaux gathers the argument, so that TeX can process it, and closes the group started by \mycommand.

Don't use such shortcuts; they'll bite you, some day or the other.

Caution: this \mycommand cannot be used in the argument of another command. If you need it there, then a slightly more complicated strategy is needed:

\protected\def\mycommand{\begingroup\setupplus\mycommandaux}
\def\setupplus{%
\catcode+=\active
\begingroup\lccode~=+\lowercase{\endgroup\def~##1~}{\textbf{##1}}%
}
\newcommand\mycommandaux[1]{\scantokens{#1\noexpand}\endgroup}

-