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}
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.
Best Answer
This isn't actually caused by the
comment
package, it's the colour change, as you can see from this example.To eliminate the problem with blank lines, replace
\color{black}
with\vskip0pt\color{black}\noindent
. However, the colouring macros will still cause trouble if amycomment2
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.