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.

Sorry for being as clueless as the last times I asked but also having done no research because I have to finish this overhead presentation for tomorrow...

Is there a good way to create an environment which makes all text inside it colored in a certain color?

I have tried:

\newenvironment{rrpptt}{\textcolor{gray}}{\textcolor{black}}

But this doesn't yield what I want... It gives a compile error and just puts the word "rrpptt" inside the text. What am I doing wrong?

Of course I do have the color package loaded. I also have the beamer documentclass - is that a problem?

Oh, and I don't care about \textcolor being lowlevel and stuff - I don't have footnotes and sudden page changes, so I would be content with the way \textcolor normally works, if it would do so.

share|improve this question

1 Answer 1

up vote 9 down vote accepted

The \textcolor macro takes a second argument, which is the text to be coloured. The \color macro changes the colour until the end of the current group or environment. So I think you need something like this.

\documentclass{minimal}
\usepackage{color}
\newenvironment{redtext}{\color{red}}{\ignorespacesafterend}
\begin{document}
Here is some black text.
\begin{redtext}
And here is some red text.
\end{redtext}
Here is more black text.
\end{document}
share|improve this answer
    
AAAAAAHHHH! Thanks! –  darij grinberg May 17 '11 at 22:22
2  
@darij (and @Ian) You could even omit the \color{black} at end of the definition because the environment itself is a group … It is also recommended to use xcolor instead of color. Maybe you would like to add \ignorespacesafterend at end of the definition to prevent unwished spaces. –  Tobi May 18 '11 at 9:24
    
@Tobi --- you are right, putting \black there was pointless. I didn't know about \ignorespacesafterend, so thanks for a useful tip. –  Ian Thompson May 18 '11 at 15:37
    
You're welcome! :-) –  Tobi May 18 '11 at 20:52

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.