![使用 smartef 交叉引用 expl3 整數](https://rvso.com/image/476255/%E4%BD%BF%E7%94%A8%20smartef%20%E4%BA%A4%E5%8F%89%E5%BC%95%E7%94%A8%20expl3%20%E6%95%B4%E6%95%B8.png)
expl3
假設我使用整數實現編號的文檔元素。進一步假設我想使用 交叉引用這些元素cleveref
。做這個的最好方式是什麼?
我想出了以下方法,它似乎在一些最小的測試中起作用,但似乎不是特別安全。
\documentclass{article}
\usepackage{bookmark}
\usepackage{cleveref}
\makeatletter
\ExplSyntaxOn
\int_new:N\g_my_counter_int
\keys_define:nn { my / topic thing }
{%
label .tl_set:N = \l_my_label_tl,
}
\NewDocumentCommand \topicthing { O{} m }
{
\keys_set:nn { my / topic thing } { #1 }
\phantomsection
\int_gincr:N \g_my_counter_int
#2
\my_label_set:Nn \g_my_counter_int { topic }
\label {topic:\l_my_label_tl}
}
\cs_new_protected_nopar:Nn \my_label_set:Nn
{
\edef\@currentlabel{\int_use:N #1}
\cref@constructprefix {#2} {\cref@result}
\protected@edef\cref@currentlabel{
[#2] [\int_use:N #1] [\cref@result]
\int_to_arabic:n { #1 }
}
}
\ExplSyntaxOff
\crefname{topic}{topic}{topics}
\makeatother
\begin{document}
\topicthing[label=first]{First Topic}
\topicthing[label=second]{Second Topic}
\ref{topic:first}
\ref{topic:second}
\Cref{topic:first}
\Cref{topic:second}
\end{document}
.aux
據我所知,這給出了編號cleveref
、連結等方面的目標輸出。
\relax
\providecommand\hyper@newdestlabel[2]{}
\providecommand\HyField@AuxAddToFields[1]{}
\providecommand\HyField@AuxAddToCoFields[2]{}
\providecommand\BKM@entry[2]{}
\newlabel{topic:first}{{1}{1}{}{section*.1}{}}
\newlabel{topic:first@cref}{{[topic][1][]1}{[1][1][]1}}
\newlabel{topic:second}{{2}{1}{}{section*.2}{}}
\newlabel{topic:second@cref}{{[topic][2][]2}{[1][1][]1}}
\gdef \@abspage@last{1}
當然,它正確記錄了交叉引用的類型,儘管我不知道是否應該填寫空白。但標準箱子在某些情況下也有空白...
然而,雖然不像在 a 中\cref
使用 a那樣有趣,但它仍然一點也不漂亮。\label
tcolorbox
有一個更好的方法嗎?
請注意,我知道我可以使用 2e 計數器並且\refstepcounter
!