帶有子方程式的自動數

帶有子方程式的自動數

有沒有辦法製作包包自主數使用子方程式?在下面的範例中,引用將正確讀取 eq. 1,但方程式中沒有附加數字(我想看 1a、1b)。

\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{autonum}
\begin{document}

\begin{subequations}
    \label{eq:subequations}
    \begin{align}
        1 + 1 = 2, \\
        2 + 2 = 4
    \end{align}
\end{subequations}

Let us examine \cref{eq:subequations}.

\end{document}

答案1

這很有趣。我相信我有一個使用包appto中命令的有效解決方案etoolbox。注意,建議使用時載入hyperref套件(我也選擇使用該選項)。hypertexnames=falseautonumhidelinks

這個autonum套件只會在實際引用該方程式時產生方程式編號,因此當以靜默方式引用該環境時,我們需要一種引用子方程式環境中的所有方程式的方法。我們可以透過定義我們自己的引用命令來做到這一點,該命令帶有一個標籤並且不執行任何操作,但然後告訴 autonum 包它是帶有\autonum@generatePatchedReference包提供的宏的引用命令。

\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage[hypertexnames=false, hidelinks]{hyperref} % hypertexnames=false for autonum compatibility (autonum.pdf 3.2 Hyperref)
\usepackage{cleveref}
\usepackage{autonum}
\usepackage{etoolbox} % \appto (etoolbox.pdf 3.3 Hook management)
\newcommand\toplabel[2]{% Args: macro and label for subequations environment
\appto{#1}{(\ref{#2})}%
}
\newcommand\sublabel[2]{% Args: macro and label for a subequation
\appto{#1}{\hoaxref{#2}}% Pretend to reference this equation when #1 is called, to fool autonum
}
\newcommand\hoaxref[1]{%
% Do nothing!
}
\makeatletter
\autonum@generatePatchedReference{hoaxref} % Tell autonum about our reference command (autonum.pdf 3.3 Reference commands)
\makeatother
\begin{document}
\begin{subequations}
    \label{eq:1}
    \begin{align}
        1 + 1 &= 2 \label{eq:1a}\\
        2 + 2 &= 4\label{eq:1b}
    \end{align}
\end{subequations}
\toplabel{\referone}{eq:1}%
\sublabel{\referone}{eq:1a}%
\sublabel{\referone}{eq:1b}%

Let us examine system \referone. 
\begin{subequations}
    \label{eq:2}
    \begin{align}
        3 + 3 &= 8 \label{eq:2a}\\
        4 + 4 &= 8\label{eq:2b}
    \end{align}
\end{subequations}

For comparison, an ordinary reference to system \ref{eq:2}.
\end{document}

輸出:

輸出

使用說明:以通常的方式標記子方程式環境方程式。然後,在此環境下,設定一個巨集來引用環境,\toplabel{\myMacroName}{subeq:label}然後\sublabel{\myMacroName}{a:sub:equation}為您希望編號的每個子方程式(不必是全部子方程式!)。您將使用以下\myMacroName內容來引用子方程式環境,如範例所示。

相關內容