lineno 和 equation 不兼容*

lineno 和 equation 不兼容*

除了许多其他不兼容性之外,lineno和之间也存在不兼容性equation*

有没有可能通过lineno更新软件包来解决这个问题?这里有人知道维护人员是否会处理这个问题吗?

平均能量损失

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

\begin{document}\linenumbers
This is the first line. Here comes a numbered equation:
\begin{equation}\label{eq.1}
a=b
\end{equation} 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}

在此处输入图片描述

答案1

您可以根据equation*环境自动进行此更正:

在此处输入图片描述

\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:
\begin{equation}\label{eq.1}
a=b
\end{equation} 
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}

答案2

这对我来说很好:

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

\begin{document}\linenumbers
This is the first line. Here comes a numbered equation:
\begin{linenomath}
\begin{equation}\label{eq.1}
a=b
\end{equation} 
\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}

答案3

使用我的设置,@Werner 的解决方案有效,但在 后面的行首插入了一个多余的空格\end{equation*}。根据他的回答,以下代码似乎对我有用:

\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:
\begin{equation}\label{eq.1}
a=b
\end{equation} 
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}

相关内容