
다음 동작을 얻고 싶습니다. 섹션/장/부분 내에서 약어가 한 번만 사용되는 경우 이 경우에는 긴 이름만 사용해야 합니다. 그러나 약어가 두 개 이상 사용되는 경우 해당 동작을 원합니다 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
% 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
. 결과:
물론 여기에는 좀 더 조정이 필요합니다.
- 지금까지는 챕터가 아닌 섹션에서만 작동하지만 간단해야 합니다.
- 최대 10개 섹션까지 작업할 수 있도록 배선되어 있습니다. 그 수를 늘리거나, 새로운 카운터를 도입하거나, .aux-file-magic을 수행하여 여러 장/섹션/하위 섹션에 대해 작동하도록 자동화할 수 있습니다.
- 또한 기호 등을 처리하려면 추가 조정이 필요합니다.
glossaries-extra
아직 설치하지 않았기 때문에 아직 시도하지 않았습니다 .- 이제 약어 목록이 어떻게 표시되기를 원하는지 모르겠습니다. 따라서 지금은 귀하의 질문과 마찬가지로 제 제안도 이를 무시합니다.
크레딧: 내 솔루션의 일부는 다음에서 가져왔습니다.여기