词汇表:仅当在章节/部分内使用多次时才引入简称

词汇表:仅当在章节/部分内使用多次时才引入简称

我希望获得以下行为:如果首字母缩略词在节/章/部分中仅使用一次,则此时仅应使用长名称。但是,如果首字母缩略词使用多次,则我想要此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 部分和 C 部分的数量为 4,首先打印的是完整描述,而不是WNs

如何确保其可靠地工作?

答案1

Nicola 给出了解决方案这里在此例子

% 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-file-magic 来自动处理任意数量的章节/部分/小节
  3. 它还需要进一步调整来处理符号等等。
  4. 我还没有尝试过glossaries-extra,因为我没有安装它。
  5. 我不知道您希望缩写列表如何显示。所以目前我的建议忽略了这一点,您的问题也是如此。

致谢:我的解决方案部分来自这里

相关内容