我正在使用 cleveref 制作“img.NN”格式的参考文献。我所在大学的说明要求在第一个参考文献中使用“img.NN”格式,并在第二个及以后的参考文献中写上“see img.NN”之类的内容。似乎 cleveref 不提供这样的功能。所以我想知道,是否有可能借助其他包自动完成此操作?
下面是 MWE,它显示了我想要的东西。
\documentclass{article}
\usepackage{cleveref}
\begin{document}
First introduction of the image \cref{fig:1}. It should look like "fig. 1" (without quotes).
\begin{figure}[htb]
\caption{\label{fig:1}The first test image}
\end{figure}
Second mention of our figure (\cref{fig:1}) after its introduction.
The reference should look like "see fig. 1" instead of "fig. 1".
\end{document}
答案1
\cref
这里有一种方法,它存储在或中使用的所有引用的出现\Cref
,并检查该引用是否已经使用过,并相应地进行分支。
使用更短的代码进行更新
\documentclass{article}
\usepackage{xparse}
\usepackage{cleveref}
\newcommand{\crefalreadyusedname}{see}
\newcommand{\Crefalreadyusedname}{See}
\ExplSyntaxOn
\seq_new:N \g_pashkoff_ref_seq
\cs_new:Nn \pashkoff_store_ref:n {%
\seq_gput_right:Nn \g_pashkoff_ref_seq {#1}%
}
\cs_new:Nn \pashkoff_redefine_crefcommand:n {%
\cs_gset_eq:cc {origcleveref#1} {#1}
\cs_gset:cpn {#1} ##1 {%
\seq_if_in:NnTF \g_pashkoff_ref_seq {##1} {% Yes, used already
\use:c{#1alreadyusedname}\ \use:c{origcleveref#1}{##1}%
}{% No, not used so far
\pashkoff_store_ref:n {##1}%
\use:c{origcleveref#1}{##1}%
}% End of \seq_if_in:NnTF
}
}
\NewDocumentCommand{\RedefineCrefCommand}{m}{%
\pashkoff_redefine_crefcommand:n{#1}%
}
\ExplSyntaxOff
\AtBeginDocument{
\RedefineCrefCommand{cref}
\RedefineCrefCommand{Cref}
}
\begin{document}
First introduction of the image \cref{fig:1}. It should look like "fig. 1" (without quotes).
\begin{figure}[htb]
\caption{The first test image}\label{fig:1}
\end{figure}
Second mention of our figure (\cref{fig:1}) after its introduction. However, \Cref{fig:1}.
The reference should look like "see fig. 1" instead of "fig. 1".
\end{document}