Change color of matrix brackets

I want to be able to change the color of a matrix brackets. I have found this answer but it is not exactly what I am looking for, since with this answer the subindex just right outside the matrix is not at the desired height. I would like to be able to write something similar to

\begin{equation*}
\begin{pmatrix}
1 \\
2 \\
-1
\end{pmatrix}_{\!\!e}
\end{equation*}


and obtain

but with a different color for the brackets (and maybe also a different color for the subindex).

• Does this answer your question? how to change color of matrix bracket – Sachchidanand Prasad Oct 26 '20 at 8:58
• @SachchidanandPrasad -- The OP mentioned, that that answer messes with the positioning of the subscript – DG' Oct 26 '20 at 11:47
• @SachchidanandPrasad It does not. As I mention in the post, I had already seen this answer, but it messes with the positioning of the subscript, as #DG' says. – Just_a_newbie Oct 26 '20 at 12:06
• @Just_a_newbie Yeah just saw that, sorry for this. – Sachchidanand Prasad Oct 26 '20 at 14:32

\documentclass{article}
\usepackage{amsmath,xcolor,environ}

\NewEnviron{pmatrixcolor}[1][red]{%
\colorlet{currentcolor}{.}%
\mathinner{\begingroup\color{#1}\left(\color{currentcolor}%
\begin{matrix}
\BODY
\end{matrix} \color{#1}\right)\endgroup}}

\begin{document}
$\begin{pmatrix} 1 \\ 2 \\ -1 \end{pmatrix} _e$

$\begin{pmatrixcolor} 1 \\ 2 \\ -1 \end{pmatrixcolor} _e$
\end{document}



• Thank you, this is exactly what I was looking for! – Just_a_newbie Oct 27 '20 at 10:40