For a report I need to print some sparse matrices as full matrices, so that means that there are a lot of zeroes. If I print them in the same color as the meaningful entries, it doesn't look very organized. And when I don't print the zeroes at all, it also doesn't look that good. So I'd like to print the zeroes in a lighter color.
Of course I could define a color (e.g. \definecolor{lightgrey}{RGB}{200,200,200}, and then for each 0 write \textcolor{lightgrey}{0}. But this is not very efficient. It is also possible to define a new command, preferably with a short name, that just inserts the grey colored 0. But I wonder, is there another, cleaner way to accomplish this?
MWE for a relatively small matrix:
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
\begin{align}
\left(\begin{array}{ccccccccc}
1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & \frac{1}{2} & \frac{1}{2} & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & \frac{1}{2} & \frac{1}{2} & 0 & 0 & 0\\
0 & 0 & 0 & \frac{1}{2} & 0 & 0 & \frac{1}{2} & 0 & 0\\
0 & 0 & 0 & 0 & \frac{1}{2} & 0 & 0 & \frac{1}{2} & 0\\
0 & 0 & 0 & 0 & \frac{1}{4} & \frac{1}{4} & 0 & \frac{1}{4} & \frac{1}{4}
\end{array}\right)
\end{align}
\end{document}


\newcommand{\0}{\textcolor{lightgrey}{0}}and then\0for the matrix entry you want in grey. – egreg Apr 24 '12 at 10:17amsmathpackage, you can replace\left(\begin{array}{ccccccccc}with\begin{pmatrix}and\end{array}\right)with\end{pmatrix}. Besides simplifying the input code, you get better spacing of the parentheses surrounding the array. – Mico Apr 24 '12 at 10:34amsmathhas the counter parameterMaxMatrixCols, whose default value is10. (The matrix in your example has 9 columns.) If need be, this parameter can be reset rather easily to a larger number, e.g.,\setcounter{MaxMatrixCols}{30}. – Mico Apr 24 '12 at 11:59