| 1 |
% arara: pdflatex |
| 2 |
% arara: makeglossaries |
| 3 |
% arara: pdflatex |
| 4 |
% arara: pdflatex |
| 5 |
\documentclass[fontsize=10pt,open=any]{scrbook} |
| 6 |
|
| 7 |
\usepackage[T1]{fontenc} |
| 8 |
\usepackage{tgtermes} |
| 9 |
\usepackage{xcolor} |
| 10 |
\usepackage{siunitx} |
| 11 |
\usepackage[hidelinks]{hyperref} |
| 12 |
\usepackage[nopostdot=false,% don't suppress the post-description dot |
| 13 |
stylemods=longragged,% load glossary-longragged.sty and glossaries-extra-stylemods.sty |
| 14 |
style=longragged3col,% set the glossary style |
| 15 |
nogroupskip% don't have a gap between groups |
| 16 |
]{glossaries-extra} |
| 17 |
|
| 18 |
% KOMA class alterations (the default sans-serif clashes |
| 19 |
% with the smallcaps font in the headings examples) |
| 20 |
\setkomafont{disposition}{\normalcolor\bfseries} |
| 21 |
|
| 22 |
\pagestyle{headings} |
| 23 |
|
| 24 |
% Need a wider column for the location list: |
| 25 |
\setlength{\glspagelistwidth}{0.12\textwidth} |
| 26 |
|
| 27 |
% Adjust the description column width if necessary: |
| 28 |
%\setlength{\glsdescwidth}{0.5\textwidth} |
| 29 |
|
| 30 |
% Default font for name field in the glossary. This may be |
| 31 |
% overridden by the category attributes: |
| 32 |
\renewcommand*{\glsnamefont}[1]{\textbf{#1}} |
| 33 |
|
| 34 |
\makeglossaries |
| 35 |
|
| 36 |
% Define some semantic commands: |
| 37 |
\newcommand*{\animalfont}[1]{\textcolor{brown}{#1}} |
| 38 |
\newcommand*{\vegetablefont}[1]{\textcolor{teal}{#1}} |
| 39 |
\newcommand*{\mineralfont}[1]{\textcolor{violet}{#1}} |
| 40 |
\newcommand*{\myacronymfont}[1]{\textcolor{orange}{#1}} |
| 41 |
\newcommand*{\bacteriafont}[1]{\textcolor{green}{#1}} |
| 42 |
\newcommand*{\unitfont}[1]{\textcolor{blue}{#1}} |
| 43 |
\newcommand*{\constantfont}[1]{\textcolor{magenta}{#1}} |
| 44 |
|
| 45 |
% Make the first letter of the name field uppercase in the glossary |
| 46 |
% for the given categories: |
| 47 |
|
| 48 |
\glssetcategoryattribute{animal}{glossname}{firstuc} |
| 49 |
\glssetcategoryattribute{mineral}{glossname}{firstuc} |
| 50 |
\glssetcategoryattribute{vegetable}{glossname}{firstuc} |
| 51 |
|
| 52 |
% Make the name field in the glossary use a font changing command |
| 53 |
% (overrides \glsnamefont). In this example, I'm using the semantic |
| 54 |
% commands I defined above. The backslash is omitted. |
| 55 |
|
| 56 |
\glssetcategoryattribute{animal}{glossnamefont}{animalfont} |
| 57 |
\glssetcategoryattribute{mineral}{glossnamefont}{mineralfont} |
| 58 |
\glssetcategoryattribute{vegetable}{glossnamefont}{vegetablefont} |
| 59 |
\glssetcategoryattribute{acronym}{glossnamefont}{myacronymfont} |
| 60 |
\glssetcategoryattribute{bacteria}{glossnamefont}{bacteriafont} |
| 61 |
\glssetcategoryattribute{unit}{glossnamefont}{unitfont} |
| 62 |
\glssetcategoryattribute{constant}{glossnamefont}{constantfont} |
| 63 |
|
| 64 |
% Modify the font used for the description in the glossary: |
| 65 |
%\glssetcategoryattribute{bacteria}{glossdescfont}{textsf} |
| 66 |
|
| 67 |
% Modify the way commands like \gls display regular terms according |
| 68 |
% to attribute. |
| 69 |
|
| 70 |
\glssetcategoryattribute{general}{font}{textsf} |
| 71 |
\glssetcategoryattribute{mineral}{font}{mineralfont} |
| 72 |
\glssetcategoryattribute{animal}{font}{animalfont} |
| 73 |
\glssetcategoryattribute{vegetable}{font}{vegetablefont} |
| 74 |
\glssetcategoryattribute{acronym}{font}{myacronymfont} |
| 75 |
\glssetcategoryattribute{unit}{font}{unitfont} |
| 76 |
\glssetcategoryattribute{constant}{font}{constantfont} |
| 77 |
|
| 78 |
% I can't add one of the above for the "abbreviation" or "bacteria" |
| 79 |
% category as they aren't considered regular entries. (They use |
| 80 |
% one of the abbreviation styles that sets the "regular" attribute |
| 81 |
% to "false".) |
| 82 |
\glssetcategoryattribute{bacteria}{font}{bacteriafont}% ignored! |
| 83 |
% If the abbreviation style for "bacteria" is changed to, say, |
| 84 |
% "short-em", the attribute won't be ignored. |
| 85 |
|
| 86 |
% Adjust \glsxtrregularfont so that it picks up the appropriate |
| 87 |
% command from the "font" attribute (set above). |
| 88 |
\renewcommand*{\glsxtrregularfont}[1]{% |
| 89 |
\glshasattribute{\glslabel}{font}% |
| 90 |
{\csuse{\glsgetattribute{\glslabel}{font}}{#1}}% |
| 91 |
{#1}% |
| 92 |
} |
| 93 |
|
| 94 |
\newglossaryentry{duck}{name=duck, |
| 95 |
category={animal}, |
| 96 |
description={a waterbird with webbed feet}} |
| 97 |
|
| 98 |
\newglossaryentry{parrot}{name=parrot, |
| 99 |
category={animal}, |
| 100 |
description={mainly tropical bird with bright plumage}} |
| 101 |
|
| 102 |
\newglossaryentry{cabbage}{name=cabbage, |
| 103 |
category={vegetable}, |
| 104 |
description={vegetable with thick green or purple leaves}} |
| 105 |
|
| 106 |
\newglossaryentry{brocolli}{name=brocolli, |
| 107 |
category={vegetable}, |
| 108 |
description={vegetable with heads of small green or purple flower |
| 109 |
buds}} |
| 110 |
|
| 111 |
\newglossaryentry{quartz}{name=quartz, |
| 112 |
category=mineral, |
| 113 |
description={hard mineral consisting of silica}} |
| 114 |
|
| 115 |
\newglossaryentry{corundum}{name=corundum, |
| 116 |
category=mineral, |
| 117 |
description={crystalline form of aluminium oxide}} |
| 118 |
|
| 119 |
% The following doesn't have the category explicitly set, so it |
| 120 |
% defaults to "general": |
| 121 |
|
| 122 |
\newglossaryentry{loremipsum}{name={lorem ipsum}, |
| 123 |
description={dummy text}} |
| 124 |
|
| 125 |
% The following set the category to "unit": |
| 126 |
|
| 127 |
\newglossaryentry{ohm}{name=ohm,symbol={\si{\ohm}}, |
| 128 |
category=unit, |
| 129 |
description=unit of electrical resistance} |
| 130 |
|
| 131 |
\newglossaryentry{angstrom}{name={\aa}ngstr\"om, |
| 132 |
category=unit, |
| 133 |
symbol={\si{\angstrom}},sort=angstrom, |
| 134 |
description={non-SI unit of length}} |
| 135 |
|
| 136 |
% The selected style doesn't display the symbol |
| 137 |
% so add it to the post-name hook: |
| 138 |
\newcommand*{\glsxtrpostnameunit}{ (\glsentrysymbol{\glscurrententrylabel})} |
| 139 |
|
| 140 |
% Insert the symbol after commands like \gls but only on first use |
| 141 |
% (and only for the "unit" category): |
| 142 |
|
| 143 |
\newcommand*{\glsxtrpostlinkunit}{% |
| 144 |
\ifdefempty\glscustomtext{\glsxtrpostlinkAddSymbolOnFirstUse}{}} |
| 145 |
% The above "post-link" hook occurs after the link-text produced by |
| 146 |
% \gls so it's place outside the \unitfont argument. |
| 147 |
|
| 148 |
% Mathematic constants need the "sort" key set because the "name" |
| 149 |
% field contains commands: |
| 150 |
\newglossaryentry{pi}{name={\ensuremath{\pi}}, |
| 151 |
sort=pi, |
| 152 |
category=constant, |
| 153 |
user1=pi, |
| 154 |
description={ratio of a circle's circumference to its diameter}} |
| 155 |
|
| 156 |
% Insert the description and "user1" text after commands like \gls but only on first use |
| 157 |
% (and only for the "constant" category): |
| 158 |
|
| 159 |
\newcommand*{\glsxtrpostlinkconstant}{% |
| 160 |
\ifdefempty\glscustomtext |
| 161 |
{\glsxtrifwasfirstuse{ (\glsentryuseri{\glslabel}, |
| 162 |
\glsentrydesc{\glslabel})}{}}% |
| 163 |
{}} |
| 164 |
|
| 165 |
% Insert the "user1" text after the description in the glossary |
| 166 |
% but only for the "constant" category: |
| 167 |
\newcommand*{\glsxtrpostdescconstant}{\space |
| 168 |
(\glsentryuseri{\glscurrententrylabel})} |
| 169 |
|
| 170 |
% \newacronym sets the category to "acronym" by default. The |
| 171 |
% "short-em" style makes it a regular entry. |
| 172 |
\setabbreviationstyle[acronym]{short-em} |
| 173 |
|
| 174 |
\newacronym{laser}{laser}{light amplification by |
| 175 |
stimulated emission of radiation} |
| 176 |
|
| 177 |
\newacronym{scuba}{scuba}{self-contained underwater breathing |
| 178 |
apparatus} |
| 179 |
|
| 180 |
% \newabbreviation sets the category to "abbreviation" by default. |
| 181 |
% The "long-short-sc" style sets the regular attribute to false. |
| 182 |
\setabbreviationstyle{long-short-sc} |
| 183 |
|
| 184 |
\newabbreviation{html}{html}{hypertext markup language} |
| 185 |
|
| 186 |
\newabbreviation{svg}{svg}{scalable vector graphics} |
| 187 |
|
| 188 |
% The optional argument can be used to set a different category: |
| 189 |
\setabbreviationstyle[bacteria]{long-em-short-em} |
| 190 |
%\setabbreviationstyle[bacteria]{short-em} |
| 191 |
|
| 192 |
% An alternative approach that uses \bacteriafont in the document |
| 193 |
% and in the glossary is to provide a custom style: |
| 194 |
%\newabbreviationstyle{bacteria}% |
| 195 |
%{% |
| 196 |
% \GlsXtrUseAbbrStyleSetup{long-short}% |
| 197 |
%}% |
| 198 |
%{% |
| 199 |
% \GlsXtrUseAbbrStyleFmts{long-short}% |
| 200 |
% \renewcommand*{\glsabbrvfont}[1]{\bacteriafont{##1}}% |
| 201 |
% \renewcommand*{\glsfirstlongfont}[1]{\bacteriafont{##1}}% |
| 202 |
% \renewcommand*{\glslongfont}[1]{\bacteriafont{##1}}% |
| 203 |
%} |
| 204 |
% (the definition of \bacteriafont would need to be adjusted to |
| 205 |
% include \emph) |
| 206 |
%\setabbreviationstyle[bacteria]{bacteria} |
| 207 |
|
| 208 |
\newabbreviation[category=bacteria]% |
| 209 |
{cbot}% label |
| 210 |
{C.~botulinum}% short |
| 211 |
{Clostridium botulinum}% long |
| 212 |
|
| 213 |
\newabbreviation[category=bacteria]% |
| 214 |
{putida}% label |
| 215 |
{P.~putida}% short |
| 216 |
{Pseudomonas putida}% long |
| 217 |
|
| 218 |
% Abbreviations that have translations. These put the translated |
| 219 |
% text in the "user1" field. The "-user" abbreviation styles |
| 220 |
% insert this field (if present) into the parenthetical material |
| 221 |
% when used with \gls. |
| 222 |
|
| 223 |
\setabbreviationstyle[foreign]{short-long-user} |
| 224 |
|
| 225 |
% The fonts used by this style can be adjusted: |
| 226 |
\renewcommand*{\glsabbrvuserfont}[1]{\textsf{\color{red}#1}}% short-form font |
| 227 |
\renewcommand*{\glslonguserfont}[1]{\textsf{#1}}% long-form font |
| 228 |
|
| 229 |
\newabbreviation[category=foreign,user1={French \TeX\ user group}] |
| 230 |
{gutenberg}{GUTenburg}{Groupe francophone des utilisateurs de \TeX} |
| 231 |
|
| 232 |
% Insert the translation (user1) text after the description |
| 233 |
% in the glossary but only for the "foreign" category: |
| 234 |
\newcommand*{\glsxtrpostdescforeign}{\space |
| 235 |
(Translation: \glsentryuseri{\glscurrententrylabel})} |
| 236 |
|
| 237 |
% Now we have an awkward one that ends with a period: |
| 238 |
\setabbreviationstyle[foreignenddot]{short-long-user} |
| 239 |
|
| 240 |
% Need to discard the end of sentence period for the |
| 241 |
% entries in this category. |
| 242 |
|
| 243 |
\glssetcategoryattribute{foreignenddot}{discardperiod}{true} |
| 244 |
|
| 245 |
% But not on first use (the user1 text doesn't end with a |
| 246 |
% period): |
| 247 |
\glssetcategoryattribute{foreignenddot}{retainfirstuseperiod}{true} |
| 248 |
|
| 249 |
\newabbreviation |
| 250 |
[user1={German Speaking \TeX\ User Group},category=foreignenddot] |
| 251 |
{dante}{DANTE e.V.}{Deutschsprachige Anwendervereinigung \TeX\ e.V.} |
| 252 |
|
| 253 |
% Insert the translation (user1) text after the description |
| 254 |
% in the glossary but only for the "foreignenddot" category: |
| 255 |
\newcommand*{\glsxtrpostdescforeignenddot}{\space |
| 256 |
(Translation: \glsentryuseri{\glscurrententrylabel})} |
| 257 |
|
| 258 |
% Insert page/pages tag before location list: |
| 259 |
\GlsXtrEnablePreLocationTag{Page: }{Pages: } |
| 260 |
|
| 261 |
\begin{document} |
| 262 |
\tableofcontents |
| 263 |
|
| 264 |
\chapter{Samples in the Main Document Text} |
| 265 |
|
| 266 |
\section{All Entries} |
| 267 |
|
| 268 |
First use (\verb|\gls|): \forglsentries{\thislabel}{\gls{\thislabel}. } |
| 269 |
|
| 270 |
Next use (\verb|\gls|): \forglsentries{\thislabel}{\gls{\thislabel}. } |
| 271 |
|
| 272 |
Using \verb|\glsfirst|: \forglsentries{\thislabel}{\glsfirst{\thislabel}. } |
| 273 |
|
| 274 |
Using \verb|\glstext|: \forglsentries{\thislabel}{\glstext{\thislabel}. } |
| 275 |
|
| 276 |
\section{Abbreviations only} |
| 277 |
Abbreviations that have the \verb|regular| attribute set are |
| 278 |
hybrids and can have odd results. In this example, the hybrid |
| 279 |
entries are: |
| 280 |
\forglsentries{\thislabel}{% |
| 281 |
\ifglshasshort{\thislabel}% |
| 282 |
{% is an abbreviation |
| 283 |
\glsifregular{\thislabel}% |
| 284 |
{% is regular |
| 285 |
\texttt{\thislabel}. |
| 286 |
}% |
| 287 |
{}% |
| 288 |
} |
| 289 |
{}% |
| 290 |
} |
| 291 |
|
| 292 |
Using \verb|\glsxtrfull|: |
| 293 |
\forglsentries{\thislabel}{% |
| 294 |
\ifglshasshort{\thislabel}{\glsxtrfull{\thislabel}. }{}} |
| 295 |
|
| 296 |
Using \verb|\glsxtrshort|: |
| 297 |
\forglsentries{\thislabel}{% |
| 298 |
\ifglshasshort{\thislabel}{\glsxtrshort{\thislabel}. }{}} |
| 299 |
|
| 300 |
Using \verb|\glsxtrlong|: |
| 301 |
\forglsentries{\thislabel}{% |
| 302 |
\ifglshaslong{\thislabel}{\glsxtrlong{\thislabel}. }{}} |
| 303 |
|
| 304 |
\section{Symbols} |
| 305 |
|
| 306 |
Using \verb|\glssymbol|: |
| 307 |
\forglsentries{\thislabel}{% |
| 308 |
\ifglshassymbol{\thislabel}{\glssymbol{\thislabel}. }{}} |
| 309 |
|
| 310 |
\section{User Field} |
| 311 |
|
| 312 |
Using \verb|\glsuseri|: |
| 313 |
\forglsentries{\thislabel}{% |
| 314 |
\ifglshasfield{useri}{\thislabel}{\glsuseri{\thislabel}[.] }{}} |
| 315 |
|
| 316 |
(The full stop in the above is placed inside square brackets |
| 317 |
to prevent the \verb|discardperiod| attribute from discarding it |
| 318 |
since the \verb|useri| field doesn't end with a dot.) |
| 319 |
|
| 320 |
\chapter{Math Mode} |
| 321 |
Inline: $\gls{pi} = \frac{C}{d}$, display: |
| 322 |
|
| 323 |
\[ |
| 324 |
\gls{pi} = \frac{C}{d} |
| 325 |
\] |
| 326 |
|
| 327 |
\chapter{Samples in Headings} |
| 328 |
|
| 329 |
Don't use commands like \verb|\gls| in section headings, but you can |
| 330 |
use commands like \verb|\glsfmttext| or \verb|\glsfmtshort|. |
| 331 |
|
| 332 |
\forglsentries{\thislabel}{% |
| 333 |
\ifglshasshort{\thislabel}% |
| 334 |
{\section{\glsfmtshort{\thislabel}}}% |
| 335 |
{% |
| 336 |
% the constant entry "pi" can't be used in the PDF bookmarks, |
| 337 |
% so use the user1 text for the bookmark |
| 338 |
\glsifcategory{\thislabel}{constant} |
| 339 |
{% |
| 340 |
\section{\texorpdfstring{\glsfmttext{\thislabel}}{\glsentryuseri{\thislabel}}}% |
| 341 |
}% |
| 342 |
{% |
| 343 |
\section{\glsfmttext{\thislabel}}% |
| 344 |
}% |
| 345 |
}% |
| 346 |
\Glsdesc[noindex]{\thislabel}. |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
\renewcommand{\glossarypreamble}{\emph{This glossary uses the style |
| 351 |
`\csuse{@glossary@default@style}' with modifications made |
| 352 |
through categories and their attributes.}\par\medskip} |
| 353 |
\printglossaries |
| 354 |
|
| 355 |
\end{document} |