TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

Also, is there any references about "advanced" macros in TeX?

share|improve this question
up vote 7 down vote accepted

This is easy:


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:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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