该包cleveref
有两种类型的引用,\cref
分别用于小写和\Cref
大写。该包是否提供了定义更多类型的方法?如果没有,您如何自己定义一个?
举个例子,人们可能想要定义参考文献的缩写版本,比如代码:
\documentclass{article}
\usepackage{fontspec, amsthm, hyperref}
\usepackage[nameinlink]{cleveref}
\newtheorem{theorem}{Theorem}
% Defining \abbrcref
% Defining \abbrCref
% Defining \abbrcrefformat
% Defining \abbrCrefformat
\crefformat{theorem}{#2theorem #1#3}
\Crefformat{theorem}{#2Theorem #1#3}
\abbrcrefformat{theorem}{#2th.#1#3}
\abbrCrefformat{theorem}{#2Th.#1#3}
\begin{document}
\begin{theorem}
\label{sometheorem}
\end{theorem}
\cref{sometheorem}, \Cref{sometheorem}, \abbrcref{sometheorem}, \abbrCref{sometheorem}
\end{document}
会产生:
怎样才能做到这一点?
答案1
您可以定义一个变量引用名称,并为您可能想要缩写的交叉引用引入一个条件。
\documentclass{article}
\usepackage{fontspec, amsthm, hyperref}
\usepackage[nameinlink]{cleveref}
\newtheorem{theorem}{Theorem}
% Defining \abbrcref
% Defining \abbrCref
% Defining \abbrcrefformat
% Defining \abbrCrefformat
\newcommand{\theoremref}{\ifabbrcref th.\,\else theorem~\fi}
\newcommand{\Theoremref}{\ifabbrcref Th.\,\else Theorem~\fi}
\crefformat{theorem}{#2\theoremref#1#3}
\Crefformat{theorem}{#2\Theoremref#1#3}
\newif\ifabbrcref
\NewDocumentCommand{\genericabbrcref}{msom}{%
\begingroup\abbrcreftrue
\IfBooleanTF{#2}{%
\IfNoValueTF{#3}{#1*{#4}}{#1*[#3]{#4}}%
}{%
\IfNoValueTF{#3}{#1{#4}}{#1[#3]{#4}}%
}%
\endgroup
}
\newcommand{\abbrcref}{\genericabbrcref\cref}
\newcommand{\abbrCref}{\genericabbrcref\Cref}
\begin{document}
\begin{theorem}\label{sometheorem}
\end{theorem}
\cref{sometheorem}, \Cref{sometheorem}, \abbrcref{sometheorem}, \abbrCref{sometheorem}
\end{document}
texdoc xparse
有关 的更多信息,请参阅\NewDocumentCommand
。