Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\documentclass{minimal}
\begin{document}

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

\end{document}

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?

share|improve this question
add comment

2 Answers 2

up vote 12 down vote accepted

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.

share|improve this answer
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
add comment

A possibility is to say

\def\fancycommand{%
  \begingroup\def\par{\endgroup\par}%
% <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.

share|improve this answer
add comment

Your Answer

 
discard

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.