4

I am preparing paper using the latest SIAM template siamart_0516.zip downloaded from http://www.siam.org/journals/auth-info.php.

I am having errors in math equations containing \tag{} command with special characters (e.g., \mathbf{}, \bar{} and etc.) in math mode. To be clear, the following code:

\documentclass[review]{siamart0516}
\usepackage{amsmath}

\begin{document}
\begin{equation}
\bar{x} = x + y
\tag{$\bar{x}$}
\label{eq:x}
\end{equation}

\end{document}

produce an error:

Package amsmath Error: \bar allowed only in math mode. \end{equation}

while using only \tag{$x$} without \bar{} works fine:

\documentclass[review]{siamart0516}
\usepackage{amsmath}

\begin{document}
\begin{equation}
\bar{x} = x + y
\tag{$x$}
\label{eq:x}
\end{equation}

\end{document}

Finally, initial non-working code using the standard article documentclass, i.e., replacing \documentclass[review]{siamart0516} with \documentclass{article} works like a charm.

Any guesses what is causing this issue and how to overcome it?

muzimuzhi Z
  • 26,474
Remis
  • 393

3 Answers3

5

Looks like a "feature" of ntheorem package

You can reproduce the error with

\documentclass{article}
\usepackage[leqno]{amsmath}

\RequirePackage[amsmath,thmmarks,hyperref]{ntheorem}%[1.33] (bad use of this argument in siam class)



\begin{document}
\begin{equation}
\bar{x} = x + y
\tag{$\bar{x}$}
\label{eq:x}
\end{equation}

\end{document}

could trace exactly where it goes wrong but I'd be tempted to simply accept the other answer and use \mbox workaround.

David Carlisle
  • 757,742
5

For very strange reasons, ntheorem, when used with the thmmarks and amsmath options, redefines \maketag@@@ (an internal command of amsmath) to do, among other things

\settowidth{\tagwidth}{$##1$}%

This is utterly wrong, because ##1 is substituted with the \tag text, which is supposed to be in text mode.

Now, what happens when you do \tag{$x$}? The \settowidth macro puts the second argument in an \hbox, so what results is \hbox{$$x$$} which is legal, because $$ in restricted horizontal mode just typesets an empty math formula, and what's measured is a text mode “x”. But $\bar{x}$ (or any other inherently math), the code \hbox{$$\bar{x}$$} tries to typeset \bar{x} in text mode, and the error is shown. Moreover, something like \tag{a*} would end up to be wrongly measured, because the width of a* in text mode is quite different from the width of $a*$.

Solution: patch the relevant command to remove the nasty $ characters.

\documentclass{article}
\usepackage[leqno]{amsmath}
\usepackage{etoolbox}

\usepackage[amsmath,thmmarks,hyperref]{ntheorem}

\patchcmd{\SetTagPlusEndMark}{$}{}{}{}
\patchcmd{\SetTagPlusEndMark}{$}{}{}{}

\begin{document}

\begin{equation}
\bar{x} = x + y
\tag{$\bar{x}$}
\label{eq:x}
\end{equation}

\end{document}

enter image description here

The same works with siamart0516.cls:

\documentclass[review]{siamart0516}
\usepackage{amsmath}

\usepackage{etoolbox}

\patchcmd{\SetTagPlusEndMark}{$}{}{}{}
\patchcmd{\SetTagPlusEndMark}{$}{}{}{}

\begin{document}

\begin{equation}
\bar{x} = x + y
\tag{$\bar{x}$}
\label{eq:x}
\end{equation}

\end{document}
egreg
  • 1,121,712
  • While @Przemysław Scherwentke \mbox workaround is the most straightforward, this one is the most comprehensive and answers both part of my question! – Remis Sep 11 '16 at 07:16
4

If it may be an aswer only for the second part of yor question, putting into \mbox seems to solve the problem:

\documentclass[review]{siamart0516}
\usepackage{amsmath}

\begin{document}
\begin{equation}
\bar{x} = x + y
\tag{\mbox{$\bar{x}$}}
\label{eq:x}
\end{equation}

\end{document}