在 align 中嵌套子方程以及使用 cleveref

在 align 中嵌套子方程以及使用 cleveref

我正在使用带对齐的嵌套子方程的解(“环境subequationsparentequation柜台”)。我想使用cleveref由命令定义的子方程组来引用包\nextParentEquation,但最后得到的却是“??”而不是“eq.”前缀。

有谁知道该如何解决这个问题?

MWE 和图像如下。

\documentclass[a4paper,12pt,abstracton]{scrartcl}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{lmodern}

\usepackage{amsmath}

\usepackage[hidelinks]{hyperref}

\usepackage{etoolbox}

\let\theparentequation\theequation % let \theparentequation use the same definition as equation
\patchcmd{\theparentequation}{equation}{parentequation}{}{} % change every occurence of "equation" to "parentequation"
\renewenvironment{subequations}[1][]{%              optional argument: label-name for (first) parent equation
    \refstepcounter{equation}%
    %  \def\theparentequation{\arabic{parentequation}}% we patched it already
    \setcounter{parentequation}{\value{equation}}%    parentequation = equation
    \setcounter{equation}{0}%                         (sub)equation  = 0
    \def\theequation{\theparentequation\alph{equation}}% 
    \let\parentlabel\label%                           Evade sanitation performed by amsmath
    \ifx\\#1\\\relax\else\label{#1}\fi%               #1 given: \label{#1}, otherwise: nothing
    \ignorespaces
}{%
    \setcounter{equation}{\value{parentequation}}%    equation = subequation
    \ignorespacesafterend
}
\newcommand*{\nextParentEquation}[1][]{%            optional argument: label-name for (first) parent equation
    \refstepcounter{parentequation}%                  parentequation++
    \setcounter{equation}{0}%                         equation = 0
    \ifx\\#1\\\relax\else\parentlabel{#1}\fi%         #1 given: \label{#1}, otherwise: nothing
}

\usepackage{cleveref}

\setlength\parindent{0pt}

\begin{document}

\section*{Equations:}

\begin{subequations} \label{eq:1}%
    Below are two main equations divided into three sub-equations:\\
    first:
    \begin{align}
    0+1 &= 1\text{,} \tag{\ref*{eq:1}} \\
    \intertext{second:} \nextParentEquation[eq:2]
    100+100 &= 200\text{,} \label{eq:2a} \\
    \intertext{and third:}
    10000+20000 &= 30000\text{.} \label{eq:2b}
    \end{align}
\end{subequations}

\section*{References to equations:}

\texttt{cref}: \cref{eq:1} vs \texttt{ref}: eq.~(\ref{eq:1}).\\
\textbf{\texttt{cref}: \cref{eq:2}} vs \texttt{ref}: eq.~(\ref{eq:2}).\\
\texttt{cref}: \cref{eq:2a} vs \texttt{ref}: eq.~(\ref{eq:2a}).\\
\texttt{cref}: \cref{eq:2b} vs \texttt{ref}: eq.~(\ref{eq:2b}).

\end{document}

呈现问题的示例文档。

答案1

cleveref维护\cref@X@name\cref@X@nameplural交叉引用信息,X计数器名称在哪里。

如果\cref@parentequation@name没有定义,则会在编译时和??文本中显示警告。

为了获得正确的交叉引用名称,请使用

\crefname{parentequation}{equation}{equations}以及\Crefname{parentequation}{Equation}{Equations}用于小写和大写的\cref`\Cref。

\documentclass[a4paper,12pt,abstracton]{scrartcl}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{lmodern}

\usepackage{amsmath}

\usepackage[hidelinks]{hyperref}

\usepackage{etoolbox}

\let\theparentequation\theequation % let \theparentequation use the same definition as equation
\patchcmd{\theparentequation}{equation}{parentequation}{}{} % change every occurence of "equation" to "parentequation"
\renewenvironment{subequations}[1][]{%              optional argument: label-name for (first) parent equation
    \refstepcounter{equation}%
    %  \def\theparentequation{\arabic{parentequation}}% we patched it already
    \setcounter{parentequation}{\value{equation}}%    parentequation = equation
    \setcounter{equation}{0}%                         (sub)equation  = 0
    \def\theequation{\theparentequation\alph{equation}}% 
    \let\parentlabel\label%                           Evade sanitation performed by amsmath
    \ifx\\#1\\\relax\else\label{#1}\fi%               #1 given: \label{#1}, otherwise: nothing
    \ignorespaces
}{%
    \setcounter{equation}{\value{parentequation}}%    equation = subequation
    \ignorespacesafterend
}
\newcommand*{\nextParentEquation}[1][]{%            optional argument: label-name for (first) parent equation
    \refstepcounter{parentequation}%                  parentequation++
    \setcounter{equation}{0}%                         equation = 0
    \ifx\\#1\\\relax\else\parentlabel{#1}\fi%         #1 given: \label{#1}, otherwise: nothing
}

\usepackage{cleveref}

\crefname{parentequation}{equation}{equations}
\Crefname{parentequation}{Equation}{Equations}

\setlength\parindent{0pt}

\begin{document}

\section*{Equations:}

\begin{subequations} \label{eq:1}%
    Below are two main equations divided into three sub-equations:\\
    first:
    \begin{align}
    0+1 &= 1\text{,} \tag{\ref*{eq:1}} \\
    \intertext{second:} \nextParentEquation[eq:2]
    100+100 &= 200\text{,} \label{eq:2a} \\
    \intertext{and third:}
    10000+20000 &= 30000\text{.} \label{eq:2b}
    \end{align}
\end{subequations}

\section*{References to equations:}

\texttt{cref}: \cref{eq:1} vs \texttt{ref}: eq.~(\ref{eq:1}).\\
\textbf{\texttt{cref}: \cref{eq:2}} vs \texttt{ref}: eq.~(\ref{eq:2}).\\
\texttt{cref}: \cref{eq:2a} vs \texttt{ref}: eq.~(\ref{eq:2a}).\\
\texttt{cref}: \cref{eq:2b} vs \texttt{ref}: eq.~(\ref{eq:2b}).

\end{document}

相关内容