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 an environment defined as follows:

\usepackage{framed}
\usepackage{listings}
\usepackage{color}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows}
\usetikzlibrary{backgrounds}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\definecolor{gray}{gray}{0.3}
\definecolor{darkgreen}{rgb}{0,0.55,0}
\definecolor{purple}{rgb}{0.5,0,1}

\newenvironment{comment}{
  \medskip
  \begin{framed}
    \color{red}
    {\textbf{I say: }}
}{
\end{framed}
  \medskip
}

After leaving the environment the color is not restored and so it is still red. Should I restore it explicitly somewhere?

share|improve this question
    
can you make a complete document showing all packages used. It is very hard to debug a fragment. Looks like a bug in something not being "color safe" as defined by the color package documentation. –  David Carlisle Sep 13 '12 at 12:44
    
Perhaps you may have a look to the mdframed package to define your own colored environment. –  Claudio Fiandrino Sep 13 '12 at 12:48
    
I can't used mdframed because of tex.stackexchange.com/questions/71345/… –  Manuel Selva Sep 13 '12 at 12:49
add comment

3 Answers

up vote 4 down vote accepted

It seems that framed messes up with colors; just declare the color before entering the environment:

\newenvironment{comment}
  {\par\medskip
   \color{red}%
   \begin{framed}
   \textbf{I say: }\ignorespaces}
 {\end{framed}
  \medskip}

I've reformatted the code and inserted the important \ignorespaces; remember that spaces (or end-of-lines) that don't follow a control sequence are significant. For the same reason, any environment whose "begin" part starts a paragraph should issue \ignorespaces: this gobbles the space after \begin{comment} (it's an end-of-line, but it's the same to TeX).

This definition will produce a red frame. If you want a black frame, then

\newenvironment{comment}
  {\par\medskip
   \begin{framed}
   \begingroup\color{red}%
   \textbf{I say: }\ignorespaces}
 {\endgroup\end{framed}
  \medskip}

will do.

share|improve this answer
    
why did you add \par ? –  Manuel Selva Sep 13 '12 at 14:13
    
@ManuelSelva It's true that framed starts a new paragraph, but the \medskip command is usually better placed between paragraphs. The \par ensures correct behavior even if you don't leave an empty line before \begin{comment}. –  egreg Sep 13 '12 at 14:18
add comment

The quickest fix seems to be insert the colored text inside a group.

The code:

\documentclass{article}   

\usepackage{framed}
\usepackage{color}
\definecolor{gray}{gray}{0.3}
\definecolor{darkgreen}{rgb}{0,0.55,0}
\definecolor{purple}{rgb}{0.5,0,1}

\newenvironment{comment}{
  \medskip
  \begin{framed}
    \bgroup\color{red}
    {\textbf{I say: }}
}{
\egroup\end{framed}
  \medskip
}

\begin{document}
Foo.
\begin{comment}
Here is the content of the \verb!comment! environment.
\end{comment}
Foo.
\end{document}

The result:

enter image description here

Is this what you want to achieve?

share|improve this answer
add comment

An easy option is to make color environments, even nested and mixed with \textcolor:

MWE ouput

\documentclass{article}
\usepackage{framed}
\usepackage{color}
\definecolor{purple}{rgb}{0.5,0,1}

\newenvironment{comment}{
  \medskip
\begin{color}{red}
\begin{framed}
\begin{color}{blue}
    \textcolor{purple}{\textbf{I say: }} 
}{
\end{color}
\end{framed}
\end{color}
  \medskip
}

\begin{document}
Normal text before
\begin{comment}
 ... Hello
\end{comment}
Normal text after
\end{document}
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.