Not really a TeX answer, but might still be useful for someone.
With Emacs you can switch from LaTeX/AUCTeX to Calc mode, do matrix operations and get back.
Let's say we have a bmatrix we want to transpose
\[
\begin{bmatrix}
0 & -1 & -1 \\
-1 & -1 & 0 \\
-1 & 0 & 1 \\
1 & 0 & 0 \\
0 & 0 & -1 \\
-1 & 2 & 1
\end{bmatrix}
\]
Place the cursor inside the environment and press C-x * e
to enter Calc embedded mode
\[
\begin{pmatrix} 0 & -1 &
-1 \\ -1 & -1 & 0 \\ -1 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 0 & -1 \\ -1 & 2 & 1 \end{pmatrix}
\]
Calc understood LaTeX syntax but messed up the alignment and turned bmatrix
into a pmatrix
. We'll get back to this later on.
Press d N
to switch to normal Calc display mode, which you may find a little nicer to work on
% [calc-mode: language: nil]
\[
[ [ 0, -1, -1 ]
[ -1, -1, 0 ]
[ -1, 0, 1 ]
[ 1, 0, 0 ]
[ 0, 0, -1 ]
[ -1, 2, 1 ] ]
\]
v t
to transpose
% [calc-mode: language: nil]
\[
[ [ 0, -1, -1, 1, 0, -1 ]
[ -1, -1, 0, 0, 0, 2 ]
[ -1, 0, 1, 0, -1, 1 ] ]
\]
C-2
d L
gets us back to LaTeX syntax, C-2
is an optional prefix that formats it as a 2D matrix with the correct alignment
% [calc-mode: language: (latex 2)]
\[
\begin{pmatrix}
0 & -1 & -1 & 1 & 0 & -1 \\
-1 & -1 & 0 & 0 & 0 & 2 \\
-1 & 0 & 1 & 0 & -1 & 1
\end{pmatrix}
\]
C-x * e
disables Calc embedded mode and gets us back to normal editing. Now the only issue is that we have a pmatrix
instead of the original bmatrix
. This unfortunately is expected and documented in Calc docs... but it's trivial to fix! If you're using AucTeX just press C-u C-c C-e
inside the matrix and enter bmatrix
.
table.pl
in github.com/thruston/Numerical-macros-for-VIM