# mathcal inside gather environment not working

I'm trying to display a sequence of equations, plainly centred, so without any alignment you get from the align environment. I thought gather would do the job, but when I try to use mathcal, I get the error:

! LaTeX Error: \mathcal allowed only in math mode.

It works fine using align. What am I doing wrong?

Minimal code to reproduce:

\documentclass[12pt]{article}
\usepackage{a4}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\begin{align*}
p(f) &= \mathcal{N}\left(f; 0, K\right)
\end{align*}

\begin{gather}
p(f) &= \mathcal{N}\left(f; 0, K\right)
\end{gather}

\end{document}

• Remove that & in &= from within gather. – user11232 Oct 23 '15 at 14:51
• Welcome to TeX.SX! You shouldn't use & in gather. – egreg Oct 23 '15 at 14:52

For several reasons some error catching in AMS environments is awkward; this is a case. The error is not really in \mathcal; indeed, if you remove it, the first error message is

! Missing \$ inserted.


If you also remove \left and \right (that shouldn't be there to begin with), the error becomes

! Extra alignment tab has been changed to \cr.


Hmm, there's something wrong with &. And this is the real problem: the gather environment has no alignment point, so & must not be used in it.

Here's an example:

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\begin{align*}
p(f) &= \mathcal{N}(f; 0, K) \\
q(f) &= \mathcal{N}(f; K, 0) + 3
\end{align*}

\begin{gather}
p(f) = \mathcal{N}(f; 0, K) \\
q(f) = \mathcal{N}(f; K, 0) + 3
\end{gather}

\end{document}


Note that I removed \left and \right that here only do damages. I also removed the call to the a4 package that's obsolete and deprecated.

Don't use align or gather as substitutes for equation (or equation*) when you have just one formula: they're for multiline displays.

• Because of a bad interaction between hyperref and the equation environment, the hyperref documentation actually recommends using gather instead of equation. – Dan Oct 23 '15 at 18:07
• @Dan I can't agree. – egreg Oct 23 '15 at 19:25
• Then you may have spacing problems for equation if you use hyperref. These seem to be rare (I've never had the problem), but the hyperref README file does suggest substituting gather when it occurs. – Dan Oct 29 '15 at 20:10