I would like to add \phantom{-} to every column of a matrix that contains at least one entry with a - in front. Here is an answer that my current code is based off. It inserts \phantom{-} in front of every entry that isn't negative, but that's not really what I am looking for.
My current attempt is attached below. Notice how in an array without negatives, it inserts phantoms in front of each entry, increasing the overall width.
\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{etoolbox}
\begin{document}
[
\begin{bmatrix}
1 & 2 & 12345 \
5 & 2 & 5 \
0 & 1 & 1
\end{bmatrix}
]
% code that inserts \phantom{-}
\makeatletter
\def\env@matrix[#1]{\hskip -\arraycolsep
\let@ifnextchar\new@ifnextchar
\array{*\c@MaxMatrixCols #1}}
@tfor@temp:=\matrix\pmatrix\bmatrix\Bmatrix\vmatrix\Vmatrix\do
{\expandafter\patchcmd@temp
{\env@matrix}
{@ifnextchar[
\env@matrix{\env@matrix[C]}}
{}{\FAILED}}
\newcolumntype{C}{>{\CheckSign}c}
\def\CheckSign\ignorespaces{%
@ifnextchar-{}{@ifnextchar+{}{\phantom{-}}}}
\makeatother
[
\begin{bmatrix}
1 & 2 & 12345 \
5 & 2 & 5 \
0 & 1 & 1
\end{bmatrix}
]
\end{document}

mathtoolspackage provides a variant ofbmatrixwhere you can specify the alignment) – David Carlisle Dec 05 '20 at 12:3212,-2and1, adding the phantom-to the top entry would be too much. – egreg Dec 05 '20 at 14:10