`\cref` の `\crefstripprefix` 構造を許可する `\crefmultilabelformat` コマンド

`\cref` の `\crefstripprefix` 構造を許可する `\crefmultilabelformat` コマンド

私の質問は、より一般的な(そしてできればより明確な)定式化です。これです

パッケージ ではcleveref、複数のラベル付きオブジェクトを同時に参照する場合、マルチフォーマットコマンド を使用するか\cref、たとえば次のようにします。参照 1、2、3、または範囲フォーマットコマンドを\crefrange使用すると、参照 1~3

ラベル付けされたオブジェクトが 1a、1b、1c の場合、範囲形式を調整して\crefstripprefix共通のプレフィックスを削除できます。

\crefrangelabelformat{<type>}{#3#1#4--#5\crefstripprefix{#1}{#2}#6}

屈服する参照 1a~cの代わりに参照 1a–1c

マルチフォーマットで同様のことを実現したいのですが、参照 1a、b、c#1残念ながら、上記では が範囲の最初のラベルを表し、 が#2最後のラベルを表すのに対し、\creflabelformatコマンドはラベルを個別に設定します (プレースホルダーのみ#1が使用可能で、 と#2は上記と#3同様にハイパーリンクを調整します)。#3#6

\cref一連のラベルを持つの出力は\crefmultiformatコマンドによって調整されます。引数に現れるプレースホルダーは、一連のラベルを1つずつ表します。各ラベルを最初に変換し、コマンド「 」#1で調整する方法はありますか?\crefmultilabelformatプレースホルダーは、たとえば#1シリーズの最初のレンダリングされたラベルを表し、#2他の各ラベルを表すのでしょうか?

\documentclass{article}
\usepackage{floatrow}
\usepackage{subcaption}

\usepackage{cleveref}
\crefrangelabelformat{figure}{#3#1#4--#5\crefstripprefix{#1}{#2}#6}

\begin{document}
\begin{figure}
\ffigbox[\textwidth]{
\begin{subfloatrow}[3]
\ffigbox[\FBwidth]{\quad a \quad}{\caption{a}\label{sfig:a}}
\ffigbox[\FBwidth]{\quad b \quad}{\caption{b}\label{sfig:b}}
\ffigbox[\FBwidth]{\quad c \quad}{\caption{c}\label{sfig:c}}
\ffigbox[\FBwidth]{\quad d \quad}{\caption{d}\label{sfig:d}}
\end{subfloatrow}
}{\caption{cap}\label{fig:1}}
\end{figure} 
%

\crefrange{sfig:a}{sfig:c} % renders 1a-c, juste like I want

\cref{sfig:a,sfig:b,sfig:d} % renders 1a, 1b and 1d, and I would like 1a, b, and d.
\end{document}

答え1

\crefmultiformatこれには新しいコマンドは必要ありません。次のように、マクロを使用して最初のコンポーネントから他のコンポーネントにプレフィックス情報を渡すことで、既存のコマンドで実行できます。

\documentclass{article}
\usepackage{floatrow}
\usepackage{subcaption}

\usepackage{cleveref}
\crefrangelabelformat{figure}{#3#1#4--#5\crefstripprefix{#1}{#2}#6}

\crefmultiformat{figure}%
  {\edef\mycrefprefixinfo{#1}figs.~#2#1#3}%
  { and~#2\crefstripprefix{\mycrefprefixinfo}{#1}#3}%
  {, #2\crefstripprefix{\mycrefprefixinfo}{#1}#3}%
  {, and~#2\crefstripprefix{\mycrefprefixinfo}{#1}#3}

\begin{document}
\begin{figure}
\ffigbox[\textwidth]{
\begin{subfloatrow}[3]
\ffigbox[\FBwidth]{\quad a \quad}{\caption{a}\label{sfig:a}}
\ffigbox[\FBwidth]{\quad b \quad}{\caption{b}\label{sfig:b}}
\ffigbox[\FBwidth]{\quad c \quad}{\caption{c}\label{sfig:c}}
\ffigbox[\FBwidth]{\quad d \quad}{\caption{d}\label{sfig:d}}
\end{subfloatrow}
}{\caption{cap}\label{fig:1}}
\end{figure}

\crefrange{sfig:a}{sfig:c} % renders "1a-c", just like I want.

\cref{sfig:a,sfig:b,sfig:d} % renders "1a, b, and d", just like you want.
\end{document}

関連情報