Como faço para alimentar referências avaliadas nesta rotina de classificação?

Como faço para alimentar referências avaliadas nesta rotina de classificação?

Abaixo está um código que reuni a partir de exemplos encontrados na rede. Gostaria que a rotina de lista classificada usasse os resultados da avaliação de \ref em vez de usar o argumento literal de \ref.

Infelizmente, isso não está acontecendo na ordem correta ou a rotina de classificação não está lembrando os resultados da avaliação de múltiplas instâncias \ref.

Pensamentos?

            \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}

Responder1

Você pode usar \dtlexpandnewvaluepara expandir o \refin \sortitem. No entanto, isso só pode ser feito depois de \refdefinido e somente após a criação do arquivo .aux. Portanto, o seguinte é a saída após osegunda corrida:

insira a descrição da imagem aqui

Durante oPrimeira corridaisso será exibido como:

insira a descrição da imagem aqui

Notas:

  • Para permitir o uso com, hyperrefagora verifico se \HyPsd@@@refestá definido (qual homem está hyperrefsendo usado) e, em caso afirmativo, uso \HyPsd@@@refem vez 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}

informação relacionada