TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I found this macro from Voss' Math mode v2.47, page 21:

    \def\cr{\crcr\noalign{\kern 2\p@\global\let\cr\endline }}%
    \ialign {$##$\hfil\kern 2\p@\kern\@tempdima & \thinspace %
    \hfil $##$\hfil && \quad\hfil $##$\hfil\crcr\omit\strut %
    \hfil\crcr\noalign{\kern -\baselineskip}#2\crcr\omit %
    $\kern\wd\@ne\kern -\@tempdima\left\@firstoftwo#1%
      \if@borderstar\kern2pt\else\kern -\wd\@ne\fi%
    \global\setbox\@ne\vbox{\box\@ne\if@borderstar\else\kern 2\p@\fi}%
    \vcenter{\if@borderstar\else\kern -\ht\@ne\fi%
      \if@borderstar\kern-2\@tempdima\kern2\p@\else\,\fi\right\@secondoftwo#1 $%
    }\null \;\vbox{\kern\ht\@ne\box\tw@}%

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?

share|improve this question
up vote 17 down vote accepted

The definition is found in latex.ltx:

% latex.ltx, line 481:

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


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:

An inline formula $E=mc^{2}$ and some text.

An inline formula $E=mc^{2}$ and some text.

enter image description here

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:

% latex.ltx, line 6017:

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).

share|improve this answer
Very nice tutorial. Thanks. – Harish Kumar Jan 11 '14 at 0:19
Oh, I think this is a better answer to my question. : ) – Shadow Jan 19 '14 at 15:37

Macros containing @ in place of a are often found in the LaTeX kernel, so the document you need is source2e. You can also use \show to enquire about macros; thus



> \m@th=macro:
->\mathsurround \z@ .

\z@ is a kernel abbreviation for 0pt.

share|improve this answer
You could mention that \mathsurround is a primitive that by default (and almost always) is 0pt but it is used as extra space before and after all inline math. – David Carlisle Jan 10 '14 at 13:31
Thank you for the answer and the hint on how to find these macros. Vote up and accept it. : ) – Shadow Jan 10 '14 at 13:32
@Shadow quite possibly:-) – David Carlisle Jan 10 '14 at 13:36
@DavidCarlisle Oh... It's the very Carlisle. Soooo excited! You know, the developers of LaTeX2e are some kind of super stars to me. (◑ω◑) – Shadow Jan 10 '14 at 13:42
Oh several of the LaTEX developers lurk here:-) – David Carlisle Jan 10 '14 at 13:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.