Debian Codegraph @

texmf-dist/doc/latex/glossaries/samples/sample-storage-abbr.tex

raw
1 % This file is public domain
2 % If you want to use arara, you need the following directives:
3 % arara: pdflatex
4 % arara: makeglossaries
5 % arara: pdflatex
6 %
7 %http://mirrors.ctan.org/macros/latex/contrib/glossaries/glossaries-user.html#sample-storage-abbr
8 \documentclass{article}
9
10 \usepackage{glossaries}
11
12 \makeglossaries
13
14 \glsaddstoragekey
15 {abbrtype}% key/field name
16 {word}% default value if not explicitly set
17 {\abbrtype}% custom command to access the value if required
18
19 \newacronymstyle
20 {mystyle}% style name
21 {% Use the generic display
22 \ifglshaslong{\glslabel}{\glsgenacfmt}{\glsgenentryfmt}%
23 }
24 {% Put the long form in the description
25 \renewcommand*{\GenericAcronymFields}{description={\the\glslongtok}}%
26 % For the full format, test the value of the "abbrtype" key.
27 % If it's set to "word" put the short form first with
28 % the long form in brackets.
29 \renewcommand*{\genacrfullformat}[2]{%
30 \ifglsfieldeq{##1}{abbrtype}{word}
31 {% is a proper acronym
32 \protect\firstacronymfont{\glsentryshort{##1}}##2\space
33 (\glsentrylong{##1})%
34 }
35 {% is another form of abbreviation
36 \glsentrylong{##1}##2\space
37 (\protect\firstacronymfont{\glsentryshort{##1}})%
38 }%
39 }%
40 % first letter upper case version:
41 \renewcommand*{\Genacrfullformat}[2]{%
42 \ifglsfieldeq{##1}{abbrtype}{word}
43 {% is a proper acronym
44 \protect\firstacronymfont{\Glsentryshort{##1}}##2\space
45 (\glsentrylong{##1})%
46 }
47 {% is another form of abbreviation
48 \Glsentrylong{##1}##2\space
49 (\protect\firstacronymfont{\glsentryshort{##1}})%
50 }%
51 }%
52 % plural
53 \renewcommand*{\genplacrfullformat}[2]{%
54 \ifglsfieldeq{##1}{abbrtype}{word}
55 {% is a proper acronym
56 \protect\firstacronymfont{\glsentryshortpl{##1}}##2\space
57 (\glsentrylong{##1})%
58 }
59 {% is another form of abbreviation
60 \glsentrylongpl{##1}##2\space
61 (\protect\firstacronymfont{\glsentryshortpl{##1}})%
62 }%
63 }%
64 % plural and first letter upper case
65 \renewcommand*{\Genplacrfullformat}[2]{%
66 \ifglsfieldeq{##1}{abbrtype}{word}
67 {% is a proper acronym
68 \protect\firstacronymfont{\Glsentryshortpl{##1}}##2\space
69 (\glsentrylong{##1})%
70 }
71 {% is another form of abbreviation
72 \Glsentrylongpl{##1}##2\space
73 (\protect\firstacronymfont{\glsentryshortpl{##1}})%
74 }%
75 }%
76 % Just use the short form as the name part in the glossary:
77 \renewcommand*{\acronymentry}[1]{\acronymfont{\glsentryshort{##1}}}%
78 % Sort by the short form:
79 \renewcommand*{\acronymsort}[2]{##1}%
80 % Just use the surrounding font for the short form:
81 \renewcommand*{\acronymfont}[1]{##1}%
82 % Same for first use:
83 \renewcommand*{\firstacronymfont}[1]{\acronymfont{##1}}%
84 % Default plural suffix if the plural isn't explicitly set
85 \renewcommand*{\acrpluralsuffix}{\glspluralsuffix}%
86 }
87
88 \setacronymstyle{mystyle}
89
90 % The default for "abbrtype" is "acronym" so we don't need
91 % this new key for acronyms:
92 \newacronym{radar}{radar}{radio detecting and ranging}
93 \newacronym{laser}{laser}{light amplification by stimulated
94 emission of radiation}
95 \newacronym{scuba}{scuba}{self-contained underwater breathing
96 apparatus}
97
98 \newcommand*{\newinitialism}[4][]{%
99 \newacronym[abbrtype=initialism,#1]{#2}{#3}{#4}%
100 }
101
102 \newinitialism{dsp}{DSP}{digital signal processing}
103 \newinitialism{atm}{ATM}{automated teller machine}
104
105 \begin{document}
106
107 First use: \gls{radar}, \gls{laser}, \gls{scuba}, \gls{dsp},
108 \gls{atm}.
109
110 Next use: \gls{radar}, \gls{laser}, \gls{scuba}, \gls{dsp},
111 \gls{atm}.
112
113 \printglossaries
114 \end{document}