![Como faço para alimentar referências avaliadas nesta rotina de classificação?](https://rvso.com/image/298810/Como%20fa%C3%A7o%20para%20alimentar%20refer%C3%AAncias%20avaliadas%20nesta%20rotina%20de%20classifica%C3%A7%C3%A3o%3F.png)
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 \dtlexpandnewvalue
para expandir o \ref
in \sortitem
. No entanto, isso só pode ser feito depois de \ref
definido e somente após a criação do arquivo .aux. Portanto, o seguinte é a saída após osegunda corrida:
Durante oPrimeira corridaisso será exibido como:
Notas:
- Para permitir o uso com,
hyperref
agora verifico se\HyPsd@@@ref
está definido (qual homem estáhyperref
sendo usado) e, em caso afirmativo, uso\HyPsd@@@ref
em 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}