I've used this code I found somewhere to typeset literally hundreds of augmented matrices, and it's been amazing:
\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{arydshln}
\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}}
\makeatother
\begin{document}
\(\begin{bmatrix}[ccc:c]
1&2&3&0 \\
4&5&6&0 \\
7&8&9&0 \\
\end{bmatrix}\)
\end{document}
My TeX and LaTeX skills are, um, fledgling. But I'm doing my best to learn.
However, I'm having trouble figuring out exactly how the redefined matrix command as above works. Here's my best guess. Can you correct me and/or fill in the gaps?
\makeatletter
: The@
character by default entails some special significance and this command temporarily removes that special significance.\renewcommand*
: This is for redefining an existing macro. The starred variation here prevents the accidental inclusion of multiple paragraphs (\n\n
or\par
) when the macro is used.\env@matrix
: This is the command we're renewing, presumably. Is it defined somewhere inamsmath
? Does it really have an@
symbol in its name?[1]
: This means the newly renewed command takes one optional argument.[*\c@MaxMatrixCols c]
: I don't know what the*
at the beginning of this does.\c
(afaik) is for doing cedillas, but that doesn't seem to fit here.MaxMatrixCols
is a variable defined inamsmath
that's 10 by default, are we doing some math with it here? Or re-setting it? Or what? The finalc
I also have no idea about. In fact, what is this entire construction? Is it some pattern matching for the optional parameter?{%
: The clever use of a comment here is presumably to ignore the newline. However, I don't see any difference in the spacing without it.\hskip -\arraycolsep
: This is a backspace by the amount of\arraycolsep
\let\@ifnextchar\new@ifnextchar
: This is shadowing the command\@ifnextchar
or something, but why? Neither\@ifnextchar
or\new@ifnextchar
seem to be used.\array{#1}}
: This inserts a raw array, and passes along the parameter. I'm unsure if#1
here refers to the optional[ccc:c]
specification, or the actual contents of the matrix.\makeatother
: This presumably returns the@
symbol to its normal status.