[Tex/LaTex] Color a line in array

arrayscolorhighlighting

Is it possible to change a color of a single line inside an array environment?

I have an array of possible solutions and I'd like the best one to be highlighted, the array is declared like

\usepackage{amsmath}
% <...>
\begin{array}{rcc@{+}c@{+}c@{+}cl}
  solution&=&\min\{
    &0&34&0&6, \\
    &&0&23&5&18, \\
    &&5&15&10&16, \\
    &&10&10&9&10, \\
    &&19&5&10&16, \\
    &&23&0&7&5, \\
    &&30&0&9&0
    &\}
\end{array}

I can get some result using

\usepackage{amsmath}
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
% <...>
\begin{array}{rcc@{+}c@{+}c@{+}cl}
  solution&=&\min\{
    &0&34&0&6, \\
    &&0&23&5&18, \\
    &&5&15&10&16, \\
    &&10&10&9&10, \\
    &&19&5&10&16, \\
    &&{\color{Emerald}23}&{\color{Emerald}0}&{\color{Emerald}7}&{\color{Emerald}5}, \\
    &&30&0&9&0
    &\}
\end{array}

But actually this requires too many TeX commands — couldn't it be done simplier? And this solution does not highlight pluses between columns. I want these pluses to be separators so that numeric substitutions be more clear throughout my solution.

Best Answer

The array package allows for inserting tokens at the start of cells:

\documentclass{article}
\usepackage{array}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

\begin{document}

$
\def\mycolor{}
\newcolumntype{R}{>{\mycolor}r}
\newcolumntype{C}{>{\mycolor}c}
\newcolumntype{L}{>{\mycolor}l}
\begin{array}{RCC@{\mycolor{}+{}}C@{\mycolor{}+{}}C@{\mycolor{}+{}}CL}
  solution&=&\min\{
    &0&34&0&6, \\
    &&0&23&5&18, \\
    &&5&15&10&16, \\
    &&10&10&9&10, \\
    &&19&5&10&16, \\
\noalign{\gdef\mycolor{\color{Emerald}}} % the next row will be colored
    &&23&0&7&5, \\
\noalign{\gdef\mycolor{}} % the next row won't be colored
    &&30&0&9&0
    &\}
\end{array}
$

\end{document}

enter image description here