Take the 2-minute tour ×
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.

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

\makeatletter
\newif\if@borderstar
\def\bordermatrix{\@ifnextchar*{%
    \@borderstartrue\@bordermatrix@i}{\@borderstarfalse\@bordermatrix@i*}%
}
\def\@bordermatrix@i*{\@ifnextchar[{\@bordermatrix@ii}{\@bordermatrix@ii[()]}}
\def\@bordermatrix@ii[#1]#2{%
\begingroup
  \m@th\@tempdima8.75\p@\setbox\z@\vbox{%
    \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 %
    \strut\cr}}%
  \setbox\tw@\vbox{\unvcopy\z@\global\setbox\@ne\lastbox}%
  \setbox\tw@\hbox{\unhbox\@ne\unskip\global\setbox\@ne\lastbox}%
  \setbox\tw@\hbox{%
    $\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%
      \unvbox\z@\kern-\if@borderstar2\fi\baselineskip}%
      \if@borderstar\kern-2\@tempdima\kern2\p@\else\,\fi\right\@secondoftwo#1 $%
    }\null \;\vbox{\kern\ht\@ne\box\tw@}%
\endgroup
}
\makeatother

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
add comment

2 Answers 2

up vote 15 down vote accepted

The definition is found in latex.ltx:

% latex.ltx, line 481:
\def\m@th{\mathsurround\z@}

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}

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:
\DeclareRobustCommand*\textsuperscript[1]{%
  \@textsuperscript{\selectfont#1}}
\def\@textsuperscript#1{%
  {\m@th\ensuremath{^{\mbox{\fontsize\sf@size\z@#1}}}}}

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 at 0:19
    
Oh, I think this is a better answer to my question. : ) –  Shadow Jan 19 at 15:37
add comment

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

\makeatletter
\show\m@th

returns

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

\z@ is a kernel abbreviation for 0pt.

share|improve this answer
2  
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 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 at 13:32
1  
@Shadow quite possibly:-) –  David Carlisle Jan 10 at 13:36
2  
@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 at 13:42
1  
Oh several of the LaTEX developers lurk here:-) –  David Carlisle Jan 10 at 13:44
show 1 more comment

Your Answer

 
discard

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.