
Gostaria de obter o seguinte comportamento: Se uma sigla for usada apenas uma vez dentro de uma seção/capítulo/parte, nesta ocorrência apenas o nome longo deverá ser usado. Se, no entanto, a sigla for usada mais de um, quero o long-short
comportamento.
Eu tenho o seguinte MWE que não funciona:
\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}
que produz:
Eu, no entanto, teria esperado/desejado uma contagem de 4 na seção A e na seção C, que inicialmente a descrição completa fosse impressa em vez deWNs
Como fazer isso funcionar de maneira confiável?
Responder1
A solução foi dada por Nicolaaquinissoexemplo:
% 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}
Para redefinir automaticamente a contagem, por exemplo, para capítulos, use este código (copiado do manual). Observe o \GlsXtrEnableEntryUnitCounting
comando.
\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}
Estou apenas colando isso aqui para completar. Por favor, vote a favor da resposta no outro tópico.
Responder2
Você pode tornar os acrônimos específicos da seção, fornecendo-lhes nomes específicos da seção. Claro que você poderia automatizar isso facilmente:
\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}
Basicamente, quando a sigla wn
é definida, ele cria siglas separadas para cada seção, nomeando-as s1-wn
e assim por diante. Agora, quando a sigla é chamada na seção X, ela "redireciona" e usa sX-wn
. O resultado:
É claro que isso precisaria de mais alguns ajustes:
- Até agora, só funciona para seções, não para capítulos, mas isso deve ser simples
- É conectado para funcionar em até 10 seções. Você pode aumentar esse número, introduzir um novo contador ou fazer alguma mágica .aux-file para automatizar isso para funcionar em qualquer número de capítulos/seções/subseções
- Também precisa de mais alguns ajustes para lidar com símbolos e assim por diante.
- Ainda não experimentei
glossaries-extra
, porque não o tenho instalado. - Não sei como você deseja que sua lista de abreviações apareça. Então, por enquanto, minha proposta ignora isso, assim como sua pergunta.
Créditos: Parte da minha solução foi retirada deaqui