[Tex/LaTex] How to define a new \item command to produce a different color

colorlists

I am trying to define an alternative \item command that would allow me to use a different color for some of the items. My code has the following form:

\documentclass{article}
\usepackage{color}

\definecolor{gray}{rgb}{0.7,0.7,0.7}
\newcommand{\grayitem}[1]{{\color{gray} \item #1}}

\begin{document}

\begin{enumerate}
\item First item.
\grayitem Second item.
\item Third item.
\end{enumerate}

\end{document}

I was hoping that

\grayitem Second item.

would produce the same result as

{\color{gray} \item Second item.}

but for some reason, these are not equivalent. They produce the following results, respectively:

       enter image description here            enter image description here

Why are these two lines of code not equivalent? What am I doing wrong and how can I change the definition of \grayitem to produce the second result?

I have also tried removing a pair of braces, like this

\newcommand{\grayitem}[1]{\color{gray} \item #1}

but then the third item becomes gray as well.

The solution should also work for multi-paragraph items.

Best Answer

A bit hacky, but without braces:

\documentclass{article}
\usepackage{color}

\definecolor{gray}{rgb}{0.7,0.7,0.7}


\let\olditem\item
\newcommand{\grayitem}{\color{gray}\olditem}
\renewcommand{\item}{\color{black}\olditem}

\begin{document}

\begin{enumerate}
\item First item.
\grayitem Second item.
\item Third item.
\end{enumerate}

\end{document}

enter image description here


To make subliste adhere to the gray colour one could do something like the following, however if you want to use gray items inside a second level list, changing back to black won't work

\documentclass{article}
\usepackage{color}

\definecolor{gray}{rgb}{0.7,0.7,0.7}

\makeatletter
\let\olditem\item
\newcommand{\grayitem}{\color{gray}\olditem}
\renewcommand{\item}{%
    \ifnum\@enumdepth<2
        \color{black}%
    \fi%
\olditem}
\makeatother

\begin{document}

\begin{enumerate}
    \item First item.
    \grayitem Second item.
        \begin{enumerate}
            \item bla
            \item bla
        \end{enumerate}
    \item Third item.
        \begin{enumerate}
            \item bla
            \grayitem bla
            \item bla
        \end{enumerate}
\end{enumerate}

\end{document}

enter image description here