[Tex/LaTex] Problem with spacing after \[…\] environment when using the \textcolor{} command

colorindentationmath-modespacing

I'm getting odd spacing/indentation behavior when the \textcolor command is combined with the \[ … \] environment. I did find a fix by putting % in a couple places, as outlined below, but I'd like to know if anyone has a better solution. The picture below, followed by a MWE, explains the problem in more detail.

Output:

enter image description here

Code:

\documentclass[a4paper,11pt]{article}
\usepackage{amsmath, amsfonts, amssymb, parskip, dsfont, amsthm, wasysym, mathrsfs}
\usepackage{graphicx}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathrsfs}
\usepackage[normalem]{ulem}
\usepackage[breaklinks=true]{hyperref}
\usepackage{soul, color} % for highlighting
\usepackage{pifont} % for cool symbols in text mode

\begin{document}

\textbf{No problems with spacing or indents when I don't use the 
\textbackslash[ ... \textbackslash] environment.}

\textcolor{NavyBlue}{Insert problem description here.}

Insert problem solution here.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\textbf{When I use the \textbackslash[ ... \textbackslash] environment, it
puts a large space after
the \textbackslash textcolor section.}

Insert problem solution here. %% this line should have been removed

\textcolor{NavyBlue}{Insert problem description here. Along with some math:
\[ 1 \neq 0 \]}

Insert problem solution here.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\textbf{I can sort of fix the problem by eliminating the space 
between the problem statement and the solution statement, but 
then there is an ugly little indent.}

\textcolor{NavyBlue}{Insert problem description here. Along with some math:
\[ 1 \neq 0 \]}
Insert problem solution here.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\textbf{Finally, I realized that I could ``fix'' the problem by putting a 
comment character at the end of the line and between the lines.}

\textcolor{NavyBlue}{Insert problem description here. Along with some math:
\[ 1 \neq 0 \]}%
%
Insert problem solution here.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\textbf{But this seems incredibly hacky, and I'm hoping someone can point 
me to a more elegant fix.}

\end{document}

EDIT: So after using your suggestions (Johannes), it no longer has the indent, but it that space is still there. Here's what I'm talking about:

Code:

enter image description here

Output:

enter image description here

EDIT #2: It's a very minor difference, but I'm seeing a larger gap between the math and the text than between the text and the text:

enter image description here

Here's the relevant code:

\textbf{4.} \hspace{5 pt} 
\begin{specialmathtwo}
Blah blah blah blah blah blah blah blah blah blah Turing machine blah blah such that
\[L \subseteq \{ M \mid \text{$M$ is a Turing machine that blah blah blah} \}.\]
\end{specialmathtwo}
Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah BLAH blah blah blah blah blah blah blah blah blah.

Blah blah blah blah blah blah blah.

and

\newenvironment{specialmathtwo}{
    \color{NavyBlue}
}{%
\par %Maybe you want to finish all of them off with a paragraph
}

Best Answer

Better not to use \textcolor along with maths over multiple line. You can use \color{<colorname>} instead, and limit the scope by grouping. To be honest, \textcolor does grouping as well, but starts \leavevmode to get to horizontal mode, which makes a little mess for your example.

You can also define a new environment for the colors. That keeps the advantage of having everything in more semantic way. Meaning: What is shown, not how it is shown.

The extra amount of white space is caused by parskip. Parskips are ugly anyways.
The little indentation you noticed is caused by a space, that came from the \textcolor-grouping. \endgroup is hiding that space. Thanks @DavidCarlisle.

\documentclass[a4paper,11pt]{article}
\usepackage{ parskip }
\usepackage{ blindtext }
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage{showframe}
\newenvironment{specialmath}{
    \color{NavyBlue}
}{%
\par %Maybe you want to finish all of them off with a paragraph
}
\begin{document}

\begingroup
\color{NavyBlue}
Insert problem description here. Along with some math:
Insert problem description here. Along with some math:
Insert problem description here. Along with some math:
\[ 1 \neq 0 \]
\endgroup
\blindtext

\blindtext
%just a visual separation, but no \par
\begin{specialmath}
    \[ \sum \int \sin 0 = a \]
        A little descriptive text
\end{specialmath}
\blindtext

\end{document}

That is giving me this output:

Output of the example

Related Question