Although the new \bordermatrix command works in my document, I want to know the meaning of every parts of this code snippets. Some of these macros could be found in macros2e, however, \m@th couldn't. So, what does \m@th mean, and which documentation should I read to gain knowledge about these macros?

2 Answers
2

OK, it's just an abbreviation for \mathsurround\z@ which in turn is an abbreviation for

\mathsurround=0pt

Now, what's \mathsurround? The syntax says it's a parameter, which has a length as value. It contains the amount of blank space that's inserted at either side of an inline math formula. Let's see a simple example:

\documentclass{article}
\begin{document}
An inline formula $E=mc^{2}$ and some text.
\setlength{\mathsurround}{10pt}
An inline formula $E=mc^{2}$ and some text.
\end{document}

Such a space is, technically, a kern; it will disappear at line breaks. Why is it in TeX to begin with? Some typographers use to add some space around formulas so as to detach them visually from the rest of the type block. This is not very common, though, and I know of no document class that sets a non zero \mathsurround. Of course, nobody would set it to a big value: maybe something around at most 2pt could be a choice.

When inline math mode is used for purposes different than inserting a formula in text, it's good practice to set \mathsurround to zero for avoiding spurious spaces. Thus, in the alignment that's build for \bordermatrix, it's set to zero in order not to add those kerns if the document sets \mathsurround. The same is done by the \@tabarray macro that's used for the array environment and in many other places where math mode is used, for instance in \textsuperscript:

A point to notice is that when TeX is typesetting a math formula, it will use the value of \mathsurround that's current when the closing $ is scanned.

The usual pattern is to say

\def\something#1{$\m@th<do something with #1>$}

although this opens the door for the possibility that some macro in #1 sets \mathsurround to another value. However this would surely be bad practice: the parameter should be set once and for all by the class or in the preamble. Note that $...$ makes a group, so doing \m@th inside the formula will not influence the value of the parameter outside this group. In the case of \textsuperscript there's an additional level of braces just for this purpose.

Is using \m@th necessary? Well, I'm guilty of not using it every time it could be necessary, trusting that nobody knows about \mathsurround or sets it to a nonzero value (which, in my opinion, makes for bad typography).