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
  • 4
    I think the title is misleading. You rather want to have a command acting on the environment body – user31729 Feb 2 '16 at 8:47
  • Doesn't \newenvironment{FOO}{\bar\bgroup}{\egroup} work? – Hagen von Eitzen Feb 2 '16 at 14:30

(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

  • Please note that there might be cases where an \expandafter for the \BODY is necessary before the command \mycmd comes into action – user31729 Feb 2 '16 at 11:36
  • Collecting the environment body is easiest with environ How do you go about it in normal environments? (I can ask a new question if necessary) – MayeulC Jul 23 '18 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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