expl3 整数を cleveref で相互参照する

expl3 整数を cleveref で相互参照する

整数を使用して番号付きドキュメント要素を実装するとします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}

確かに、相互参照の種類は正しく記録されていますが、空白を埋める必要があるかどうかはわかりません。ただし、標準的なケースでは、空白が含まれる場合もあります...。

しかし、は で\crefを扱うのほど楽しいものではありませんが、それでもまったく見栄えがよくありません。\labeltcolorbox

これを行うより良い方法はありますか?

2e カウンターと\refstepcounter!を使用できることに留意してください。

関連情報