Debian Codegraph @

texmf-dist/doc/latex/glossaries/samples/sample-storage-abbr-desc.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-desc
8 \documentclass{article}
9
10 \usepackage{glossaries}
11
12 \makeglossaries
13
14 \glsaddstoragekey
15 {abbrtype}% key/field name
16 {acronym}% 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 {% User needs to explicitly set the description
25 \renewcommand*{\GenericAcronymFields}{}%
26 % For the full format, test the value of the "abbrtype" key.
27 % If it's set to "acronym" put the short form first with
28 % the long form in brackets.
29 \renewcommand*{\genacrfullformat}[2]{%
30 \ifglsfieldeq{##1}{abbrtype}{acronym}
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}{acronym}
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}{acronym}
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}{acronym}
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[description={system for detecting the position and
93 speed of aircraft, ships, etc}]{radar}{radar}{radio detecting
94 and ranging}
95
96 \newacronym[description={device that creates a narrow beam
97 of intense light}]{laser}{laser}{light amplification by
98 stimulated emission of radiation}
99
100 \newacronym[description={portable breathing device for
101 divers}]{scuba}{scuba}{self-contained underwater breathing
102 apparatus}
103
104 \newcommand*{\newinitialism}[4][]{%
105 \newacronym[abbrtype=initialism,#1]{#2}{#3}{#4}%
106 }
107
108 \newinitialism[description={mathematical manipulation of an
109 information signal}]{dsp}{DSP}{digital signal processing}
110 \newinitialism[description={device that allows customers of
111 financial institutions to perform transactions, such as
112 cash withdrawal, without the need for a teller}]{atm}{ATM}
113 {automated teller machine}
114
115 \newcommand*{\newcontraction}[4][]{%
116 \newacronym[abbrtype=contraction,#1]{#2}{#3}{#4}%
117 }
118
119 \newcontraction[description={front part of a ship below the
120 deck}]{focsle}{fo'c's'le}{forecastle}
121
122 \newglossaryentry{apple}{name={apple},description={a fruit}}
123
124 \newglossarystyle
125 {mystyle}% style name
126 {% base it on the "list" style
127 \setglossarystyle{list}%
128 \renewcommand*{\glossentry}[2]{%
129 \item[\glsentryitem{##1}%
130 \glstarget{##1}{\glossentryname{##1}}]
131 \ifglshaslong{##1}%
132 { (\abbrtype{##1}: \glsentrylong{##1})\space}{}%
133 \glossentrydesc{##1}\glspostdescription\space ##2}%
134 }
135
136 \setglossarystyle{mystyle}
137
138 \begin{document}
139
140 First use: \gls{radar}, \gls{laser}, \gls{scuba}, \gls{dsp},
141 \gls{atm}, \gls{focsle}.
142
143 Next use: \gls{radar}, \gls{laser}, \gls{scuba}, \gls{dsp},
144 \gls{atm}, \gls{focsle}.
145
146 Regular term: \gls{apple}.
147
148 \printglossaries
149 \end{document}