我想創建一個文檔,其中詞彙表條目位於腳註的每一頁上,並且我已經能夠做到這一點(請參閱下面的 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
在本例中)。
上面的例子產生
在第一頁的頂部。頁面底部的腳註顯示為
可以透過編輯行來調整格式
\footnotetext[1]{\@for\thisentry:=\entrylabellist\do{%
\glsentryname{\thisentry} \glsentrydesc{\thisentry}. }}%
第二頁的頂部顯示為
與註腳
警告:由於 TeX 的非同步輸出例程,這對於出現在跨越分頁符號的段落尾部的條目可能無法正常運作。