| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2019-2025 by Jan Hajer |
| 4 |
% ----------------------------------- |
| 5 |
% |
| 6 |
% This file may be distributed and/or modified under the |
| 7 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 8 |
% of this license or (at your option) any later version. |
| 9 |
% The latest version of this license is in: |
| 10 |
% |
| 11 |
% http://www.latex-project.org/lppl.txt |
| 12 |
% |
| 13 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 14 |
% version 2005/12/01 or later. |
| 15 |
% |
| 16 |
% \fi |
| 17 |
% |
| 18 |
% \iffalse |
| 19 |
% |
| 20 |
%<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01] |
| 21 |
%<package>\ProvidesPackage{hep-acronym}[2025/09/01 v1.4 Acronyms using glossaries] |
| 22 |
%<documentation>\ProvidesFile{hep-acronym-documentation.tex}[2025/09/01 v1.4 hep-acronym documentation] |
| 23 |
% |
| 24 |
%<*documentation> |
| 25 |
\RequirePackage[l2tabu, orthodox]{nag} |
| 26 |
\documentclass{ltxdoc} |
| 27 |
|
| 28 |
\renewcommand*\theCodelineNo{\rmfamily\tstyle\footnotesize\arabic{CodelineNo}} |
| 29 |
\AtBeginEnvironment{macrocode}{\renewcommand*{\ttdefault}{clmt}} |
| 30 |
\renewcommand*{\MacroFont}{\codestyle} |
| 31 |
\AtBeginDocument{\DeleteShortVerb{\|}} |
| 32 |
\AtBeginDocument{\MakeShortVerb{\"}} |
| 33 |
\EnableCrossrefs |
| 34 |
\CodelineIndex |
| 35 |
\RecordChanges |
| 36 |
|
| 37 |
\usepackage{hologo} |
| 38 |
|
| 39 |
\usepackage[parskip,oldstyle,font=10pt]{hep-paper} |
| 40 |
\bibliography{bibliography} |
| 41 |
\acronym{PDF}{portable document format} |
| 42 |
%</documentation> |
| 43 |
|
| 44 |
%<*driver> |
| 45 |
\expandafter\newif\csname ifshort\endcsname |
| 46 |
\shortfalse |
| 47 |
\begin{document} |
| 48 |
\DocInput{hep-acronym-implementation.dtx} |
| 49 |
\end{document} |
| 50 |
%</driver> |
| 51 |
% |
| 52 |
% \fi |
| 53 |
% |
| 54 |
% \CheckSum{541} |
| 55 |
% |
| 56 |
% \CharacterTable |
| 57 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 58 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 59 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 60 |
% Exclamation \! Double quote \" Hash (number) \# |
| 61 |
% Dollar \$ Percent \% Ampersand \& |
| 62 |
% Acute accent \' Left paren \( Right paren \) |
| 63 |
% Asterisk \* Plus \+ Comma \, |
| 64 |
% Minus \- Point \. Solidus \/ |
| 65 |
% Colon \: Semicolon \; Less than \< |
| 66 |
% Equals \= Greater than \> Question mark \? |
| 67 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 68 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 69 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 70 |
% Right brace \} Tilde \~} |
| 71 |
% |
| 72 |
% \changes{v1.0}{2021/09/01}{Initial version of the style file.} |
| 73 |
% \changes{v1.1}{2022/11/01}{Bug fixes.} |
| 74 |
% \changes{v1.2}{2023/07/01}{Bug fixes.} |
| 75 |
% \changes{v1.3}{2024/11/01}{Bug fixes.} |
| 76 |
% \changes{v1.4}{2025/09/01}{Bug fixes.} |
| 77 |
% |
| 78 |
% \ifshort |
| 79 |
%<*documentation> |
| 80 |
% \fi |
| 81 |
% |
| 82 |
\GetFileInfo{hep-acronym.sty} |
| 83 |
|
| 84 |
\title{The \software{hep-acronym} package\thanks{This document corresponds to \software{hep-acronym}~\fileversion.}} |
| 85 |
\subtitle{An acronym extension for glossaries} |
| 86 |
\author{Jan Hajer \email{[email protected]}} |
| 87 |
\date{\filedate} |
| 88 |
|
| 89 |
% \ifshort |
| 90 |
\begin{document} |
| 91 |
% \fi |
| 92 |
|
| 93 |
\newgeometry{vscale=.8, vmarginratio=3:4, includeheadfoot, left=11em, marginparwidth=4.6cm, marginparsep=3mm, right=7em} |
| 94 |
|
| 95 |
\maketitle |
| 96 |
|
| 97 |
\begin{abstract} |
| 98 |
The \software{hep-acronym} package provides an acronym macro based on the \software{glossaries} package. |
| 99 |
\end{abstract} |
| 100 |
|
| 101 |
Acronyms are implemented using the \software{glossaries-extra} package \cite{glossaries-extra} which is an extension of the \software{glossaries} package \cite{glossaries} and must be loaded after the \software{hyperref} package \cite{hyperref}. |
| 102 |
It can be loaded using "\usepackage{hep-acronym}". |
| 103 |
|
| 104 |
\DescribeMacro{\acronym} |
| 105 |
The "\acronym"\meta{*}\oarg{typeset abbreviation}\marg{abbreviation}\meta{*}\marg{definition}\oarg{plural definition} macro generates the singular "\"\meta{abbreviation} and plural "\"\meta{abbreviation}"s" macros. |
| 106 |
|
| 107 |
The first star prevents the addition of an \enquote{s} to the abbreviation plural. |
| 108 |
The second star restores the \hologo{TeX} default of swallowing subsequent white space. |
| 109 |
The long form is only shown at the first appearance of these macros, later appearances generate the abbreviation with a hyperlink to the long form. |
| 110 |
Capitalisation at the beginning of paragraphs and sentences is (mostly) ensured. |
| 111 |
The long form is never used in math mode which can be exploited to enforce the short form. |
| 112 |
In order to enforce the long form use "\"\meta{abbreviation}"long". |
| 113 |
As there can be no fixed rule whether to use the long form or the short form in section headers the user is left to their own devices \eg "\glsdesc"\marg{abbreviation}, "\Glsdesc"\marg{abbreviation}. |
| 114 |
\DescribeMacro{\sentence} |
| 115 |
The "\sentence" macro ensures that the directly following abbreviation is capitalised. |
| 116 |
|
| 117 |
|
| 118 |
\DescribeMacro{\shortacronym} |
| 119 |
\DescribeMacro{\longacronym} |
| 120 |
The "\shortacronym" and "\longacronym" macros are drop-in replacements of the "\acronym" macro showing only the short or long form of their acronym. |
| 121 |
|
| 122 |
\DescribeMacro{\resetacronym} |
| 123 |
The first use form of the acronym can be enforced by resetting the acronym counter with "\resetacronym"\marg{key}. |
| 124 |
|
| 125 |
\DescribeMacro{\dummyacronym} |
| 126 |
If the acronym counter equals one at the end of the document the short form of the acronym is not introduced. |
| 127 |
Placing a "\dummyacronym"\marg{key} at the end of the document ensures that the short form is introduced. |
| 128 |
|
| 129 |
\DescribeMacro{warning} |
| 130 |
In order to reduce the number of potentially conflicting packages the \software{glossaries} package is loaded without any glossary style. |
| 131 |
In the case that the glossary should be printed additional packages must be loaded via \eg "\usepackage{glossary-list}". |
| 132 |
|
| 133 |
% \ifshort |
| 134 |
\printbibliography |
| 135 |
|
| 136 |
\end{document} |
| 137 |
% |
| 138 |
%</documentation> |
| 139 |
% \fi |
| 140 |
% |
| 141 |
% \StopEventually{ |
| 142 |
% \printbibliography |
| 143 |
% \PrintChanges |
| 144 |
% } |
| 145 |
% |
| 146 |
% \appendix |
| 147 |
% |
| 148 |
% \section{Implementation} |
| 149 |
% |
| 150 |
%<*package> |
| 151 |
% |
| 152 |
% Define a hepacronym namespace for the options using the \software{kvoptions} package \cite{kvoptions}. |
| 153 |
% \begin{macrocode} |
| 154 |
\RequirePackage{kvoptions} |
| 155 |
\SetupKeyvalOptions{ |
| 156 |
family=hepacronym, |
| 157 |
prefix=hepacronym@ |
| 158 |
} |
| 159 |
% \end{macrocode} |
| 160 |
% |
| 161 |
% \begin{macro}{hyper} |
| 162 |
% Define the "hyper" option controlling the hyperlink to the first appearance of the acronyms. |
| 163 |
% \begin{macrocode} |
| 164 |
\DeclareBoolOption[true]{hyper} |
| 165 |
% \end{macrocode} |
| 166 |
% \end{macro} |
| 167 |
% |
| 168 |
% Process options. |
| 169 |
% \begin{macrocode} |
| 170 |
\ProcessKeyvalOptions* |
| 171 |
% \end{macrocode} |
| 172 |
% |
| 173 |
% Load the base package \cite{glossaries, glossaries-extra} and set the abbreviation style. |
| 174 |
% \begin{macrocode} |
| 175 |
\PassOptionsToPackage{nostyles}{glossaries-extra} |
| 176 |
\RequirePackage{glossaries-extra} |
| 177 |
% \setabbreviationstyle{long-hyphen-short-hyphen} |
| 178 |
% \end{macrocode} |
| 179 |
% Use the entry count feature. |
| 180 |
% \begin{macrocode} |
| 181 |
\glsenableentrycount |
| 182 |
\glssetcategoryattribute{abbreviation}{entrycount}{1} |
| 183 |
% \end{macrocode} |
| 184 |
% Provide macros for older "glossaries-extra" installations. |
| 185 |
% \begin{macrocode} |
| 186 |
\AtBeginDocument{ |
| 187 |
\@ifpackageloaded{hyperref}{ |
| 188 |
\providecommand*{\glsxtrusefield}[2]{\@gls@entry@field{#1}{#2}} |
| 189 |
\providecommand*{\glsxtrsetfieldifexists}[3]{\glsdoifexists{#1}{#3}} |
| 190 |
\providecommand*{\gGlsXtrSetField}[3]{% |
| 191 |
\glsxtrsetfieldifexists{#1}{#2}{% |
| 192 |
\csgdef{glo@\glsdetoklabel{#1}@#2}{#3}% |
| 193 |
}% |
| 194 |
} |
| 195 |
% \end{macrocode} |
| 196 |
% Set hyperlinks from the abbreviation to their definition in the text. |
| 197 |
% \begin{macrocode} |
| 198 |
\glssetcategoryattribute{abbreviation}{nohyperfirst}{true} |
| 199 |
\renewcommand*{\glsdonohyperlink}[2]{{% |
| 200 |
\glsxtrprotectlinks\edef\fieldvalue{% |
| 201 |
\glsxtrusefield{\glslabel}{hastarget}% |
| 202 |
}% |
| 203 |
\ifdefstring\fieldvalue{true}{#2}{% |
| 204 |
\gGlsXtrSetField{\glslabel}{hastarget}{true}% |
| 205 |
\glsdohypertarget{#1}{#2}% |
| 206 |
}% |
| 207 |
}} |
| 208 |
}{} |
| 209 |
} |
| 210 |
% \end{macrocode} |
| 211 |
% Provide for the case that hyperref is not loaded. |
| 212 |
% \begin{macrocode} |
| 213 |
\newcommand*{\hep@disable}[1]{% |
| 214 |
\@ifpackageloaded{hyperref}{\pdfstringdefDisableCommands{#1}}{}% |
| 215 |
} |
| 216 |
% \end{macrocode} |
| 217 |
% Deactivate hyperrefs if requested. |
| 218 |
% \begin{macrocode} |
| 219 |
\ifhepacronym@hyper\else |
| 220 |
\glsdisablehyper |
| 221 |
\fi |
| 222 |
% \end{macrocode} |
| 223 |
% |
| 224 |
% \begin{macro}{\begin@sentence} |
| 225 |
% Mark the beginning of a paragraph as if it would follow a full stop using the \software{everyhook} package \cite{everyhook}. |
| 226 |
% \begin{macrocode} |
| 227 |
\PassOptionsToPackage{excludeor}{everyhook} |
| 228 |
\RequirePackage{everyhook} |
| 229 |
\newcommand*{\begin@sentence}{1001} |
| 230 |
\newcommand*{\sentence}{\spacefactor=\begin@sentence} |
| 231 |
\hep@disable{\renewcommand*\sentence{}} |
| 232 |
\PushPostHook{par}{{\sentence}} |
| 233 |
\gdef\ttl@case{\leavevmode\sentence} |
| 234 |
% \end{macrocode} |
| 235 |
% \end{macro} |
| 236 |
% |
| 237 |
% \begin{macro}{\frenchspacing} |
| 238 |
% Adjust the "\frenchspacing" macro to be compatibel with this idea. |
| 239 |
% \begin{macrocode} |
| 240 |
\def\frenchspacing{% |
| 241 |
\sfcode`\.\begin@sentence \sfcode`\?\begin@sentence |
| 242 |
\sfcode`\!\begin@sentence \sfcode`\:\begin@sentence |
| 243 |
\sfcode`\;\@m \sfcode`\,\@m |
| 244 |
} |
| 245 |
% \end{macrocode} |
| 246 |
% \end{macro} |
| 247 |
% |
| 248 |
% \begin{macro}{\hep@if@begin@of@sentence} |
| 249 |
% Provide a macro checking for the beginning of a sentence by examining the length of the preceeding space. |
| 250 |
% \begin{macrocode} |
| 251 |
\newcommand*{\hep@if@begin@of@sentence}[2]{\leavevmode\protecting{% |
| 252 |
\ifboolexpr{ test {\ifnumcomp{\spacefactor}{=}{3000}} or% |
| 253 |
test {\ifnumcomp{\spacefactor}{=}{2000}} or% |
| 254 |
test {\ifnumcomp{\spacefactor}{=}{\begin@sentence}}% |
| 255 |
}{#1}{#2}% |
| 256 |
}} |
| 257 |
% \end{macrocode} |
| 258 |
% \end{macro} |
| 259 |
% |
| 260 |
% \begin{macro}{\mathdef} |
| 261 |
% Provide a macro that allows to extend a macro definition into math mode using the \software{xparse} package \cite{xparse}. |
| 262 |
% \begin{macrocode} |
| 263 |
\RequirePackage{xparse} |
| 264 |
\ProvideDocumentCommand{\mathdef}{mO{0}m}{% |
| 265 |
\expandafter\let\csname hep@text\string#1\endcsname=#1 |
| 266 |
\expandafter\newcommand\expandafter*% |
| 267 |
\csname hep@math\string#1\endcsname[#2]{#3} |
| 268 |
\DeclareRobustCommand#1{% |
| 269 |
\ifmmode |
| 270 |
\expandafter\let\expandafter\next\csname% |
| 271 |
hep@math\string#1\endcsname% |
| 272 |
\else |
| 273 |
\expandafter\let\expandafter\next\csname% |
| 274 |
hep@text\string#1\endcsname% |
| 275 |
\fi |
| 276 |
\next |
| 277 |
}% |
| 278 |
} |
| 279 |
% \end{macrocode} |
| 280 |
% \end{macro} |
| 281 |
% |
| 282 |
% \begin{macro}{\acronym} |
| 283 |
% Define the "\acronym"\meta{*}\oarg{typeset abbreviation}\marg{abbreviation}\meta{*}\marg{definition}\oarg{plural\linebreak[4] definition} macro using the \software{xspace} \cite{xspace} and \software{amstext} \cite{amstext} packages. |
| 284 |
% \begin{enumerate}[nosep, label=\#\arabic*] |
| 285 |
% \item star for omitting the \enquote{s} in the short plural |
| 286 |
% \item optional typeset abbreviation |
| 287 |
% \item mandatory abbreviation |
| 288 |
% \item star for restoring the \hologo{TeX} default for space after text macros |
| 289 |
% \item mandatory long form |
| 290 |
% \item optional plural long form |
| 291 |
% \end{enumerate} |
| 292 |
% \begin{macrocode} |
| 293 |
\RequirePackage{xspace} |
| 294 |
\RequirePackage{amstext} |
| 295 |
\NewDocumentCommand{\acronym}{somsmo}{ |
| 296 |
\newabbreviation[ |
| 297 |
type=\acronymtype, |
| 298 |
sort=#3, |
| 299 |
\glsshortpluralkey=\IfBooleanTF{#1}{#3}{\IfNoValueTF{#2}{#3s}{#2s}}, |
| 300 |
longplural=\IfNoValueTF{#6}{#5s}{#6} |
| 301 |
]{#3}{\IfNoValueTF{#2}{#3}{#2}}{#5} |
| 302 |
% \end{macrocode} |
| 303 |
% Provide the singular acronym macro. |
| 304 |
% \begin{macrocode} |
| 305 |
\expandafter\newcommand\expandafter*\csname#3\endcsname[1][]{% |
| 306 |
\hep@if@begin@of@sentence{% |
| 307 |
\ifglsused{#3}{\cgls{#3}[##1]}{\cGls{#3}[##1]}% |
| 308 |
}{\cgls{#3}[##1]}% |
| 309 |
\ifnum\glsentrycurrcount{#3}>1\relax |
| 310 |
\IfBooleanTF{#4}{}{\@\xspace}% |
| 311 |
\else\@\xspace\fi |
| 312 |
} |
| 313 |
% \end{macrocode} |
| 314 |
% Expand the singular acronym macro in \PDF labels. |
| 315 |
% \begin{macrocode} |
| 316 |
\hep@disable{\expandafter\def\csname#3\endcsname{% |
| 317 |
\IfNoValueTF{#2}{#3}{#2} }% |
| 318 |
} |
| 319 |
% \end{macrocode} |
| 320 |
% Provide the singular acronym macro in math mode. |
| 321 |
% \begin{macrocode} |
| 322 |
\expandafter\mathdef\csname#3\endcsname{% |
| 323 |
\mathinner{\text{\glsxtrshort{#3}}}\@gls@increment@currcount{#3}% |
| 324 |
} |
| 325 |
% \end{macrocode} |
| 326 |
% Provide the plural acronym macro. |
| 327 |
% \begin{macrocode} |
| 328 |
\expandafter\newcommand\expandafter*\csname#3s\endcsname[1][]{% |
| 329 |
\hep@if@begin@of@sentence{\cGlspl{#3}[##1]}{\cglspl{#3}[##1]}% |
| 330 |
\IfBooleanTF{#4}{}{\@\xspace}% |
| 331 |
} |
| 332 |
% \end{macrocode} |
| 333 |
% Expand the plural acronym macro in \PDF labels. |
| 334 |
% \begin{macrocode} |
| 335 |
\hep@disable{\expandafter\def\csname#3s\endcsname{% |
| 336 |
\IfBooleanTF{#1}{#3}{\IfNoValueTF{#2}{#3s}{#2s}} }% |
| 337 |
} |
| 338 |
% \end{macrocode} |
| 339 |
% Provide the plural acronym macro in math mode. |
| 340 |
% \begin{macrocode} |
| 341 |
\expandafter\mathdef\csname#3s\endcsname{% |
| 342 |
\mathinner{\text{\glsxtrshortpl{#3}}}\@gls@increment@currcount{#3}% |
| 343 |
} |
| 344 |
% \end{macrocode} |
| 345 |
% Provide an enforced long form. |
| 346 |
% \begin{macrocode} |
| 347 |
\expandafter\newcommand\expandafter*\csname#3long\endcsname[1][]{% |
| 348 |
\hep@if@begin@of@sentence{\Glsdesc*{#3}[##1]}{\glsdesc*{#3}[##1]}% |
| 349 |
\IfBooleanTF{#4}{}{\@\xspace}% |
| 350 |
} |
| 351 |
% \end{macrocode} |
| 352 |
% Ensure that it works in \PDFs. |
| 353 |
% \begin{macrocode} |
| 354 |
\hep@disable{\expandafter\def\csname#3long\endcsname{#5 }} |
| 355 |
% \end{macrocode} |
| 356 |
% Provide an enforced long plural form. |
| 357 |
% \begin{macrocode} |
| 358 |
\expandafter\newcommand\expandafter*\csname#3slong\endcsname[1][]{% |
| 359 |
\hep@if@begin@of@sentence{% |
| 360 |
\Glsxtrlongpl*{#3}[##1]}{\glsxtrlongpl*{#3}[##1]% |
| 361 |
}% |
| 362 |
\IfBooleanTF{#4}{}{\@\xspace}% |
| 363 |
} |
| 364 |
% \end{macrocode} |
| 365 |
% Ensure that it works in \PDFs. |
| 366 |
% \begin{macrocode} |
| 367 |
\hep@disable{\expandafter\def\csname#3slong\endcsname{% |
| 368 |
\IfNoValueTF{#6}{#5s}{#6} }% |
| 369 |
} |
| 370 |
% \end{macrocode} |
| 371 |
% End of "\acronym". |
| 372 |
% \begin{macrocode} |
| 373 |
} |
| 374 |
% \end{macrocode} |
| 375 |
% \end{macro} |
| 376 |
% |
| 377 |
% \begin{macro}{\shortacronym} |
| 378 |
% The "\shortacronym" never expands into the long form. |
| 379 |
% \begin{macrocode} |
| 380 |
\NewDocumentCommand{\shortacronym}{somsmo}{ |
| 381 |
% \end{macrocode} |
| 382 |
% Provide the singular acronym macro. |
| 383 |
% \begin{macrocode} |
| 384 |
\expandafter\newcommand\expandafter*\csname#3\endcsname[1][]{% |
| 385 |
\IfNoValueTF{#2}{#3}{#2}\IfBooleanTF{#4}{}{\@\xspace}##1% |
| 386 |
} |
| 387 |
% \end{macrocode} |
| 388 |
% Expand the singular acronym macro in \PDF labels. |
| 389 |
% \begin{macrocode} |
| 390 |
\hep@disable{\expandafter\def\csname#3\endcsname{% |
| 391 |
\IfNoValueTF{#2}{#3}{#2} }% |
| 392 |
} |
| 393 |
% \end{macrocode} |
| 394 |
% Provide the singular acronym macro in math mode. |
| 395 |
% \begin{macrocode} |
| 396 |
\expandafter\mathdef\csname#3\endcsname{% |
| 397 |
\mathinner{\text{\IfNoValueTF{#2}{#3}{#2}}}% |
| 398 |
} |
| 399 |
% \end{macrocode} |
| 400 |
% Provide the plural acronym macro. |
| 401 |
% \begin{macrocode} |
| 402 |
\expandafter\newcommand\expandafter*\csname#3s\endcsname[1][]{% |
| 403 |
\IfBooleanTF{#1}{#3}{\IfNoValueTF{#2}{#3s}{#2s}}% |
| 404 |
\IfBooleanTF{#4}{}{\@\xspace}##1% |
| 405 |
} |
| 406 |
% \end{macrocode} |
| 407 |
% Expand the plural acronym macro in \PDF labels. |
| 408 |
% \begin{macrocode} |
| 409 |
\hep@disable{\expandafter\def\csname#3s\endcsname{% |
| 410 |
\IfBooleanTF{#1}{#3}{\IfNoValueTF{#2}{#3s}{#2s}} }% |
| 411 |
} |
| 412 |
% \end{macrocode} |
| 413 |
% Provide the plural acronym macro in math mode. |
| 414 |
% \begin{macrocode} |
| 415 |
\expandafter\mathdef\csname#3s\endcsname{% |
| 416 |
\mathinner{\text{\IfBooleanTF{#1}{#3}{\IfNoValueTF{#2}{#3s}{#2s}}}}% |
| 417 |
}% |
| 418 |
% \end{macrocode} |
| 419 |
% Ensure that long form also exists. |
| 420 |
% \begin{macrocode} |
| 421 |
\expandafter\let\csname#3long\expandafter\endcsname\csname#3\endcsname |
| 422 |
\expandafter\let\csname#3slong\expandafter\endcsname\csname#3s\endcsname |
| 423 |
% \end{macrocode} |
| 424 |
% End of "\shoracronym". |
| 425 |
% \begin{macrocode} |
| 426 |
} |
| 427 |
% \end{macrocode} |
| 428 |
% \end{macro} |
| 429 |
% |
| 430 |
% \begin{macro}{\longacronym} |
| 431 |
% The "\longacronym" never shows the abbreviated form. |
| 432 |
% \begin{macrocode} |
| 433 |
\NewDocumentCommand{\longacronym}{somsmo}{ |
| 434 |
% \end{macrocode} |
| 435 |
% Provide the singular acronym macro. |
| 436 |
% \begin{macrocode} |
| 437 |
\expandafter\newcommand\expandafter*\csname#3\endcsname[1][]{% |
| 438 |
\hep@if@begin@of@sentence{\MakeUppercase#5}{#5}% |
| 439 |
\IfBooleanTF{#4}{}{\@\xspace}##1% |
| 440 |
} |
| 441 |
% \end{macrocode} |
| 442 |
% Expand the singular acronym macro in \PDF labels. |
| 443 |
% \begin{macrocode} |
| 444 |
\hep@disable{\expandafter\def\csname#3\endcsname{#5 }} |
| 445 |
% \end{macrocode} |
| 446 |
% Provide the plural acronym macro. |
| 447 |
% \begin{macrocode} |
| 448 |
\expandafter\newcommand\expandafter*\csname#3s\endcsname[1][]{% |
| 449 |
\hep@if@begin@of@sentence{% |
| 450 |
\IfNoValueTF{#6}{\MakeUppercase#5s}{\MakeUppercase#6}% |
| 451 |
}{% |
| 452 |
\IfNoValueTF{#6}{#5s}{#6}}\IfBooleanTF{#4}{}{\@\xspace}##1% |
| 453 |
} |
| 454 |
% \end{macrocode} |
| 455 |
% Expand the plural acronym macro in \PDF labels. |
| 456 |
% \begin{macrocode} |
| 457 |
\hep@disable{\expandafter\def\csname#3s\endcsname{% |
| 458 |
\IfNoValueTF{#6}{#5s}{#6} }% |
| 459 |
} |
| 460 |
% \end{macrocode} |
| 461 |
% Ensure that long form also exists. |
| 462 |
% \begin{macrocode} |
| 463 |
\expandafter\let\csname#3long\expandafter\endcsname\csname#3\endcsname |
| 464 |
\expandafter\let\csname#3slong\expandafter\endcsname\csname#3s\endcsname |
| 465 |
% \end{macrocode} |
| 466 |
% End of "\longacronym". |
| 467 |
% \begin{macrocode} |
| 468 |
} |
| 469 |
% \end{macrocode} |
| 470 |
% \end{macro} |
| 471 |
|
| 472 |
% \begin{macro}{\acronymalternative} |
| 473 |
% Allow for alternative long text in abbreviation. |
| 474 |
% \begin{macrocode} |
| 475 |
\NewDocumentCommand{\acronymalternative}{mmsm}{% |
| 476 |
% \end{macrocode} |
| 477 |
% Store it in the "useri" field. |
| 478 |
% \begin{macrocode} |
| 479 |
\GlsXtrSetField{#1}{useri}{#4}% |
| 480 |
% \end{macrocode} |
| 481 |
% Define the acronym |
| 482 |
% \begin{macrocode} |
| 483 |
\expandafter\newcommand\expandafter*\csname#2\endcsname[1][]{% |
| 484 |
% \end{macrocode} |
| 485 |
% Redirect the relevant macros to the useri field. |
| 486 |
% \begin{macrocode} |
| 487 |
\let\hep@glsaccesslong\glsaccesslong% |
| 488 |
\let\hep@Glsaccesslong\Glsaccesslong% |
| 489 |
\let\glsaccesslong\glsuseri% |
| 490 |
\let\Glsaccesslong\Glsuseri% |
| 491 |
% \end{macrocode} |
| 492 |
% Execute abbreviation macros. |
| 493 |
% \begin{macrocode} |
| 494 |
\hep@if@begin@of@sentence{% |
| 495 |
\ifglsused{#1}{\cgls{#1}[##1]}{\cGls{#1}[##1]}% |
| 496 |
}{\cgls{#1}[##1]}% |
| 497 |
% \end{macrocode} |
| 498 |
% Undo the redirection. |
| 499 |
% \begin{macrocode} |
| 500 |
\let\glsaccesslong\hep@glsaccesslong% |
| 501 |
\let\Glsaccesslong\hep@Glsaccesslong% |
| 502 |
% \end{macrocode} |
| 503 |
% Spacing code. |
| 504 |
% \begin{macrocode} |
| 505 |
\ifnum\glsentrycurrcount{#1}>1\relax% |
| 506 |
\IfBooleanTF{#3}{}{\@\xspace}% |
| 507 |
\else\@\xspace\fi% |
| 508 |
} |
| 509 |
% \end{macrocode} |
| 510 |
% Redirect \PDF code to original acronym. |
| 511 |
% \begin{macrocode} |
| 512 |
\hep@disable{\expandafter\def\csname#2\endcsname{% |
| 513 |
\csname#1\endcsname }% |
| 514 |
} |
| 515 |
% \end{macrocode} |
| 516 |
% Redirect math macro to original acronym. |
| 517 |
% \begin{macrocode} |
| 518 |
\expandafter\mathdef\csname#2\endcsname{% |
| 519 |
\mathinner{\text{\glsxtrshort{#1}}}\@gls@increment@currcount{#1}% |
| 520 |
} |
| 521 |
% \end{macrocode} |
| 522 |
% Provie long version of acronym. |
| 523 |
% \begin{macrocode} |
| 524 |
\expandafter\newcommand\expandafter*\csname#2long\endcsname[1][]{% |
| 525 |
% \end{macrocode} |
| 526 |
% Redirect relevant macros. |
| 527 |
% \begin{macrocode} |
| 528 |
\let\hep@glsentrydesc\glsentrydesc% |
| 529 |
\let\hep@Glsentrydesc\Glsentrydesc% |
| 530 |
\renewrobustcmd*{\glsentrydesc}[1]{\@gls@entry@field{#1}{useri}}% |
| 531 |
\renewrobustcmd*{\Glsentrydesc}[1]{\@Gls@entry@field{#1}{useri}}% |
| 532 |
% \end{macrocode} |
| 533 |
% Execute relevant macro. |
| 534 |
% \begin{macrocode} |
| 535 |
\hep@if@begin@of@sentence{\Glsdesc*{#1}[##1]}{\glsdesc*{#1}[##1]}% |
| 536 |
\IfBooleanTF{#3}{}{\@\xspace}% |
| 537 |
% \end{macrocode} |
| 538 |
% Undo redefinition. |
| 539 |
% \begin{macrocode} |
| 540 |
\let\glsentrydesc\hep@glsentrydesc% |
| 541 |
\let\Glsentrydesc\hep@Glsentrydesc% |
| 542 |
} |
| 543 |
% \end{macrocode} |
| 544 |
% Provie \PDF code. |
| 545 |
% \begin{macrocode} |
| 546 |
\hep@disable{% |
| 547 |
\expandafter\def\csname#2long\endcsname{% |
| 548 |
\@Gls@entry@field{#1}{useri} % |
| 549 |
}% |
| 550 |
}% |
| 551 |
} |
| 552 |
% \end{macrocode} |
| 553 |
% \end{macro} |
| 554 |
% Silence warning if no acronyms are defined. |
| 555 |
% \begin{macrocode} |
| 556 |
\renewcommand*{\@gls@write@entrycounts}{% |
| 557 |
\immediate\write\@auxout{% |
| 558 |
\string\providecommand*{\string\@gls@entry@count}[2]{} |
| 559 |
}% |
| 560 |
\count@=0\relax |
| 561 |
\forallglsentries{\@glsentry}{% |
| 562 |
\glshasattribute{\@glsentry}{entrycount}{% |
| 563 |
\ifglsused{\@glsentry}{% |
| 564 |
\immediate\write\@auxout{% |
| 565 |
\string\@gls@entry@count{\@glsentry}{% |
| 566 |
\glsentrycurrcount{\@glsentry}% |
| 567 |
} |
| 568 |
}% |
| 569 |
}{}\advance\count@ by \@ne |
| 570 |
}{}% |
| 571 |
}% |
| 572 |
} |
| 573 |
% \end{macrocode} |
| 574 |
% \begin{macro}{\resetacronym} |
| 575 |
% \begin{macro}{\dummyacronym} |
| 576 |
% Add two macros for acronym management. |
| 577 |
% \begin{macrocode} |
| 578 |
\newcommand*{\resetacronym}[1]{\protect\glsreset{#1}} |
| 579 |
\newcommand*{\dummyacronym}[1]{\protect\glsunset{#1}} |
| 580 |
% \end{macrocode} |
| 581 |
% \end{macro} |
| 582 |
% \end{macro} |
| 583 |
% |
| 584 |
% \begin{macro}{abstract} |
| 585 |
% Adjust the "abstract" environment to reset all acronym counters. |
| 586 |
% \begin{macrocode} |
| 587 |
\@ifundefined{endabstract}{}{% |
| 588 |
\let\end@hep@abstract\endabstract% |
| 589 |
\renewcommand*\endabstract{\glsresetall\end@hep@abstract}% |
| 590 |
} |
| 591 |
% \end{macrocode} |
| 592 |
% \end{macro} |
| 593 |
% |
| 594 |
% \begin{macro}{\tableofcontents} |
| 595 |
% \begin{macro}{\listoffigures} |
| 596 |
% \begin{macro}{\listoftables} |
| 597 |
% Adjust the "\tableofcontents" macro to never show the long form of acronyms. |
| 598 |
% \begin{macrocode} |
| 599 |
% \let\hep@table@of@contents\tableofcontents |
| 600 |
% \renewcommand*\tableofcontents{% |
| 601 |
% \glsunsetall\hep@table@of@contents\glsresetall% |
| 602 |
% } |
| 603 |
% \let\hep@list@of@figures\listoffigures |
| 604 |
% \renewcommand*\listoffigures{% |
| 605 |
% \glsunsetall\hep@list@of@figures\glsresetall% |
| 606 |
% } |
| 607 |
% \let\hep@list@of@tables\listoftables |
| 608 |
% \renewcommand*\listoftables{% |
| 609 |
% \glsunsetall\hep@list@of@tables\glsresetall% |
| 610 |
% } |
| 611 |
% \end{macrocode} |
| 612 |
% \end{macro} |
| 613 |
% \end{macro} |
| 614 |
% \end{macro} |
| 615 |
% |
| 616 |
% \begin{macro}{\acronyms} |
| 617 |
% Add a possibility to have different groups of acronyms. |
| 618 |
% \begin{macrocode} |
| 619 |
\NewDocumentCommand{\acronyms}{om}{% |
| 620 |
\IfNoValueTF{#1}{ |
| 621 |
\newglossary{#2}{#2.in}{#2.out}{#2}% |
| 622 |
\renewcommand*{\acronymtype}{#2}% |
| 623 |
}{ |
| 624 |
\newglossary{#1}{#1.in}{#1.out}{#2}% |
| 625 |
\renewcommand*{\acronymtype}{#1}% |
| 626 |
} |
| 627 |
} |
| 628 |
% \end{macrocode} |
| 629 |
% \end{macro} |
| 630 |
% |
| 631 |
%</package> |
| 632 |
% |
| 633 |
% \section{Test} |
| 634 |
% |
| 635 |
%<*test> |
| 636 |
% \begin{macrocode} |
| 637 |
\documentclass{article} |
| 638 |
|
| 639 |
\usepackage{hyperref} |
| 640 |
\usepackage{hep-acronym} |
| 641 |
\usepackage{titlesec} |
| 642 |
|
| 643 |
\acronym{PDF}{portable document format} |
| 644 |
\acronym{URL}{uniform resource locator} |
| 645 |
\acronym{CM}{computer modern} |
| 646 |
\acronym{LM}{latin modern} |
| 647 |
|
| 648 |
\begin{document} |
| 649 |
|
| 650 |
\PDF \emph{(Capitalised at beginning of paragraph)} |
| 651 |
\PDF \emph{(Second appearance is shortened)}. |
| 652 |
\URLs \emph{(Capitalised plural form at beginning of sentence)} |
| 653 |
$\URL$ \emph{(Second appearance is forced to be always short)} |
| 654 |
\LM \emph{(Not capitalised in middle of sentence)} |
| 655 |
\LM \emph{(Second appearance is shorted)}. |
| 656 |
$\CM$ \emph{(Enforce short form)} |
| 657 |
\CM \emph{(then extend second appearance)} |
| 658 |
\URLlong \emph{(enforce long form)} |
| 659 |
|
| 660 |
\section{\PDFlong table of contents is not broken} |
| 661 |
|
| 662 |
\end{document} |
| 663 |
% \end{macrocode} |
| 664 |
% |
| 665 |
%</test> |
| 666 |
% |
| 667 |
% \section{Readme} |
| 668 |
% |
| 669 |
%<*readme> |
| 670 |
% |
| 671 |
% \begin{macrocode} |
| 672 |
# The `hep-acronym` package |
| 673 |
|
| 674 |
An acronym extension for glossaries |
| 675 |
|
| 676 |
## Introduction |
| 677 |
|
| 678 |
The `hep-acronym` package provides an acronym macro based on the |
| 679 |
`glossaries` package. It can be loaded using `\usepackage{hep-acronym}`. |
| 680 |
|
| 681 |
## Author |
| 682 |
|
| 683 |
Jan Hajer |
| 684 |
|
| 685 |
## License |
| 686 |
|
| 687 |
This file may be distributed and/or modified under the conditions of the |
| 688 |
`LaTeX` Project Public License, either version 1.3c of this license or |
| 689 |
(at your option) any later version. The latest version of this license is |
| 690 |
in `http://www.latex-project.org/lppl.txt` and version 1.3c or later is |
| 691 |
part of all distributions of LaTeX version 2005/12/01 or later. |
| 692 |
% \end{macrocode} |
| 693 |
% |
| 694 |
%</readme> |
| 695 |
% |
| 696 |
% \Finale |
| 697 |
|
| 698 |
\endinput |
| 699 |
|
| 700 |
% \PrintIndex |
| 701 |
% makeindex -s gglo.ist -o hep-acronym-implementation.gls hep-acronym-implementation.glo |
| 702 |
% makeindex -s gglo.ist -o hep-acronym-implementation.ind hep-acronym-implementation.idx |