2

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}

enter image description here

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
1

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]{\begin{equation}#1\end{equation}\align}{\endalign}

\begin{document}

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

\end{document}
1

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

Sample output

\documentclass{article}

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

\NewEnviron{hop}[1]{\begin{equation}#1\end{equation}\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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.