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'm using the specialcomment-command from the comment package around equation and align environments. This leads to an unwanted blank line after the math environment. When just using the simple includecomment-command, the problem does not show, neither when my special comment just encloses "normal" text. In my example, this doesn't look so bad. But in my actual document there are other settings so it just doesn't look good. Changing the spacing by \specialcomment{mycomment2}{\color{red}}{\color{black}\vspace{-4ex}} or something like that messes with the normal commented text. How can I fix this?

\documentclass{article}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{comment}
\includecomment{mycomment1}
\specialcomment{mycomment2}{\color{red}}{\color{black}}
\begin{document}
\begin{mycomment1}
\begin{equation}
x=y
\end{equation}
\end{mycomment1}

\blindtext

\begin{mycomment2}
\begin{equation}
x=y
\end{equation}
\end{mycomment2}

\blindtext

\begin{mycomment2}
Just some normal text, no problem there.
\end{mycomment2}

\blindtext
\end{document}

enter image description here


Edit: It seems that a bit of code I left out in order to make the problem as simple as possible is relevant after all. My code regarding the equations is actually like this:

\begin{mycomment2}
\begin{equation}
x=y
\end{equation}
\end{mycomment2}
%
\begin{flushleft}
Text
\end{flushleft}
\blindtext

In this case there is an extra blank line even though there are none in the code.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

This isn't actually caused by the comment package, it's the colour change, as you can see from this example.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{xcolor}
\begin{document}
\begin{equation}
x=y
\end{equation}

\blindtext

\color{red}
\begin{equation}
x=y
\end{equation}
\color{black}

%
\blindtext

\color{red}
Just some normal text, no problem there.
\color{black}

\blindtext
\end{document}

To eliminate the problem with blank lines, replace \color{black} with \vskip0pt\color{black}\noindent. However, the colouring macros will still cause trouble if a mycomment2 is followed by an environment that begins a new line, and I am not aware of any general solution. @David Carlisle gives a good explanation of the problem and a workaround here.

share|improve this answer
    
Thanks, but that solution doesn't work for me, because the blank lines in my code are there to make paragraphs. If I chose to use \excludecomment{mycomment2} at some point, these paragraphs would no longer exist. It would just be one big bulk of text. –  meep.meep Mar 6 '12 at 12:03
    
@meep.meep --- I have edited my answer. Does it work now? –  Ian Thompson Mar 6 '12 at 14:39
    
Thank you, this is the result I was looking for. –  meep.meep Mar 6 '12 at 15:02
    
Note that this solution doesn’t work if \begin{mycomment2}\begin{equation}...\end{equation}\end{mycomment2} is followed by \begin{flushleft}...\end{flushleft}. –  mhp Mar 6 '12 at 21:39
add comment

If the special comment mycomment2 always constitutes a separate paragraph try:

\makeatletter

\specialcomment{mycomment2}{%
  \par\begingroup\color{red}%
}{%
  \par\global\@tempskipa\lastskip\removelastskip\endgroup\vskip\@tempskipa%
}

\makeatother

Unfortunately, using \color can easily degrade vertical spacing. The critical internal macros are \set@color and \reset@color. Since they are driver-dependent it might be difficult to find a general fix to the vertical spacing problems induced by them.

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.