# minted broke equation numbering in an user-defined environment

When I load the minted package between amsmath and hyperref, the equation numbering seems to be broken in an environment of mine.

\usepackage{amsmath}
\usepackage{minted}
\usepackage{hyperref}

\newenvironment{hop}[1]{\equation#1\endequation\align}{\endalign}

\begin{document}
\begin{hop}{ a + b = c }
c - a = b\\
c - b = a
\end{hop}
\end{document}


What cause that behavior? And how can I go back to the one number per line?

This behavior doesn't appear when minted is load somewhere else, but I can't load minted after hyperref because csquotes goes between, and I can't load minted before amsmath because amsmath is part of the class I need to use.
Replacing the parameter with an hard-coded formula doesn't change anything.
The problem seems to come from the equation environment, but this seems to be the most suited for my needs.

• The issue is with the lineno package. – egreg Jun 3 at 17:30
• Thanks @egreg! But can you elaborate a bit? I can't find any incompatibility between amsmath and lineno (at least not for equations numbering). – mrBen Jun 4 at 8:33

The minted package is not relevant to the issue: the problem is in how lineno redefines equation. The processing by amsmath gets confused.

Solution:

\documentclass{article}
\usepackage{amsmath}
\usepackage{lineno}

\newenvironment{hop}[1]{$$#1$$\align}{\endalign}

\begin{document}

\begin{hop}{ a + b = c }
c - a &= b+abc+de \\
c - b &= a
\end{hop}

\end{document}


I would suggest using the environ package to set this up. It interfers less with the inner environments.

\documentclass{article}

\usepackage{amsmath,environ}
\usepackage{minted}
\usepackage{hyperref}

\NewEnviron{hop}[1]{$$#1$$\begin{align}\BODY\end{align}}

\begin{document}
\begin{hop}{ a + b = c }
c - a = b\\
c - b = a
\end{hop}
\end{document}


Incidentally you have not specified any alignment points & in the body.

• About the alignment points in the body, you're right, I totally forgot them in my example. (they are present in the real document though) – mrBen Jun 3 at 12:55