按字母順序或每頁術語表對腳註進行排序

按字母順序或每頁術語表對腳註進行排序

我想創建一個文檔,其中詞彙表條目位於腳註的每一頁上,並且我已經能夠做到這一點(請參閱下面的 MWE),但我希望腳註註釋按字母順序排序,但我已經無法找到對腳註進行排序的方法。相反,是否有每頁詞彙表?

微量元素:

\documentclass{book}
\usepackage[nonumberlist]{glossaries}
\usepackage{xifthen}
\usepackage{everypage}
\makeglossaries

% enable counting the words
\glsenableentrycount

% reset counts every page
\AddEverypageHook{\glsresetall}

% populate some entries
\newglossaryentry{uno}{name=uno,description=one}
\newglossaryentry{dos}{name=dos,description=two}
\newglossaryentry{tres}{name=tres,description=three}
\newglossaryentry{quatro}{name=quatro,description=four}
\newglossaryentry{cinco}{name=cinco,description=five}

% displaying glossary entries
\newcommand\glossdisplay[2]{%
    \ifthenelse{\glsentrycurrcount{\glslabel} = 0}{%
        % first time we've seen this word on this page so add a footnote
        #1\let\thefootnote\relax\footnote{\textbf{\glslabel} #2}%
    }{%
        % not the first definition on this page so just display the word
        #1%
    }%
}
\renewcommand\glsdisplayfirst[4]{\glossdisplay{#1}{#2}}
\renewcommand\glsdisplay[4]{\glossdisplay{#1}{#2}}
\newcommand\gloss[2][\relax]{\glsdisp{#1}{#2}}

\begin{document}
    Counting to three in Spanish, \gloss[uno]{uno}, \gloss[dos]{dos}, \gloss[tres]{tres}.
    Counting to five in Spanish, \gloss[uno]{uno}, \gloss[dos]{dos}, \gloss[tres]{tres}, \gloss[quatro]{quatro}, \gloss[cinco]{cinco}.\\

    Notice how \gloss[uno]{uno}, \gloss[dos]{dos}, and \gloss[tres]{tres} only appear once in the footnotes despite being glossed three times.
    Now the real question: \textit{How do I sort the per-page glossary alphabetically?}  Perhaps there is a per-page option for the glossaries package?
\end{document}

在產生的文件中,腳註/術語表條目已排序

  • 烏諾
  • DOS
  • 特雷斯
  • 夸特羅
  • 辛科

但我想看看

  • 辛科
  • DOS
  • 夸特羅
  • 特雷斯
  • 烏諾

另外,如果有幫助的話,我用以下方法建立了文件:

pdflatex repro.tex
makeindex -s repro.ist -o repro.gls repro.glo
pdflatex repro.tex

答案1

這是我能得到的最接近的。我用過glossaries-extra它擴展了glossaries包並除了glossaries包的文檔範圍計數之外還提供按單元計數。這樣可以更輕鬆地計算每頁的數量。

\documentclass{book}

\usepackage{everypage}
\usepackage{glossaries-extra}

\AddEverypageHook{%
 \gdef\entrylabellist{}%
}

\GlsXtrEnableEntryUnitCounting{general}{0}{page}

\newcommand*{\entrylabellist}{}

\makeatletter
\def\@glo@sortinghandler{\@glo@sorthandler@word}%
\newcommand*{\sortpageentries}{%
 \forglsentries{\thisentry}{%
   \ifnum\glsentryprevcount{\thisentry}>0\relax
     \expandafter\@glo@sortedinsert\expandafter\entrylabellist\expandafter
       {\thisentry}%
   \fi
 }%
}

\newcommand*{\glsxtrpostlinkgeneral}{%
 \ifnum\glsentrycurrcount{\glslabel}=1\relax
   \footnotemark[1]%
   \ifdefempty\entrylabellist
   {%
     \sortpageentries
     \footnotetext[1]{\@for\thisentry:=\entrylabellist\do{%
      \glsentryname{\thisentry} \glsentrydesc{\thisentry}. }}%
   }%
   {}%
 \fi
}
\makeatother

\newglossaryentry{uno}{name=uno,description=one}
\newglossaryentry{dos}{name=dos,description=two}
\newglossaryentry{tres}{name=tres,description=three}
\newglossaryentry{quatro}{name=quatro,description=four}
\newglossaryentry{cinco}{name=cinco,description=five}


\begin{document}

Counting to three in Spanish, \gls{uno}, \gls{dos},
\gls{tres}.  Counting to five in Spanish, \gls{uno},
\gls{dos}, \gls{tres}, \gls{quatro}, \gls{cinco}.

Notice how \gls{uno}, \gls{dos}, and \gls{tres} only appear once in
the footnotes despite being glossed three times.

\newpage

Test next page.

\gls{tres}, \gls{quatro} and \gls{cinco}.
And again:
\gls{tres}, \gls{quatro} and \gls{cinco}.

\end{document}

這需要兩次 LaTeX 運行,因為它使用輔助檔案來儲存上次運行的總計數,因此腳註不會出現在第一個實例上。這不需要makeindex/xindy除非您另外想要在文件的開頭或結尾處提供完整的術語表。排序是使用 的datatool-base有序插入命令完成的,這些命令可透過\@glo@sortedinsert(由 提供glossaries)存取。這需要\@glo@sortinghandler設定為適當的比較處理程序(\@glo@sorthandler@word在本例中)。

上面的例子產生

第 1 頁頂部的圖像,在第一個實例之後帶有腳註標記

在第一頁的頂部。頁面底部的腳註顯示為

1 五五。執行二。四輪車。特雷斯三。聯合國一。

可以透過編輯行來調整格式

     \footnotetext[1]{\@for\thisentry:=\entrylabellist\do{%
      \glsentryname{\thisentry} \glsentrydesc{\thisentry}. }}%

第二頁的頂部顯示為

測試下一頁。 tres 1、quatro 1 和 cinco 1。

與註腳

1 五五。四輪車。特雷斯三。

警告:由於 TeX 的非同步輸出例程,這對於出現在跨越分頁符號的段落尾部的條目可能無法正常運作。

相關內容