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