# ! Package amsmath Error: \tag not allowed here

I want to use \tag in my LaTex file at https://www.sharelatex.com/.

For example, I want to do:

If $x \equiv x' \pmod{N}$ and $y \equiv y' \pmod{N}$, then: $xy \equiv x'y' \pmod{N}\tag{Substitution rule}$.


I look at a previous question on this website, \numcases with \tag, and found the answer insufficient for my problem.

I still get the ! Package amsmath Error: \tag not allowed here. error even though I am only importing the following:

\usepackage{textcomp,geometry,graphicx,hyperref,empheq}


I have two questions:

(1) Why does the amsmath package cause an error when \tag is used?
(2) How do I add customized tags to my equations without causing errors?

EDIT:

This is a made-up example as requested:

Now solve for $E[X]$:\newline

\hspace{30pt} $E[X] = 1 + E[X] - p \cdot E[X]$\newline

\hspace{30pt} $0 = 1 - p \cdot E[X]\tag{"xyz"}$\newline

\hspace{30pt} $p \cdot E[X] = 1\tag{"xyy"}$\newline

\hspace{30pt} $E[X] = \frac{1}{p}\tag{"xzy"}$\newline\newline


Note the \tag parts were added in afterwards because they caused errors.

Then I want to say, based on "xyz" and "xyy", I can prove "abc".

• I would guess it's because you're using it in inline math. 'Numbering' inline math seems weird to me. What exactly do you want to do? As it stands it looks like you may just as well use \text or write Substitution rule outside the math. Sep 9, 2013 at 8:48
• @TorbjørnT. This is just an example, but I have other non-inline equations I want to write (e.g. equations at different points of a proof). I want to give them special \tag names like "Substitution rule". Sep 9, 2013 at 9:01
• Can you then make a complete example with a displayed equation where it doesn't work? Sep 9, 2013 at 9:04
• @TorbjørnT. Example added. Sep 9, 2013 at 9:21
• @user93172 Those are still inline equations: the fact you are making them look like display doesn't make a difference. Sep 9, 2013 at 9:25

You're still using inline math. (La)TeX distinguishes between math that is supposed be written on a line of text, delimited by $...$ or $$...$$, and displayed math, which is placed on its own paragraph.

For a single unnumbered, displayed equation you can use $...$, for a numberered equation there is $$...$$. For sets of equations, or multiline equations, amsmath provides several environment, including align and gather, as well as the starred forms align* and gather* that are unnumbered.

Displayed equations are by default centered, to make them left-aligned add fleqn as an option to amsmath or the document class, e.g. \usepackage[fleqn]{amsmath}.

For more information about amsmath, read the manual. For math typesetting in general, you could take a look at Herbert Voss' Mathmode.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
Now solve for $E[X]$:
\begin{gather}
E[X] = 1 + E[X] - p \cdot E[X] \\
0 = 1 - p \cdot E[X]\tag{"xyz"} \\
p \cdot E[X] = 1\tag{"xyy"} \\
E[X] = \frac{1}{p}\tag{"xzy"}
\end{gather}

Now solve for $E[X]$:
\begin{align}
E[X] &= 1 + E[X] - p \cdot E[X] \\
0 &= 1 - p \cdot E[X]\tag{"xyz"} \\
p \cdot E[X] &= 1\tag{"xyy"} \\
E[X] &= \frac{1}{p}\tag{"xzy"}
\end{align}
\end{document}

• Thank you for clearing up my confusion about inline vs. non-inline text! Thank you for the detailed rewriting of my code, which is an excellent example for me to work off of! Sep 9, 2013 at 9:46

These are still inline equations. You need to use

$formula$


of

$$formula$$


• \end{formula} --> . Sep 9, 2013 at 9:28
• I recently got the "\tag not allowed here" error when I put a \tag inside $...$; but I was able to get the \tag to work inside $$...$$, so it was no big deal. I was using a lot of packages; is this a known incompatibility?
• @MSC In short, the two are not equivalent; $...$ is equivalent to \begin{displaymath}...\end{displaymath} and neither create equation numbers. For an excellent explanation, look at this very thorough answer. Oct 20, 2017 at 11:07