如何將評估的參考文獻輸入到此排序例程中?

如何將評估的參考文獻輸入到此排序例程中?

以下是我根據網路上找到的範例拼湊而成的一些程式碼。我希望排序清單例程使用評估 \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來擴充\refin \sortitem。但是,這只能\ref在定義一次並且僅在建立 .aux 檔案之後完成。因此,以下是執行後的輸出第二次運行

在此輸入影像描述

在此期間第一次運行這將顯示為:

在此輸入影像描述

筆記:

  • 為了允許使用,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}

相關內容