¿Cómo introduzco referencias evaluadas en esta rutina de clasificación?

¿Cómo introduzco referencias evaluadas en esta rutina de clasificación?

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 \dtlexpandnewvaluepara expandir el \refin \sortitem. Sin embargo, esto solo se puede hacer una vez que \refse 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:

ingrese la descripción de la imagen aquí

Durante elprimer intentoesto se mostrará como:

ingrese la descripción de la imagen aquí

Notas:

  • Para permitir el uso con, hyperrefahora verifico si \HyPsd@@@refestá definido (qué hombre se hyperrefestá usando) y, de ser así, lo uso \HyPsd@@@refen 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}

información relacionada