![如何將評估的參考文獻輸入到此排序例程中?](https://rvso.com/image/298810/%E5%A6%82%E4%BD%95%E5%B0%87%E8%A9%95%E4%BC%B0%E7%9A%84%E5%8F%83%E8%80%83%E6%96%87%E7%8D%BB%E8%BC%B8%E5%85%A5%E5%88%B0%E6%AD%A4%E6%8E%92%E5%BA%8F%E4%BE%8B%E7%A8%8B%E4%B8%AD%EF%BC%9F.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
來擴充\ref
in \sortitem
。但是,這只能\ref
在定義一次並且僅在建立 .aux 檔案之後完成。因此,以下是執行後的輸出第二次運行:
在此期間第一次運行這將顯示為:
筆記:
- 為了允許使用,
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}