
我想自訂cleveref
包中處理多個引用的方式。我想要這樣的形式(eq0, eq1, eq3, eq4)
,即逗號分隔,除非參考集形成一個完整的範圍,在這種情況下,我想要一個破折號,例如(eq0--eq3)
而不是(eq0, eq1, eq2, eq3)
。
不過我沒有使用這個\begin{equation} ... \end{equation}
環境。我使用以下宏:\newcommand{\nt}{\addtocounter{equation}{1}\tag{\theequation}}
和\begin{equation*} ... \nt \end{equation*}
.如果只是方程,我可以改用非*
-d 版本。然而,我希望堅持使用該\nt
巨集還有其他原因。
下面是一個最小的工作範例。 (抱歉,它很長,但它是我能得到的最短的!)
\documentclass[]{article}
\usepackage{amsmath,cleveref}
\newcommand{\nt}{\refstepcounter{equation}\tag{\theequation}}
\crefformat{equation}{(#2#1#3)}
\crefmultiformat{equation}{(#2#1#3}{, #2#1#3)}{, #2#1#3}{, #2#1#3)}
\crefrangeformat{equation}{(#3#1#4--#5#2#6)}
\begin{document}
\setcounter{equation}{-1}
\begin{equation}\label{0} 0\end{equation}
\begin{equation}\label{1} 1\end{equation}
\begin{equation}\label{2} 2\end{equation}
\begin{equation}\label{3} 3\end{equation}
\begin{equation}\label{4} 4\end{equation}
\begin{equation*}\nt\label{5} 5\end{equation*}
\begin{equation*}\nt\label{6} 6\end{equation*}
\begin{equation*}\nt\label{7} 7\end{equation*}
\begin{equation*}\nt\label{8} 8\end{equation*}
\begin{equation*}\nt\label{9} 9\end{equation*}
\texttt{\textbackslash cref\{0,1,3,4\}}: \cref{0,1,3,4}
%this prints the desired `(0, 1, 3, 4)`
\texttt{\textbackslash cref\{5,6,8,9\}}: \cref{5,6,8,9}
%this prints the undesired `(5--9)`
\end{document}
當我使用巨集時,似乎cleveref
不知何故不知道這不是一個完整的範圍\nt
。也許這與cleveref
查看有關環境,而不是櫃檯?
編輯。
Mico似乎建議使用\refstepcounter
並放置\nt
在之前\label
。他們沒有提供更多細節,但我還是做了上述更改。