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.

I have a set of commands in my document's preamble that look like this:

\newcommand{\nathaniel}[1]{\textcolor{blue}{[#1]}}
\newcommand{\anotherAuthor}[1]{\textcolor{darkgreen}{[#1]}}

They are to allow my coauthors and I to make comments in the document that will appear in the pdf, to facilitate working on it. However, we find we quite often want to put several paragraphs inside such a comment (e.g. if we've written some new material that we're not sure about, and we want the other authors to notice it). If I try to do this:

\nathaniel{
    one

    two
 }

then I get this error:

paragraph ended before \@textcolor was complete

I know I can use \\ to get a linebreak instead, but I'd prefer it if my custom command would just accept normal paragraph breaks. Is there some command that will cause LaTeX to accept multiple paragraphs as if they were a single one, or some other way to colour multiple paragraphs of text?

share|improve this question

3 Answers 3

up vote 17 down vote accepted

\textcolor is similar to \mbox, so it doesn't typeset paragraphs; use the declarative form, instead, in a group:

\newcommand{\nathaniel}[1]{{\color{blue}[#1]}}
share|improve this answer
    
Perfect, thanks. –  Nathaniel Mar 29 '12 at 11:29

you could make an environment form

\newenvironment{thisnote}{\par\color{blue}}{\par}

then

\begin{thisnote}
   stuff

   in blue
\end{thisnote}

can take paragraphs of text

share|improve this answer
    
I'm always unsure about this. The way it is defined here, the \endgroup triggering color-back-switching will come in vertical mode, hence the switching magic will go in the vertical list, making \lastbox and things more difficult. Hence I always try to have color switching in horizontal mode. –  Stephan Lehmke Mar 29 '12 at 10:01
    
true but arranging environment switching to be always in hmode is a pain too (see missing item error question in today's list) When we added the colour support did experiment with a version that always delayed itself if used in hmode, and insert at start of next para but that complication had downsides as well as it broke more 3rd part packages and is harder to make work with rules and things. –  David Carlisle Mar 29 '12 at 10:18
    
Wouldn't this work: \newenvironment{thisnote}{\par\begingroup\color{blue}}{\endgroup\par}? –  Stephan Lehmke Mar 29 '12 at 10:23
1  
That makes it very sensitive to the contents of the environment, for example if there is a size change in the text but no ending para the size change and the colour will end at the \endgroup but the paragraph will end at the \par so you get big text set on normal baselineskip. Also in that form the start color is definitely in vertical mode so it doesn't really solve the problem (you could try delaying it into \everypar but then it gets delicate if the first thing in the environment isn't just simple text. In particular if the paragraph starts within a group. –  David Carlisle Mar 29 '12 at 11:06
    
Ok, thanks for the clarification. It seems color switching is too murky to be done right without a great amount of care. –  Stephan Lehmke Mar 29 '12 at 11:07

Just for a change:

\documentclass{article}  
\usepackage{xcolor}
\usepackage{lipsum}
%%---------------------------- colored box as paragraph---------------
\newcommand*{\mybox}[2]{%
\noindent\colorbox{#1!30}{%
\parbox{0.98\linewidth}{#2}}}%
%%----------------------------colored text as paragraph---------------
\newcommand*{\mytext}[2]{%
\noindent\color{#1!80}{%
\parbox{0.98\linewidth}{#2}}}%
%%----------------------------
\begin{document}
%=====================
\mybox{green}{\lipsum[1]}
\par
\mytext{red}{\lipsum[2]}   
%%----------------------------
\end{document}

Disclaimer: This won't break across pages. If that is the requirement, one can use mdframed package.

share|improve this answer

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.