![如何在枚举列表项中交叉引用可选参数内容?](https://linux22.com/image/471874/%E5%A6%82%E4%BD%95%E5%9C%A8%E6%9E%9A%E4%B8%BE%E5%88%97%E8%A1%A8%E9%A1%B9%E4%B8%AD%E4%BA%A4%E5%8F%89%E5%BC%95%E7%94%A8%E5%8F%AF%E9%80%89%E5%8F%82%E6%95%B0%E5%86%85%E5%AE%B9%EF%BC%9F.png)
下面,是否可以创建一个交叉引用来打印内容可选参数的“类似注释”字段\ditem
?
也就是说,我希望在引用标签时能够打印“一些大内容”(不带引号)ex:wow
。
\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{enumitem}
\declaretheoremstyle[
headfont= \sffamily\bfseries, headpunct={\sffamily\bfseries.},
postheadspace=0.5em,
notefont=\sffamily\mdseries, bodyfont=\normalfont,
]{defstyle}
\declaretheorem[
name=Examples, style=defstyle,
numberwithin=chapter,
qed=$\diamond$
]
{examples}
\counterwithin{examples}{chapter}
\newlist{pexenum}{enumerate}{1}
\setlist[pexenum,1]{%
label= \sffamily\upshape(\arabic*),
ref={\arabic*},
}
\makeatletter
\newcommand\gobblepar
{\@ifnextchar\label{\gobblepar@label}{\@ifnextchar\par{\@gobble}{}}}
\newcommand\gobblepar@label[2]{\label{#2}\gobblepar}
\makeatother
% For examples with optional ``note-like'' field:
\newcommand\ditem[1][]{\item{\sffamily\MakeUppercase#1. }\gobblepar}
\usepackage[colorlinks,linkcolor=red]{hyperref}
\usepackage{cleveref}
\usepackage{crossreftools} % <--- does this help?
\begin{document}
\chapter{The Main Thing}
\begin{examples}[some instances]\label{exs:mine}
\begin{pexenum}
\item A first example
\ditem[something big]\label{ex:wow} A surprising example.\qedhere
\end{pexenum}
\end{examples}
See \cref{ex:wow}.
\end{document}
观察确实\crtrefname{ex:wow}
如此不是做我想要做的事:它返回封闭环境的注释字段“一些实例” examples
。
答案1
解决方法是 Ulrike Fischer 在https://tex.stackexchange.com/a/303149/13492。以下是整个文档,其中包含该修复程序并检查特殊交叉引用命令是否仍然有效。
\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{enumitem}
\declaretheoremstyle[
headfont= \sffamily\bfseries, headpunct={\sffamily\bfseries.},
postheadspace=0.5em,
notefont=\sffamily\mdseries, bodyfont=\normalfont,
spacebelow=12pt
]{defstyle}
\declaretheorem[
name=Examples, style=defstyle,
numberwithin=chapter,
qed=$\diamond$
]
{examples}
\counterwithin{examples}{chapter}
\newlist{pexenum}{enumerate}{1}
\setlist[pexenum,1]{%
label= \sffamily\upshape(\arabic*),
ref={\arabic*},
}
\makeatletter
\newcommand\gobblepar
{\@ifnextchar\label{\gobblepar@label}{\@ifnextchar\par{\@gobble}{}}}
\newcommand\gobblepar@label[2]{\label{#2}\gobblepar}
\makeatother
% For examples with optional ``note-like'' field:
% Original \ditem is method of Skillmon, https://tex.stackexchange.com/a/699243/13492
% Fix: Ulrike Fischer's method, https://tex.stackexchange.com/a/303149/13492:
\makeatletter
\newcommand\ditem[1][]{\item{\sffamily\MakeUppercase#1. }%
\protected@edef\@currentlabel{#1}\gobblepar}
\makeatother
\usepackage[colorlinks,linkcolor=red]{hyperref}
\usepackage{cleveref}
\usepackage{crossreftools} % <--- does this help?
% Special cross-referencing commands to check still OK:
\crefname{examples}{Examples}{Examples}
\crefname{pexenumi}{}{} % do not use ``Item''
\crefformat{pexenumi}{\textup{(}#2#1#3\textup{)}}
\newcommand{\crefex}[2]{\hyperref[#2]{\namecref{#1}~\labelcref*{#1}~(\crtcrefcountervalue{#2})}}
\newcommand\crefexone[1]{\hyperref[#1]{\textup{Example}~\textup{(}\crtcrefcountervalue{#1}\textup{)}}}
\begin{document}
\chapter{The Main Thing}
\begin{examples}[some instances]\label{exs:mine}
\begin{pexenum}
\item\label{ex:first} A first example.
\ditem[something big]\label{ex:wow} A surprising example. \qedhere
\end{pexenum}
\end{examples}
OK: Grab the optional argument of item \cref{ex:wow} which is: \ref*{ex:wow}.
OK: \crefex{exs:mine}{ex:wow}.
OK: \crefexone{ex:first} and \crefexone{ex:wow}.
\end{document}