summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/glossaries-extra/samples/sample-name-font.tex
blob: 169b28e9c22dfcfb2adaedc10ef40e162a5e5944 (plain)
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
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
% arara: pdflatex
\documentclass[fontsize=10pt,open=any]{scrbook}

\usepackage[T1]{fontenc}
\usepackage{tgtermes}
\usepackage{xcolor}
\usepackage{siunitx}
\usepackage[hidelinks]{hyperref}
\usepackage[nopostdot=false,% don't suppress the post-description dot
 stylemods=longragged,% load glossary-longragged.sty and glossaries-extra-stylemods.sty
 style=longragged3col,% set the glossary style
 nogroupskip% don't have a gap between groups
]{glossaries-extra}

% KOMA class alterations (the default sans-serif clashes
% with the smallcaps font in the headings examples)
\setkomafont{disposition}{\normalcolor\bfseries}

\pagestyle{headings}

% Need a wider column for the location list:
\setlength{\glspagelistwidth}{0.12\textwidth}

% Adjust the description column width if necessary:
%\setlength{\glsdescwidth}{0.5\textwidth}

% Default font for name field in the glossary. This may be
% overridden by the category attributes:
\renewcommand*{\glsnamefont}[1]{\textbf{#1}}

\makeglossaries

% Define some semantic commands:
\newcommand*{\animalfont}[1]{\textcolor{brown}{#1}}
\newcommand*{\vegetablefont}[1]{\textcolor{teal}{#1}}
\newcommand*{\mineralfont}[1]{\textcolor{violet}{#1}}
\newcommand*{\myacronymfont}[1]{\textcolor{orange}{#1}}
\newcommand*{\bacteriafont}[1]{\textcolor{green}{#1}}
\newcommand*{\unitfont}[1]{\textcolor{blue}{#1}}
\newcommand*{\constantfont}[1]{\textcolor{magenta}{#1}}

% Make the first letter of the name field uppercase in the glossary
% for the given categories:

\glssetcategoryattribute{animal}{glossname}{firstuc}
\glssetcategoryattribute{mineral}{glossname}{firstuc}
\glssetcategoryattribute{vegetable}{glossname}{firstuc}

% Make the name field in the glossary use a font changing command
% (overrides \glsnamefont). In this example, I'm using the semantic
% commands I defined above. The backslash is omitted.

\glssetcategoryattribute{animal}{glossnamefont}{animalfont}
\glssetcategoryattribute{mineral}{glossnamefont}{mineralfont}
\glssetcategoryattribute{vegetable}{glossnamefont}{vegetablefont}
\glssetcategoryattribute{acronym}{glossnamefont}{myacronymfont}
\glssetcategoryattribute{bacteria}{glossnamefont}{bacteriafont}
\glssetcategoryattribute{unit}{glossnamefont}{unitfont}
\glssetcategoryattribute{constant}{glossnamefont}{constantfont}

% Modify the font used for the description in the glossary:
%\glssetcategoryattribute{bacteria}{glossdescfont}{textsf}

% Modify the way commands like \gls display regular terms according
% to attribute.

\glssetcategoryattribute{general}{font}{textsf}
\glssetcategoryattribute{mineral}{font}{mineralfont}
\glssetcategoryattribute{animal}{font}{animalfont}
\glssetcategoryattribute{vegetable}{font}{vegetablefont}
\glssetcategoryattribute{acronym}{font}{myacronymfont}
\glssetcategoryattribute{unit}{font}{unitfont}
\glssetcategoryattribute{constant}{font}{constantfont}

% I can't add one of the above for the "abbreviation" or "bacteria"
% category as they aren't considered regular entries. (They use
% one of the abbreviation styles that sets the "regular" attribute
% to "false".)
\glssetcategoryattribute{bacteria}{font}{bacteriafont}% ignored!
% If the abbreviation style for "bacteria" is changed to, say,
% "short-em", the attribute won't be ignored.

% Adjust \glsxtrregularfont so that it picks up the appropriate
% command from the "font" attribute (set above).
\renewcommand*{\glsxtrregularfont}[1]{%
  \glshasattribute{\glslabel}{font}%
  {\csuse{\glsgetattribute{\glslabel}{font}}{#1}}%
  {#1}%
}

\newglossaryentry{duck}{name=duck,
  category={animal},
  description={a waterbird with webbed feet}}

\newglossaryentry{parrot}{name=parrot,
  category={animal},
  description={mainly tropical bird with bright plumage}}

\newglossaryentry{cabbage}{name=cabbage,
  category={vegetable},
  description={vegetable with thick green or purple leaves}}

\newglossaryentry{brocolli}{name=brocolli,
  category={vegetable},
  description={vegetable with heads of small green or purple flower
buds}}

\newglossaryentry{quartz}{name=quartz,
 category=mineral,
 description={hard mineral consisting of silica}}

\newglossaryentry{corundum}{name=corundum,
 category=mineral,
 description={crystalline form of aluminium oxide}}

% The following doesn't have the category explicitly set, so it
% defaults to "general":

\newglossaryentry{loremipsum}{name={lorem ipsum},
 description={dummy text}}

% The following set the category to "unit":

\newglossaryentry{ohm}{name=ohm,symbol={\si{\ohm}},
category=unit,
description=unit of electrical resistance}

\newglossaryentry{angstrom}{name={\aa}ngstr\"om,
category=unit,
symbol={\si{\angstrom}},sort=angstrom,
description={non-SI unit of length}}

% The selected style doesn't display the symbol
% so add it to the post-name hook:
\newcommand*{\glsxtrpostnameunit}{ (\glsentrysymbol{\glscurrententrylabel})}

% Insert the symbol after commands like \gls but only on first use
% (and only for the "unit" category):

\newcommand*{\glsxtrpostlinkunit}{%
 \ifdefempty\glscustomtext{\glsxtrpostlinkAddSymbolOnFirstUse}{}}
% The above "post-link" hook occurs after the link-text produced by 
% \gls so it's place outside the \unitfont argument.

% Mathematic constants need the "sort" key set because the "name"
% field contains commands:
\newglossaryentry{pi}{name={\ensuremath{\pi}},
sort=pi,
category=constant,
user1=pi,
description={ratio of a circle's circumference to its diameter}}

% Insert the description and "user1" text after commands like \gls but only on first use
% (and only for the "constant" category):

\newcommand*{\glsxtrpostlinkconstant}{%
 \ifdefempty\glscustomtext
 {\glsxtrifwasfirstuse{ (\glsentryuseri{\glslabel},
  \glsentrydesc{\glslabel})}{}}%
 {}}

% Insert the "user1" text after the description in the glossary
% but only for the "constant" category:
\newcommand*{\glsxtrpostdescconstant}{\space
 (\glsentryuseri{\glscurrententrylabel})}

% \newacronym sets the category to "acronym" by default. The
% "short-em" style makes it a regular entry.
\setabbreviationstyle[acronym]{short-em}

\newacronym{laser}{laser}{light amplification by
stimulated emission of radiation}

\newacronym{scuba}{scuba}{self-contained underwater breathing
apparatus}

% \newabbreviation sets the category to "abbreviation" by default.
% The "long-short-sc" style sets the regular attribute to false.
\setabbreviationstyle{long-short-sc}

\newabbreviation{html}{html}{hypertext markup language}

\newabbreviation{svg}{svg}{scalable vector graphics}

% The optional argument can be used to set a different category:
\setabbreviationstyle[bacteria]{long-em-short-em}
%\setabbreviationstyle[bacteria]{short-em}

% An alternative approach that uses \bacteriafont in the document
% and in the glossary is to provide a custom style:
%\newabbreviationstyle{bacteria}%
%{%
%  \GlsXtrUseAbbrStyleSetup{long-short}%
%}%
%{%
%  \GlsXtrUseAbbrStyleFmts{long-short}%
%  \renewcommand*{\glsabbrvfont}[1]{\bacteriafont{##1}}%
%  \renewcommand*{\glsfirstlongfont}[1]{\bacteriafont{##1}}%
%  \renewcommand*{\glslongfont}[1]{\bacteriafont{##1}}%
%}
% (the definition of \bacteriafont would need to be adjusted to
% include \emph)
%\setabbreviationstyle[bacteria]{bacteria}

\newabbreviation[category=bacteria]%
 {cbot}% label
 {C.~botulinum}% short
 {Clostridium botulinum}% long

\newabbreviation[category=bacteria]%
 {putida}% label
 {P.~putida}% short
 {Pseudomonas putida}% long

% Abbreviations that have translations. These put the translated
% text in the "user1" field. The "-user" abbreviation styles
% insert this field (if present) into the parenthetical material
% when used with \gls.

\setabbreviationstyle[foreign]{short-long-user}

% The fonts used by this style can be adjusted:
\renewcommand*{\glsabbrvuserfont}[1]{\textsf{\color{red}#1}}% short-form font
\renewcommand*{\glslonguserfont}[1]{\textsf{#1}}% long-form font

\newabbreviation[category=foreign,user1={French \TeX\ user group}]
 {gutenberg}{GUTenburg}{Groupe francophone des utilisateurs de \TeX}

% Insert the translation (user1) text after the description 
% in the glossary but only for the "foreign" category:
\newcommand*{\glsxtrpostdescforeign}{\space
 (Translation: \glsentryuseri{\glscurrententrylabel})}

% Now we have an awkward one that ends with a period:
\setabbreviationstyle[foreignenddot]{short-long-user}

% Need to discard the end of sentence period for the
% entries in this category.

\glssetcategoryattribute{foreignenddot}{discardperiod}{true}

% But not on first use (the user1 text doesn't end with a
% period):
\glssetcategoryattribute{foreignenddot}{retainfirstuseperiod}{true}

\newabbreviation
 [user1={German Speaking \TeX\ User Group},category=foreignenddot]
 {dante}{DANTE e.V.}{Deutschsprachige Anwendervereinigung \TeX\ e.V.}

% Insert the translation (user1) text after the description 
% in the glossary but only for the "foreignenddot" category:
\newcommand*{\glsxtrpostdescforeignenddot}{\space
 (Translation: \glsentryuseri{\glscurrententrylabel})}

% Insert page/pages tag before location list:
\GlsXtrEnablePreLocationTag{Page: }{Pages: }

\begin{document}
\tableofcontents

\chapter{Samples in the Main Document Text}

\section{All Entries}

First use (\verb|\gls|): \forglsentries{\thislabel}{\gls{\thislabel}. }

Next use (\verb|\gls|): \forglsentries{\thislabel}{\gls{\thislabel}. }

Using \verb|\glsfirst|: \forglsentries{\thislabel}{\glsfirst{\thislabel}. }

Using \verb|\glstext|: \forglsentries{\thislabel}{\glstext{\thislabel}. }

\section{Abbreviations only}
Abbreviations that have the \verb|regular| attribute set are
hybrids and can have odd results. In this example, the hybrid
entries are: 
\forglsentries{\thislabel}{%
 \ifglshasshort{\thislabel}%
 {% is an abbreviation
   \glsifregular{\thislabel}%
   {% is regular
     \texttt{\thislabel}.
   }%
   {}%
 }
 {}%
}

Using \verb|\glsxtrfull|: 
\forglsentries{\thislabel}{%
 \ifglshasshort{\thislabel}{\glsxtrfull{\thislabel}.  }{}}

Using \verb|\glsxtrshort|: 
\forglsentries{\thislabel}{%
 \ifglshasshort{\thislabel}{\glsxtrshort{\thislabel}.  }{}}

Using \verb|\glsxtrlong|: 
\forglsentries{\thislabel}{%
 \ifglshaslong{\thislabel}{\glsxtrlong{\thislabel}.  }{}}

\section{Symbols}

Using \verb|\glssymbol|:
\forglsentries{\thislabel}{%
 \ifglshassymbol{\thislabel}{\glssymbol{\thislabel}.  }{}}

\section{User Field}

Using \verb|\glsuseri|:
\forglsentries{\thislabel}{%
 \ifglshasfield{useri}{\thislabel}{\glsuseri{\thislabel}[.]  }{}}

(The full stop in the above is placed inside square brackets
to prevent the \verb|discardperiod| attribute from discarding it
since the \verb|useri| field doesn't end with a dot.)

\chapter{Math Mode}
Inline: $\gls{pi} = \frac{C}{d}$, display:

\[
 \gls{pi} = \frac{C}{d}
\]

\chapter{Samples in Headings}

Don't use commands like \verb|\gls| in section headings, but you can
use commands like \verb|\glsfmttext| or \verb|\glsfmtshort|.

\forglsentries{\thislabel}{%
 \ifglshasshort{\thislabel}%
 {\section{\glsfmtshort{\thislabel}}}%
 {%
% the constant entry "pi" can't be used in the PDF bookmarks,
% so use the user1 text for the bookmark
   \glsifcategory{\thislabel}{constant}
   {%
     \section{\texorpdfstring{\glsfmttext{\thislabel}}{\glsentryuseri{\thislabel}}}%
   }%
   {%
     \section{\glsfmttext{\thislabel}}%
   }%
 }%
 \Glsdesc[noindex]{\thislabel}.
}


\renewcommand{\glossarypreamble}{\emph{This glossary uses the style 
`\csuse{@glossary@default@style}' with modifications made
through categories and their attributes.}\par\medskip}
\printglossaries

\end{document}