脚注をアルファベット順またはページごとの用語集で並べ替える

脚注をアルファベット順またはページごとの用語集で並べ替える

各ページの脚注に用語集のエントリがある文書を作成したいのですが、それを実現することはできました (以下の MWE を参照)。ただし、脚注の用語をアルファベット順に並べ替えたいのですが、脚注を並べ替える方法が見つかりません。逆に、ページごとの用語集はありますか?

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}

作成された文書では、脚注/用語集のエントリがソートされます。

  • ウノ
  • する
  • トレス
  • クアトロ
  • シンコ

でも見たい

  • シンコ
  • する
  • クアトロ
  • トレス
  • ウノ

また、役に立つかどうかはわかりませんが、私は次のようにドキュメントを作成しました:

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}

これには、前回の実行からの合計カウントを保存するために補助ファイルを使用するため、2 回の LaTeX 実行が必要であり、最初のインスタンスでは脚注は表示されません。ドキュメントの先頭または末尾に完全な用語集を追加する必要がある場合を除き、 makeindex/は必要ありません。並べ替えは、 ( によって提供される)を通じてアクセスされる の順序付き挿入コマンドxindyを使用して行われます。これには、適切な比較ハンドラー (この場合は ) を設定する必要があります。datatool-base\@glo@sortedinsertglossaries\@glo@sortinghandler\@glo@sorthandler@word

上記の例では、

最初のインスタンスの後に脚注マーカーが付いたページ 1 の上部の画像

最初のページの上部に表示されます。ページの下部の脚注は次のように表示されます。

1 5. 2 2. 4 4. 3 3. 1 1。

書式は行を編集することで調整できます

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

2ページ目の上部は次のように表示されます

次のページをテストします。tres 1、quatro 1、cinco 1。そしてもう一度: tres、quatro、cinco。

脚注付き

1 5. 4 4. 3 3.

警告:TeX の非同期出力ルーチンが原因で、ページ区切りにまたがる段落の末尾にあるエントリに対しては、これが適切に機能しない可能性があります。

関連情報