用語集: セクション/章/パート内で複数回使用される場合にのみ短縮名を導入する

用語集: セクション/章/パート内で複数回使用される場合にのみ短縮名を導入する

次のような動作を実現したいと考えています。セクション/章/パート内で頭字語が 1 回だけ使用されている場合、この場合は長い名前のみを使用します。ただし、頭字語が複数回使用されている場合は、このlong-short動作を実現したいと考えています。

次のような動作しない MWE があります:

\documentclass{book}
\usepackage{xparse}
\ExplSyntaxOn
\NewExpandableDocumentCommand{\fpcompare}{ m m m }
{
    % #1 = test to perform
    % #2 = text for the true case
    % #3 = text for the false case
    \fp_compare:nTF { #1 } { #2 } { #3 }
}
\ExplSyntaxOff

\usepackage[acronym,symbols,nomain,toc,sanitizesort,nogroupskip,xindy,numberedsection=autolabel]{glossaries-extra}
\setglossarystyle{super}
\setabbreviationstyle[acronym]{long-short}

\GlsXtrEnableEntryUnitCounting{acronym}{1}{section}
%\renewcommand*{\gls}{\cgls}%
%\renewcommand*{\Gls}{\cGls}%
%\renewcommand*{\glspl}{\cglspl}%
%\renewcommand*{\Glspl}{\cGlspl}%
%\renewcommand*{\GLS}{\cGLS}%
%\renewcommand*{\GLSpl}{\cGLSpl}%


\makenoidxglossaries
\newacronym{wn}{WN}{wireless network}

\glsxtrnewsymbol[description={pi},type=symbols]{symb:pi}{\ensuremath{\pi}}%


\usepackage{xstring}
\renewcommand*{\gls}[1]{%
    \IfEq{\glscategory{#1}}{acronym}{%to apply this to acronym only (and not symbols as well)
        \fpcompare{\glsentrycurrcount{#1} > 1}{\glsentrydesc{#1}}{\cgls{#1}}% fpcompare to detect how often used 
    }{%
        \cgls{#1}%
    }%
}%
\renewcommand*{\Gls}[1]{%
    \IfEq{\glscategory{#1}}{acronym}{%
        \fpcompare{\glsentrycurrcount{#1} > 1}{\Glsentrydesc{#1}}{\cgls{#1}}%
    }{%
        \cgls{#1}%
    }%
}%
\renewcommand*{\glspl}[1]{%
    \IfEq{\glscategory{#1}}{acronym}{%
        \fpcompare{\glsentrycurrcount{#1} > 1}{\glsentryplural{#1}}{\cglspl{#1}}%
    }{%
        \cglspl{#1}%
    }%
}%
\renewcommand*{\Glspl}[1]{%
    \IfEq{\glscategory{#1}}{acronym}{%
        \fpcompare{\glsentrycurrcount{#1} > 1}{\Glsentryplural{#1}}{\cglspl{#1}}%
    }{%
        \cglspl{#1}%
    }%
}%
\renewcommand*{\GLS}[1]{%
    \IfEq{\glscategory{#1}}{acronym}{%
        \fpcompare{\glsentrycurrcount{#1} > 1}{\GLSentrydesc{#1}}{\cgls{#1}}%
    }{%
        \cgls{#1}%
    }%
}%
\renewcommand*{\GLSpl}[1]{%
    \IfEq{\glscategory{#1}}{acronym}{%
        \fpcompare{\glsentrycurrcount{#1} > 1}{\GLSentryplural{#1}}{\cglspl{#1}}%
    }{%
        \cglspl{#1}%
    }%
}%

\begin{document}
    \section{A}
    \gls{wn}\\
    \glspl{wn}\\
    \glspl{wn}\\
    \glspl{wn}\\
    count: \glsentrycurrcount{wn}\\
    \gls{symb:pi}
    \section{B} 

    \glspl{wn}\\
    count: \glsentrycurrcount{wn}

    \section{C}
    \Glspl{wn}\\
    \gls{wn}\\
    count: \glsentrycurrcount{wn}
\end{document}

これにより、次のようになります。

ここに画像の説明を入力してください

しかし、私はセクションAでは4のカウントを期待していた/望んでいたし、セクションCでは最初に完全な説明が印刷されるのではなく、WNs

これを確実に動作させるにはどうすればよいでしょうか?

答え1

解決策はニコラによって提示されたこここの:

% arara: pdflatex
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage{glossaries-extra}

\makeglossaries

\GlsXtrEnableEntryCounting
 {abbreviation}% list of categories to use entry counting
 {2}% trigger value

\newabbreviation{html}{HTML}{hypertext markup language}
\newabbreviation{xml}{XML}{extensible markup language}
\newabbreviation{css}{CSS}{cascading style sheet}

\newglossaryentry{sample}{name={sample},description={sample}}

\begin{document}
This is a sample document that uses entry counting. The entry counting
has been enabled on the \texttt{abbreviation} category.
This means that abbreviations will only be added to the glossary 
if they have been used more than $n$ times, where in this 
document $n$ has been set to
\glsgetcategoryattribute{abbreviation}{entrycount}.
Entries in other categories behave as normal.


Used once: \gls{html}.

Used twice: \gls{xml} and \gls{xml}.

Used three times: \gls{css} and \gls{css} and \gls{css}.

Used once but this entry is in the ``general'' category
which doesn't have the ``entrycount'' attribute set:
\gls{sample}.

\printglossaries

\end{document}

章などのカウントを自動的にリセットするには、このコードを使用します (マニュアルからコピー)。\GlsXtrEnableEntryUnitCountingコマンドに注意してください。

\documentclass{report}  
\usepackage{glossaries-extra}  
\GlsXtrEnableEntryUnitCounting{abbreviation}{2}{chapter}  
\makeglossaries  
\newabbreviation{html}{HTML}{hypertext markup language}  
\newabbreviation{css}{CSS}{cascading style sheet}  
\newglossaryentry{sample}{name={sample},description={sample}}  
\begin{document}  
\chapter{Sample}  
Used once: \gls{html}.  
Used three times: \gls{css} and \gls{css} and \gls{css}.  
Used once: \gls{sample}.  
\chapter{Another Sample}  
Used once: \gls{css}.  
Used twice: \gls{html} and \gls{html}.  
\printglossaries  
\end{document} 

完全を期すためにここに貼り付けておきますので、他のスレッドの回答に賛成票をお願いします。

答え2

セクション固有の名前を付けることで、頭字語をセクション固有のものにすることができます。もちろん、これを簡単に自動化することもできます。

\documentclass{book}
\usepackage[xindy,style=long,numberline,savewrites=true,acronym,nomain]{glossaries}
\usepackage{pgffor}

\makeglossaries
\glsenableentrycount 

%create a separate acrony for each section
\let\oldnewacronym\newacronym   \renewcommand{\newacronym}[3]{\foreach \n in {0,...,10}{\oldnewacronym{c\n-#1}{#2}{#3}}}

%%patch all the commands to use the within-section version of the acronym
\let\oldcgls\cgls \renewcommand{\cgls}[1]{\oldcgls{s\arabic{section}-#1}}
\let\oldcglspl\cglspl \renewcommand{\cglspl}[1]{\oldcglspl{s\arabic{section}-#1}}
\let\oldcGlspl\cGlspl \renewcommand{\cGlspl}[1]{\oldcGlspl{s\arabic{section}-#1}}

\newacronym{wn}{WN}{wireless network}

\begin{document}
        \section{A}
        \cgls{wn}\\
        \cglspl{wn}\\
        \cglspl{wn}\\
        \cglspl{wn}\\
        count: \glsentrycurrcount{s1-wn}\\

        \section{B} 
        \cglspl{wn}\\
        count: \glsentrycurrcount{s2-wn}

        \section{C}
        \cGlspl{wn}\\
        \cgls{wn}\\
        count: \glsentrycurrcount{s3-wn}            
\end{document}

基本的に、頭字語wnが定義されると、セクションごとに個別の頭字語が作成され、名前が付けs1-wnられます。これで、セクション X 内で頭字語が呼び出されると、「リダイレクト」されて が使用されますsX-wn。結果:

ここに画像の説明を入力してください

もちろん、これにはさらに調整が必要です。

  1. 今のところ、章ではなくセクションでしか機能しませんが、それは簡単なはずです
  2. 最大 10 のセクションで動作するようにハードワイヤードされています。この数を増やしたり、新しいカウンターを導入したり、.aux ファイルマジックを使用してこれを自動化して、任意の数の章/セクション/サブセクションで動作するようにすることができます。
  3. また、シンボルなどを処理するためにさらに調整が必要です。
  4. glossaries-extraまだインストールしていないので試していません。
  5. 略語のリストをどのように表示したいのかわかりません。そのため、現時点では、私の提案では、あなたの質問と同様に、これを無視します。

クレジット: 私の解決策の一部は以下から引用しましたここ

関連情報