![¿Cómo introduzco referencias evaluadas en esta rutina de clasificación?](https://rvso.com/image/298810/%C2%BFC%C3%B3mo%20introduzco%20referencias%20evaluadas%20en%20esta%20rutina%20de%20clasificaci%C3%B3n%3F.png)
A continuación se muestra un código que improvisé a partir de ejemplos encontrados en la red. Me gustaría que la rutina de lista ordenada use los resultados de la evaluación \ref en lugar de usar el argumento literal de \ref.
Desafortunadamente, esto no sucede en el orden correcto o la rutina de clasificación no recuerda los resultados de evaluar múltiples instancias de \ref.
¿Pensamientos?
\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}
Respuesta1
Puede utilizar \dtlexpandnewvalue
para expandir el \ref
in \sortitem
. Sin embargo, esto solo se puede hacer una vez que \ref
se haya definido y solo después de que se haya creado el archivo .aux. Por lo tanto, el siguiente es el resultado después desegunda carrera:
Durante elprimer intentoesto se mostrará como:
Notas:
- Para permitir el uso con,
hyperref
ahora verifico si\HyPsd@@@ref
está definido (qué hombre sehyperref
está usando) y, de ser así, lo uso\HyPsd@@@ref
en lugar de\ref
.
Código:
\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}