
Ich möchte folgendes Verhalten erreichen: Wenn ein Akronym nur einmal innerhalb eines Abschnitts/Kapitels/Teils vorkommt, soll bei diesem Vorkommen nur der Langname verwendet werden. Wenn das Akronym jedoch mehr als einmal vorkommt, möchte ich dieses long-short
Verhalten.
Ich habe das folgende nicht funktionierende 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}
was ergibt:
Ich hätte jedoch erwartet/gewollt, dass in Abschnitt A eine Anzahl von 4 angegeben wird, und in Abschnitt C, dass zuerst die vollständige Beschreibung abgedruckt wird, anstattWNs
Wie kann dies zuverlässig funktionieren?
Antwort1
Die Lösung wurde von Nicola gegebenHierin diesemBeispiel:
% 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}
Um die Anzahl beispielsweise für Kapitel automatisch zurückzusetzen, verwenden Sie diesen Code (aus dem Handbuch kopiert). Notieren Sie sich den \GlsXtrEnableEntryUnitCounting
Befehl.
\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}
Ich füge dies hier nur der Vollständigkeit halber ein. Bitte bewerten Sie die Antwort im anderen Thread positiv.
Antwort2
Sie können Akronyme abschnittsspezifisch machen, indem Sie ihnen abschnittsspezifische Namen geben. Natürlich können Sie dies auch ganz einfach automatisieren:
\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}
Wenn das Akronym wn
definiert ist, werden grundsätzlich separate Akronyme für jeden Abschnitt erstellt, diese benannt s1-wn
und so weiter. Wenn das Akronym nun innerhalb von Abschnitt X aufgerufen wird, „leitet“ es um und verwendet sX-wn
. Das Ergebnis:
Natürlich wären hier noch einige Anpassungen erforderlich:
- Bisher funktioniert es nur für Abschnitte, nicht für Kapitel, aber das sollte unkompliziert sein
- Es ist so voreingestellt, dass es für bis zu 10 Abschnitte funktioniert. Sie können diese Zahl erhöhen, einen neuen Zähler einführen oder etwas .aux-file-magic anwenden, um dies zu automatisieren, sodass es für eine beliebige Anzahl von Kapiteln/Abschnitten/Unterabschnitten funktioniert.
- Außerdem sind noch einige weitere Anpassungen im Hinblick auf den Umgang mit Symbolen usw. erforderlich.
- Ich habe es
glossaries-extra
bisher noch nicht ausprobiert, da ich das nicht installiert habe. - Ich weiß nicht, wie Sie Ihre Abkürzungsliste haben möchten. Mein Vorschlag ignoriert dies daher vorerst, ebenso wie Ihre Frage.
Credits: Ein Teil meiner Lösung stammt ausHier