![평가된 참조를 이 정렬 루틴에 어떻게 공급합니까?](https://rvso.com/image/298810/%ED%8F%89%EA%B0%80%EB%90%9C%20%EC%B0%B8%EC%A1%B0%EB%A5%BC%20%EC%9D%B4%20%EC%A0%95%EB%A0%AC%20%EB%A3%A8%ED%8B%B4%EC%97%90%20%EC%96%B4%EB%96%BB%EA%B2%8C%20%EA%B3%B5%EA%B8%89%ED%95%A9%EB%8B%88%EA%B9%8C%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
두 번째 실행:
시첫 번째 실행이는 다음과 같이 표시됩니다.
노트:
- 와 함께 사용할 수 있도록 이제 가 정의되어 있는지(사용 중인 사람이 무엇인지 )
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}