![評価された参照をこのソート ルーチンに入力するにはどうすればよいでしょうか?](https://rvso.com/image/298810/%E8%A9%95%E4%BE%A1%E3%81%95%E3%82%8C%E3%81%9F%E5%8F%82%E7%85%A7%E3%82%92%E3%81%93%E3%81%AE%E3%82%BD%E3%83%BC%E3%83%88%20%E3%83%AB%E3%83%BC%E3%83%81%E3%83%B3%E3%81%AB%E5%85%A5%E5%8A%9B%E3%81%99%E3%82%8B%E3%81%AB%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%82%88%E3%81%84%E3%81%A7%E3%81%97%E3%82%87%E3%81%86%E3%81%8B%3F.png)
以下は、ネット上で見つけた例から私がまとめたコードです。ソートされたリスト ルーチンでは、\ref のリテラル引数を使用するのではなく、\ref の評価結果を使用するようにしたいと思います。
残念ながら、これは正しい順序で行われていないか、ソート ルーチンが複数の \ref インスタンスの評価結果を記憶していません。
ご意見は?
\documentclass{report}
\newcounter{TableNoteCounter}
\renewcommand{\theTableNoteCounter}{\alph{TableNoteCounter}}
\newcommand{\tablenotelabel}[1]{\refstepcounter{TableNoteCounter}\alph{TableNoteCounter}\label{#1}}
\usepackage{datatool}% http://ctan.org/pkg/datatool
\newcommand{\sortitem}[2]{%
\DTLnewrow{list}%
\DTLnewdbentry{list}{label}{\ref{#1}}%
\DTLnewdbentry{list}{description}{#2}%
}
\newenvironment{sortedlist}%
{%
\DTLifdbexists{list}{\DTLcleardb{list}}{\DTLnewdb{list}}%
}%
{%
\DTLsort{label}{list}%
\begin{description}%
\DTLforeach*{list}{\theLabel=label,\theDesc=description}{%
\item[\theLabel] \theDesc
}%
\end{description}%
}
\begin{document}
\tablenotelabel{stars}
\tablenotelabel{galaxies}
\tablenotelabel{planets}
\begin{sortedlist}
\sortitem{planets}{Some planets are inhabited.}
\sortitem{galaxies}{Some galaxies are grand.}
\sortitem{stars}{All stars ``burn'' hydrogen.}
\end{sortedlist}
\end{document}
答え1
を使って\dtlexpandnewvalue
を拡張することができます。ただし、これは が定義され、.aux ファイルが作成された後にのみ実行できます。したがって、以下は が定義された後の出力です。\ref
\sortitem
\ref
2回目の実行:
間にファーストラン次のように表示されます。
ノート:
- を で使用できるようにするには、が定義されているかどうか ( 使用されている を指す)
hyperref
を確認し、定義されている場合はの代わりにを使用します。\HyPsd@@@ref
hyperref
\HyPsd@@@ref
\ref
コード:
\documentclass{report}
\usepackage{alphalph}
\usepackage{datatool}% http://ctan.org/pkg/datatool
\usepackage{hyperref}
\newcounter{TableNoteCounter}
\renewcommand{\theTableNoteCounter}{\alphalph{\value{TableNoteCounter}}}
\newcommand{\tablenotelabel}[1]{\refstepcounter{TableNoteCounter}\alphalph{\value{TableNoteCounter}}\label{#1}}
\makeatletter
\newcommand{\sortitem}[2]{%
\ifcsname r@#1\endcsname% Only expand once the \ref has been defined
\dtlexpandnewvalue% <-- Added
\fi
\DTLnewrow{list}%
\ifdefined\HyPsd@@@ref
\DTLnewdbentry{list}{label}{\HyPsd@@@ref{#1}}%
\else
\DTLnewdbentry{list}{label}{\ref{#1}}%
\fi
\DTLnewdbentry{list}{description}{#2}%
}
\makeatother
\newenvironment{sortedlist}%
{%
\DTLifdbexists{list}{\DTLcleardb{list}}{\DTLnewdb{list}}%
}%
{%
\DTLsort{label}{list}%
\begin{description}%
\DTLforeach*{list}{\theLabel=label,\theDesc=description}{%
\item[\theLabel] \theDesc
}%
\end{description}%
}
\begin{document}
\tablenotelabel{stars}
\tablenotelabel{galaxies}
\tablenotelabel{planets}
\begin{sortedlist}
\sortitem{planets}{Some planets are inhabited.}
\sortitem{galaxies}{Some galaxies are grand.}
\sortitem{stars}{All stars ``burn'' hydrogen.}
\end{sortedlist}
\end{document}