14

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.

24

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}
4
  • 4
    @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
  • How do we get this working for grey text (or somehow faded). I tried colors "gray", but it says that is undefined (though I can see "gray" in the documentation). – Jeff Jan 18 '17 at 22:33
  • 2
    @Jeff --- Use xcolor rather than color. This has predefined colours gray, lightgray and darkgray. Otherwise, you can define your own by doing something like \definecolor{mygray}{gray}{0.75}. – Ian Thompson Jan 18 '17 at 22:52

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.