Is it possible to define a command so that it affects everything until the end of the current paragraph?

As a minimal example, I am trying to define a command using syntax similar to the following:


\fancycommand Laugh, and the world laughs with you.
Weep, and you weep alone.


Where \fancycommand affects all of the following text from the same paragraph including any line-breaks (for example, doing a number of text transformations), but not any subsequent paragraphs. The command cannot use braces around the rest of the paragraph.

If this is not possible, is it possible to do something similar until the end of the current line?


You can use \par as delimiter and scan the paragraph as one argument.

\def\fancycommand #1\par{#1\par}

Note, that you need to re-add the \par.

  • 4
    Two limitations: \par or an empty line must be given explicitly, it cannot be hidden in other macros. Verbatim stuff makes problems, because the catcodes are already set by the previous reading from \fancycommand. – Heiko Oberdiek Oct 25 '12 at 3:02

A possibility is to say

% <other setup>

It much depends on what you have to do in <other setup>. For instance, here is a version that italicizes, just write \itshape in place of <other setup>

enter image description here

Here the trick is that \endgroup will remove the redefinition of \par, so the inserted \par will be whatever it was when TeX encountered \fancycommand. Of course a \par (or an empty line) should be present in order to terminate properly the special setting.


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.