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 need to turn this

my little pony

into this

\bar{my little pony}

I have tried this:


But this seems to only make \bar apply on the first character, like so:

\bar{m}y little pony
share|improve this question
I think the title is misleading. You rather want to have a command acting on the environment body – Christian Hupfer Feb 2 at 8:47
Welcome to TeX.SE! – Mico Feb 2 at 8:49
Doesn't \newenvironment{FOO}{\bar\bgroup}{\egroup} work? – Hagen von Eitzen Feb 2 at 14:30
up vote 10 down vote accepted

(Admittedly, the example with \color) could be achieved without this, but let us assume \mycmd is more complex for the real case and not a toy 'theory';-))

Collecting the environment body is easiest with environ package and its \NewEnviron command and \BODY.





my little pony



More complex examples might have to use a \expandafter before \BODY.

enter image description here

share|improve this answer
Please note that there might be cases where an \expandafter for the \BODY is necessary before the command \mycmd comes into action – Christian Hupfer Feb 2 at 11:36

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.