# Incompatibility between lineno and equation*

In addition to a lot of others incompatibilities, also there is one between lineno and equation*.

Is there any chance to have the lineno package updated to solve this problem? Does anybody here knows if the maintainers would work on it?

MWE

\documentclass{report}
\usepackage{amsmath}
\usepackage{lineno}

\begin{document}\linenumbers
This is the first line. Here comes a numbered equation:
$$\label{eq.1} a=b$$ and here is the first line after equation~\eqref{eq.1}.

New paragraph here and now comes a stared \texttt{equation} environment:
\begin{equation*}\label{eq.2}
c=d
\end{equation*}
and here is the line after the unumbered equation.

Finally, last paragraph with a display math environment:
$e=f$ and the last line. Bye!
\end{document}


• The incompatibility is somehow stated in the documentation of lineno – user31729 Apr 7 '15 at 8:45
• Yes, and a workaround also. Put your math stuff in a linenomsth environment, iirc. – JPi Apr 7 '15 at 11:01
• @JPi: As far as I know this is exactly what does not work for amsmath's equation* environment – user31729 Apr 7 '15 at 17:14

You can automate this correction around the equation* environment:

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

\expandafter\let\expandafter\oldequation\csname equation*\endcsname
\expandafter\let\expandafter\endoldequation\csname endequation*\endcsname

\def\lneq{\linenomath\oldequation}
\def\endlneq{\endoldequation\endlinenomath}
\renewenvironment{equation*}{%
\ifLineNumbers
\let\mathenvironment\lneq
\let\endmathenvironment\endlneq
\else
\let\mathenvironment\oldequation
\let\endmathenvironment\endoldequation
\fi
\begin{mathenvironment}}
{\end{mathenvironment}}

\begin{document}
\linenumbers
This is the first line. Here comes a numbered equation:
$$\label{eq.1} a=b$$
and here is the first line after equation~\eqref{eq.1}.

New paragraph here and now comes a stared \texttt{equation} environment:
\begin{equation*}\label{eq.2}
c=d
\end{equation*}
and here is the line after the unumbered equation.

Finally, last paragraph with a display math environment:
$e=f$
and the last line. Bye!
\end{document}

• This could be inserted in a new version of the package. Thanks. – Sigur Sep 5 '15 at 11:35

This works fine for me:

\documentclass{report}
\usepackage{amsmath}
\usepackage{lineno}

\begin{document}\linenumbers
This is the first line. Here comes a numbered equation:
\begin{linenomath}
$$\label{eq.1} a=b$$
\end{linenomath}
and here is the first line after equation~\eqref{eq.1}.

New paragraph here and now comes a stared \texttt{equation} environment:
\begin{linenomath}
\begin{equation*}\label{eq.2}
c=d
\end{equation*}
\end{linenomath}
and here is the line after the unumbered equation.

Finally, last paragraph with a display math environment:
$e=f$ and the last line. Bye!
\end{document}

• Yes, you are right. It works for me also. But it would be nice to have a new version of the package solving this problem. – Sigur Apr 7 '15 at 18:47

With my setup, @Werner's solution works but inserts an extraneous space at the beginning of the line following the \end{equation*}. The following code, based on his answer, seems to work for me:

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

\expandafter\let\expandafter\oldequationstar\csname equation*\endcsname
\expandafter\let\expandafter\endoldequationstar\csname endequation*\endcsname

\expandafter\def\csname equation*\endcsname{%
\ifLineNumbers%
\expandafter\linenomath%
\fi%
\oldequationstar%
}

\expandafter\def\csname endequation*\endcsname{%
\endoldequationstar%
\ifLineNumbers%
\def\maybeendlinenomath{\expandafter\endlinenomath}%
\else
\def\maybeendlinenomath{}%
\fi%
\expandafter\maybeendlinenomath%
}
\begin{document}
\linenumbers
This is the first line. Here comes a numbered equation:
$$\label{eq.1} a=b$$
and here is the first line after equation~\eqref{eq.1}.

New paragraph here and now comes a stared \texttt{equation} environment:
\begin{equation*}\label{eq.2}
c=d
\end{equation*}
and here is the line after the unumbered equation.

Finally, last paragraph with a display math environment:
$e=f$
and the last line. Bye!
\end{document}