8

When I try to compile this:

\documentclass{article}
\usepackage{amsmath}
\usepackage{nath}
\DeclareMathOperator{\argmin}{arg\,min}
\begin{document}
    \begin{equation}
        \argmin \log(\sum_{x=1}^2 x^2)
    \end{equation}
\end{document}

I get:

Test.tex:7: Limit controls must follow a math operator
Test.tex:7: Limit controls must follow a math operator

What exactly does this mean and how can I fix it?

user541686
  • 9,547

1 Answers1

10

In order for the automatic resizing of delimiters to work, nath redefines a lot of TeX internals. amsmath also defines a lot of TeX internals. Neither nath nor amsmath take into consideration that some other package might redefine the internal macros, and hence the error.

By default, \log is defined as follows:

> \log=macro:
->\mathop {\operator@font log}\nolimits .
l.3 \show\log

But, after loading amsopn (which is loaded by amsmath), we get

> \log=macro:
->\qopname \relax o{log}.
l.5 \show\log

This is the reason that the following minimal document fails:

\documentclass{article}
\usepackage{nath}
\usepackage{amsopn}

\begin{document}
$\log$
\end{document}

So, you must choose between loading amsmath and nath. For example, your minimal example can be processes without loading amsmath:

\documentclass{article}
\usepackage{nath}
\makeatletter
\def\argmin{\mathop{\operator@font arg\,min}\nolimits}
\makeatother

\begin{document}
\begin{equation}
  \argmin \log( \sum_{i=1}^2 x^2)
\end{equation}
\end{document}

Another option is to save and restore the meaning of operators like \log, \max,\arg, \sin, etc.

\documentclass{article}
\let\normallog \log
\usepackage{amsmath,nath}
\let\log \normallog
\makeatletter
\def\argmin{\mathop{\operator@font arg\,min}\nolimits}
\makeatother

\begin{document}
\begin{equation}
  \argmin \log( \sum_{i=1}^2 x^2)
\end{equation}
\end{document}

nath provides some macros for display math (\wall .. \return); some of the other packages that are part of amsmath bundle (amsgen, amstext, amsfonts) work with nath.

EDIT: It seems that nath is at fault here. nath redefines \mathop. Quoting from nath.sty:

\mathop is redefined to stop misinterpretation of following Bins as unary operators (cf. TeXbook, p. 170).

The following definition determines spacing between Op and Bin. (According to [TeXBook, p. 170], ``such case never arises, so plain TeX leaves it undefined, making the Bin into unary.'')

If you simply restore the definition of \mathop, then everything works fine:

\documentclass{article}
\usepackage{amsmath,nath}
\makeatletter
\let\mathop\o@mathop
\makeatother
\DeclareMathOperator{\argmin}{arg\,min}
\begin{document}
    \begin{equation}
        \argmin \log(\sum_{x=1}^2 x^2)
    \end{equation}
\end{document}
Aditya
  • 62,301