# how to change color of matrix bracket

How can I change the color of bracket in following matrix.

\begin{bmatrix} 1 & 0.5 \end{bmatrix}


I want entries in black while [ ] in red. Is it possible to do it using bmatrix

Here I provide bmatrixcolor with an optional argument for the color. EDITED to save the pre-existing color, rather than returning to black, using the xcolor feature . to refer to the current color. In this way, the matrix data will be set in the prevailing color.

\documentclass{article}

\usepackage{amsmath,xcolor}
\newenvironment{bmatrixcolor}[1][red]
{\colorlet{savethecolor}{.}\colorlet{bracecolor}{#1}%
\color{bracecolor}\left[\color{savethecolor}\begin{matrix}}
{\end{matrix}\color{bracecolor}\right]}

\begin{document}
$\begin{bmatrix} 1 & 0.5 \end{bmatrix}$
$\begin{bmatrixcolor} 1 & 0.5 \end{bmatrixcolor}$
$\begin{bmatrixcolor}[blue] 1 & 0.5 \end{bmatrixcolor}$
\color{red}
$x =\begin{bmatrixcolor}[blue] 1 & 0.5 \end{bmatrixcolor}\!^T$
\end{document}


• You saved me an answer. The last color setting is not necessary, though. – egreg Sep 14 '16 at 16:30