[texhax] Is redefining primitives a good idea?

Barbara Beeton bnb at ams.org
Tue Apr 24 16:20:44 CEST 2012

On Sun, 22 Apr 2012, Vafa Khalighi wrote:

    As an example amsmath.sty redefines \eqno and \leqno. Would not it be
    better to define new macros rather than redefining existing primitives? and
    how one can (if a package already redefines some primitives), restore the
    original definition of the primitive? so that a primitive is really a
    primitive? as in ams math package, \eqno and \lqno become primitives not

there have been a lot of comments on
this, generally negative regarding the
desirability of redefining primitives.
i won't try to justify the practice, but
i have uncovered some reasons why it was
done, at least in the case of \eqno and

in amstex, \eqno and \leqno were not
redefined, but the handling of display
numbers was made more complicated by the
built-in handling.  from (not distributed)
documentation for amstex:

  Basically, \tag is supposed to mean \leqno or \eqno, depending on
  whether the flag \iftagsleft@ has been set.  [...]

  \tag has another slight problem, because \eqno and \leqno treat their
  arguments as math formulas, which isn't convenient when - is used as
  a hyphen; normally, it is better to have the argument treated as
  text.  We will allow the argument to be treated both ways, depending
  on the flag \ifmathtags at .  [...]

  [NOTE: TeX puts an \eqno or \leqno on a separate line unless the space
  between the tag and the formula is at least as wide as the tag
  itself, i.e., the formula plus a box twice the width of the tag
  should fit on the line.  By diddling with \tagform@, this rule could
  be changed.  For example, if the rule is that the space between the
  tag and the formula should be at least 1em (seems to be used by
  Cambridge University Press) we could

      \dimen0=\wd0 \advance\dimen0 1em \divide\dimen0 by 2
      \wd0=\dimen0 \box0 }

  Then twice the width of \tagform@{#1} would be the `real' width of
  the tag plus 1em.]

in practice among ams authors, text display
numbers are decidedly more appropriate;
perhaps if knuth had been asked in 1980 to
consider changing the handling of \eqno and
\leqno to text, things might have been
different, but it's too late for that now.

this reformatting of the equation number
as text was carried over into amsmath,
but even more forcefully.  amsmath is
more ambitious than amstex regarding the
formatting of multi-line displays, and
additional checking/changes were required
to accommodate that.  from the comments
in amsmath.dtx:

  Special handling is needed for flush-left equations. We need to
  measure the equation body (found in box 0 after we close it with
  the \egroup). Then after a fairly normal test to see if it fits
  within the available space, we need to consider overlapping into
  the displayindent area if displayindent is nonzero (as in an
  indented list). If there is an equation number we may have to shift
  it by hand to a separate line when there is not enough room;
  we can no longer take advantage of the automatic shifting provided
  by the \leqno, \eqno primitives.

since amsmath.dtx *is* distributed,
and the pdf file is included in tex live
(texdoc -l amsmath  and choose amsmath.pdf),
interested users can read the rest of the
commentary there.

in response to another comment regarding
the change to plain \pmatrix{...} to
\pmatrix ... \endpmatrix in amstex, that
got around problems with the immediate
tokenization of the argument which were
inherent when using the original definition
in complicated situations that knuth hadn't
had to deal with, but started arising when
actual examples drawn from material in ams
publications were attempted.  (this is the
same reason that \begin{...} ... \end{...}
environment syntax is more often used in
latex rather than simple commands with
arguments.)  should the command names have
been changed?  probably, but again,
hindsight is wonderful.
						-- bb

More information about the texhax mailing list