title: How do you align matrices with a negative sign in mathjax?
body: <p>If you just use something like this:</p>
  
  <pre><code>\(
      \left[
          \begin{matrix}
              0 &amp;  1 &amp; 5 &amp; 2 \\
              1 &amp; -7 &amp; 1 &amp; 0 \\
              0 &amp;  0 &amp; 1 &amp; 3
          \end{matrix}
      \right]
  \)
  </code></pre>
  
  <p>the negative signs don't line up.</p>
  
  <p><a href="https://i.stack.imgur.com/TvE9r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TvE9r.png" alt="enter image description here"></a></p>
  
  <p>so what I've been doing is going through and adding in a <code>\phantom{-}</code> to offset the difference:</p>
  
  <pre><code>\(
      \left[
          \begin{matrix}
              0 &amp;  \phantom{-}1 &amp; 5 &amp; 2 \\
              1 &amp;            -7 &amp; 1 &amp; 0 \\
              0 &amp;  \phantom{-}0 &amp; 1 &amp; 3
          \end{matrix}
      \right]
  \)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/nP5UG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nP5UG.png" alt="enter image description here"></a></p>
  
  <p>That works for that one column but now the widths between the columns is different unless every column after the first one has at least one number with a negative sign. So I'm fixing that by giving them all a <code>\phantom{-}</code>:</p>
  
  <pre><code>\(
      \left[
          \begin{matrix}
              0 &amp;  \phantom{-}1 &amp; \phantom{-}5 &amp; \phantom{-}2 \\
              1 &amp;            -7 &amp; \phantom{-}1 &amp; \phantom{-}0 \\
              0 &amp;  \phantom{-}0 &amp; \phantom{-}1 &amp; \phantom{-}3
          \end{matrix}
      \right]
  \)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/GLVbg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GLVbg.png" alt="enter image description here"></a></p>
  
  <p>And that looks right to me but the way I'm doing it is extremely tedious. Is there a better way of doing this? </p>
  
  <p>Maybe I should write my own script to automate doing all that. This seems ideal to me:</p>
  
  <pre><code>&lt;matrix&gt;
      0  1 5 2;
      1 -7 1 0;
      0  0 1 3
  &lt;/matrix&gt;
  </code></pre>