summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/glossaries/samples/sample.tex
blob: eca146458543fa76b3c6e0e97683028b52f33007 (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
% This file is public domain
% If you want to use arara, you need the following directives:
% arara: pdflatex: { synctex: on }
% arara: makeglossaries
% arara: pdflatex: { synctex: on }
% arara: pdflatex: { synctex: on }
\documentclass[a4paper]{report}

\usepackage[plainpages=false,colorlinks]{hyperref}
\usepackage[toc,style=treenoname,order=word,subentrycounter]{glossaries}

\makeglossaries

\newglossaryentry{Perl}{name=\texttt{Perl},
sort=Perl, % need a sort key because name contains a command
description=A scripting language}

\newglossaryentry{glossary}{name=glossary,
description={\nopostdesc},
plural={glossaries}}

\newglossaryentry{glossarycol}{
description={collection of glosses},
sort={2},
parent={glossary}}

\newglossaryentry{glossarylist}{
description={list of technical words},
sort={1},
parent={glossary}}

\newglossaryentry{pagelist}{name=page list,
% description value has to be enclosed in braces
% because it contains commas
description={a list of individual pages or page ranges 
(e.g.\ 1,2,4,7-9)}}

\newglossaryentry{mtrx}{name=matrix,
description={rectangular array of quantities},
% plural is not simply obtained by appending an s, so specify
plural=matrices}

% Entry with a paragraph break in the description:
% (If you use \newglossaryentry, the paragraph break
% must be identified with \glspar not with \par or a blank line.
% It's easier to use \longnewglossaryentry.)

\longnewglossaryentry{par}% label
{name=paragraph}% options
{% multi-paragraph description
distinct section of a piece of writing.

Beginning on new, usually indented, line}

% entry with two types of plural. Set the plural form to the 
% form most likely to be used. If you want to use a different
% plural, you will need to explicity specify it in \glslink
\newglossaryentry{cow}{name=cow,
% this isn't necessary, as this form (appending an s) is
% the default
plural=cows,
% description:
description={(\emph{pl.}\ cows, \emph{archaic} kine) an adult
female of any bovine animal}}

\newglossaryentry{bravo}{name={bravo},
description={\nopostdesc}}

\newglossaryentry{bravo1}{description={cry of approval (pl.\ bravos)},
sort={1},
plural={bravos},
parent=bravo}

\newglossaryentry{bravo2}{description={hired ruffian or killer (pl.\ bravoes)},
sort={2},
plural={bravoes},
parent=bravo}

\newglossaryentry{seal}{%
  name=seal,%
  description={sea mammal with flippers that eats fish}
}

\newglossaryentry{sealion}{%
 name={sea lion},%
 description={large seal}%
}

% If a value contains a comma, you must use braces to hide
% it from the key=value list parser. Take care to avoid
% accidentally introducing unwanted space as leading and trailing
% spaces within the braces aren't stripped. For example,
% text={ spurious space } will result in extra space appearing
% when the entry is referenced.  
\newglossaryentry{spuriousspace}{%
  name={space, spurious},
  text={spurious space},
  description={unwanted spaces accidentally introduced by
uncommented line breaks or attempts to pretty-print the \LaTeX\ code}
}

\begin{document}

\title{Sample Document Using the glossaries Package}
\author{Nicola Talbot}
\pagenumbering{alph}% prevent duplicate page link names if using PDF
\maketitle

\pagenumbering{roman}
\tableofcontents

\chapter{Introduction}
\pagenumbering{arabic}

A \gls{glossarylist} (definition~\glsrefentry{glossarylist}) is a
very useful addition to any technical document, although a
\gls{glossarycol} (definition~\glsrefentry{glossarycol}) can also
simply be a collection of glosses, which is another thing entirely.
Some documents have multiple \glspl{glossarylist}.

Once you have run your document through \LaTeX, you will then need
to run the \texttt{.glo} file through \texttt{makeindex} (default)
or \texttt{xindy}.  You will need to set the output file so that the
indexing application
creates a \texttt{.gls} file instead of an \texttt{.ind} file, and
change the name of the log file so that it doesn't overwrite the
index log file (if you have an index for your document).  Rather
than having to remember all the command line switches, you can call
the \gls{Perl} script \texttt{makeglossaries} which provides a
convenient wrapper. See
\href{https://www.dickimaw-books.com/latex/buildglossaries}{Incorporating makeglossaries or makeglossaries-lite or bib2gls into the document build} for help.

If a comma appears within the name or description, grouping
must be used, e.g.\ in the description of \gls{pagelist}.
Be careful about \glspl{spuriousspace} appearing in your code.

\chapter{Plurals and Paragraphs}

Plurals are assumed to have the letter s appended, but if this is
not the case, as in \glspl{mtrx}, then you need to specify the
plural when you define the entry. If a term may have multiple
plurals (for example \glspl{cow}/\glslink{cow}{kine}) then 
define the entry with the plural form most likely to be used and
explicitly specify the alternative form using \verb|\glslink|
(e.g.\ \glslink{cow}{kine})
or \verb|\glsdisp| (e.g.\ \glsdisp{cow}{kine}).
\Glspl{seal} and \glspl{sealion} have regular plural forms.

\Gls{bravo} is a homograph, but the plural forms are spelt
differently. The plural of \gls{bravo1}, a cry of approval
(definition~\glsrefentry{bravo1}), is \glspl{bravo1}, whereas the
plural of \gls{bravo2}, a hired ruffian or killer
(definition~\glsrefentry{bravo2}), is \glspl{bravo2}.

\Glspl{par} can cause a problem in commands, so care is needed
when having a paragraph break in a \gls{glossarylist} entry.

\chapter{Ordering}

There are two types of ordering: word ordering (which places
``\gls{sealion}'' before ``\gls{seal}'') and letter ordering
(which places ``\gls{seal}'' before ``\gls{sealion}'').

\printglossaries

\end{document}