summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/datatool/samples/sample-gidx.tex
blob: 1bc510953891c9c93d02e0999fbce3811ec2cb85 (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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
\documentclass{book}

\usepackage{datagidx}

\usepackage[colorlinks]{hyperref}

\usepackage{fmtcount}

\DTLgidxAddLocationType{numberstringnum}

 % Define some convenient commands

\newcommand*{\principleloc}[1]{\textbf{#1}}
\newcommand*{\glossaryloc}[1]{\textit{#1}}
\newcommand*{\appname}[1]{\texttt{#1}}

 % Don't let \appname interfere with the sorting and labelling of
 % terms:

\appto\newtermlabelhook{\let\appname\DTLgidxNoFormat}

 % (datagidx also does this for \MakeUppercase, \MakeTextUppercase,
 % \MakeLowercase, \MakeTextLowercase, \textsc and \acronymfont.)

 % Make an index database labelled 'index' with given title.
 % (Omit optional argument to affect all indexing databases
 % or use a comma-separated list of labels for each database
 % to affect.)

\newgidx[heading=\chapter]{index}{Index}

 % Add custom fields to the 'index' database

\newtermaddfield[index]{Ed}{ed}{\field{text}ed}

\newtermaddfield[index]{Ing}{ing}{\field{text}ing}

\newtermaddfield[index]{AltPlural}{altplural}{}% no default value

 % Define some convenience commands to access these fields

\newcommand*{\glsed}[1]{\useentry{#1}{Ed}}
\newcommand*{\glsing}[1]{\useentry{#1}{Ing}}
\newcommand*{\glsaltpl}[1]{\useentry{#1}{AltPlural}}

 % Make a glossary database labelled 'glossary' with given title.

\newgidx[heading=\section]{glossary}{Glossary}

 % Make an acronym database labelled 'acronyms' with given title.
 % A different heading for the table of contents is supplied.

\newgidx[heading={\section[Acronyms]}]{acronyms}{List of Acronyms}

 % Make a notation database labelled 'notation' with given title

\newgidx[heading=\section]{notation}{Notation}

 % Define some terms for the index

 % Either use "database" key in optional argument
 % or set the default database. It's less typing to set the default
 % database, so let's do that:

\DTLgidxSetDefaultDB{index}

 % These definitions will add terms to the "index" database:

\newterm{singular}
\newterm{plural}
\newterm
 [% options
   label=pluralalt,
   parent=plural,
   see={altplural}
 ]
 {alternative}
\newterm[label=altplural]{alternative plural}
\newterm{group}
\newterm[see=group]{scope}
\newterm[label={ind-glossary}]{glossary}
\newterm
 [%
   label={ind-index},
   seealso={ind-glossary},
 ]
 {index}
\newterm
 [
   seealso={ind-glossary}
 ]
 {acronym}
\newterm[parent=acronym]{reset}
\newterm
 [%
   parent=acronym,
   label={firstuse},
 ]
 {first use}
\newterm
 [%
   parent=acronym,
   label={acronymlist},
   text={list of acronyms},
   plural={lists of acronyms}
 ]
 {list}

 % Be careful if a value contains a comma or an equal sign. The
 % entire value must be grouped.
\newterm
 [%
   label={comma},
   sort={,},
   text={comma (,)},
   plural={commas (,)}
 ]%
 {, (comma)}

\newterm
 [%
   label={equals},
   sort={=},
   text={equal sign (=)},
   plural={equal signs (=)},
 ]%
 {= (equal sign)}

 % Don't need to worry about makeindex's special characters (since
 % we're not using makeindex!)
\newterm
 [%
   label={"},
   sort={"},
   text={double quote (")},
   plural={double quotes (")},
 ]%
 {" (double quote)}

\newterm
 [%
   label={!},
   sort={!},
   text={exclamation mark (!)},
   plural={exclamation marks (!)},
 ]%
 {! (exclamation mark)}

\newterm
 [%
   label={|},
   sort={|},
   text={vertical bar (\textbar)},
   plural={vertical bars (\textbar)},
 ]%
 {\textbar\ (vertical bar)}


 % Be careful of special characters

\newterm
 [%
   label={amp},
   sort={\DTLgidxStripBackslash{\&}},
   text={ampersand (\&)},
   plural={ampersands (\&)},
 ]
 {\& (ampersand)}

\newterm
 [%
   label={underscore},
   sort={\DTLgidxStripBackslash{\_}},
   text={underscore (\_)},
   plural={underscores (\_)},
 ]
 {\_ (underscore)}

\newterm
 [%
   label={dollar},
   sort={\DTLgidxStripBackslash{\$}},
   text={dollar (\$)},
   plural={dollars (\$)},
 ]
 {\$ (dollar)}

\newterm
 [%
   label={circum},
   sort={\DTLgidxStripBackslash{\^}},
   text={circumflex (\textasciicircum)},
   plural={circumflexes (\textasciicircum)},
 ]
 {\textasciicircum\ (circumflex)}

\newterm
 [%
   label={tilde},
   sort={\string~},
   text={tilde (\textasciitilde)},
   plural={tildes (\textasciitilde)},
 ]
 {\textasciitilde\ (tilde)}

\newterm
 [
   label={0},
   sort={0},
 ]
 {0 (zero)}

\newterm
 [
   label={1},
   sort={1},
 ]
 {1 (one)}

\newterm
 [
   label={2},
   sort={2},
 ]
 {2 (two)}

\newterm
 [
   label={3},
   sort={3},
 ]
 {3 (three)}

 % Let's index a person
\newterm
 [%
   label={knuth},
   text={Knuth},
 ]
 {Knuth, Donald E.}

 % and have a few more entries in the same letter group to test case
 % ordering:
\newterm{kite}
\newterm{koala}

 % Earlier I modified \newtermlabelhook so
 % that \appname won't interfere with the sorting
 % and labelling mechanism, so I don't need to specify separate sort
 % and label keys here:

\newterm{\appname{makeindex}}% label and sort both set to just 'makeindex'
\newterm{\appname{xindy}}% label and sort both set to just 'xindy'

 % Define some terms for the glossary

\DTLgidxSetDefaultDB{glossary}

\newterm[description={sea mammal with flippers that eats fish}]{seal}
\newterm[description={large seal},seealso={seal}]{sea lion}

\newterm{bravo}
\newterm
  [%
    label=bravocry,
    description={cry of approval (pl.\ bravos)},
    parent=bravo
  ]
  {bravo}
\newterm
  [% options
    label=bravokiller,
    description={hired ruffian or killer (pl.\ bravoes)},
    plural=bravoes,
    parent=bravo
  ]
 {bravo}

\newterm
 [%
   plural={indices\glsadd{ind-index}},
   altplural={indexes},
   text={index\glsadd{ind-index}},
   description={an alphabetical list of names or subjects with
   references to their location in the document (pl.\ indices or
   indexes)}
 ]
 {index\glsadd{[glossaryloc]ind-index}}

\newterm
 [% options
   text={glossary\glsadd{ind-glossary}},
   plural={glossaries\glsadd{ind-glossary}},
   seealso={index}%
 ]%
 {glossary\glsadd{ind-glossary}}

\newterm
 [% options
   label=glossarycol,
   text={glossary\glsadd{ind-glossary}},
   plural={glossaries\glsadd{ind-glossary}},
   description={collection of glosses},
   parent=glossary
 ]
 {glossary\glsadd{[glossaryloc]ind-glossary}}

\newterm
 [% options
   label=glossarylist,
   text={glossary\glsadd{ind-glossary}},
   plural={glossaries\glsadd{ind-glossary}},
   description={list of technical words},
   parent=glossary
 ]
 {glossary\glsadd{[glossaryloc]ind-glossary}}

\newterm
  [% options
   label=pglist,
   % description contains commas so it must be grouped
   description={a list of individual pages or page ranges
    (e.g.\ 1,2,4,7--9)}
  ]
  {page list}

 % define some acronyms

\DTLgidxSetDefaultDB{acronyms}

 % Let's redefine \newacro so that the short form is also indexed:

\renewcommand{\newacro}[3][]{%
  \newterm[database=index,label={ind-#2-long},see={ind-#2}]{#3}%
  \newterm[database=index,label={ind-#2}]{\acronymfont{#2}}%
  \newterm
    [%
      description={\capitalisewords{#3}},% long form capitalised
      text={\DTLgidxAcrStyle{#3}{\acronymfont{#2}}},% produced via \gls
      plural={\DTLgidxAcrStyle{#3}{\acronymfont{#2}}},% produced via \glspl
      short={\acronymfont{#2}\glsadd{ind-#2}},% short form
      long={#3},% long form
      sort={#2},% sort on short form
      #1%
    ]%
    {#2\glsadd{[glossaryloc]ind-#2}}
}

\newacro{html}{hyper-text markup language}
\newacro{css}{cascading style sheet}
\newacro{xml}{extensible markup language}

% define some notation

\DTLgidxSetDefaultDB{notation}

\newterm
 [%
   symbol={\ensuremath{\mathcal{S}}},
   description={a collection of distinct objects},
 ]%
 {set}

\newterm
 [%
   parent=set,
   symbol={\ensuremath{\mathcal{U}}},
   text={universal set},
   description={the set containing everything}
 ]%
 {universal}

\newterm
 [%
   parent=set,
   symbol={\ensuremath{\emptyset}},
   text={empty set},
   description={the set with no elements}
 ]%
 {empty}

\newterm
 [%
   symbol={\ensuremath{|\mathcal{S}|}},
   description={the number of elements in the set \ensuremath{\mathcal{S}}}
 ]%
 {cardinality}

\title{Sample Document Using the datagidx Package}
\author{Nicola L. C. Talbot}

\begin{document}
\pagenumbering{alph}% Stop hyperref complaining about duplicate page identifiers
\maketitle
\thispagestyle{empty}%

\frontmatter

\tableofcontents

\chapter{Summary}

This is a sample document illustrating the use of the
\texttt{datagidx} package to create document \glspl{index},
\glspl{glossarylist} and \glspl{acronymlist} without the use of
external \glsing{index} % custom command defined earlier
applications, such as \gls{makeindex} or
\gls{xindy}. Please read the user guide (datatool-user.pdf) for
further guidance.

\mainmatter

\chapter{Introduction}
%\renewcommand{\thepage}{\numberstring{page}}

Words can be \glsed{index}. % custom command defined earlier.

A \gls{glossarylist}\glsadd{[principleloc]ind-glossary} is a useful addition to any technical document,
although a \gls{glossarycol} can also simply be a collection of
glosses, which is another thing entirely. Some documents have
multiple \glspl{glossarylist}.

A \gls{bravocry} is a cry of approval (plural \glspl{bravocry}) but a 
\gls{bravokiller} can also be a hired ruffian or killer (plural
\glspl{bravokiller}).

\section{Characters}

When defining entries be careful of \glspl{comma} and \glspl{equals}
so they don't interfere with the key=value mechanism. The sort and
label keys get expanded so be careful of special characters, such as
\gls{amp}, \gls{underscore}, \gls{circum}, \gls{dollar} and \gls{tilde}.

Since we're not using \gls{makeindex}, we don't need to worry about
\gls{makeindex}'s special characters, such as \gls{"}, \gls{!} and
\gls{|}. (Unless they've been made active by packages such as
\texttt{ngerman} or \texttt{babel}.)

Non-alphabetical characters are usually grouped at the start of an
index, and are usually followed by the number group. That is, the
group of entries that are numerical, such as \gls{0}, \gls{1},
\gls{2} and \gls{3}.

\section{Custom Fields}

You can add custom fields. For example, this document has added
three custom fields to the `index' database.

\section{Plurals}

The \gls{plural} of \gls{glossarylist} is
\glspl{glossarylist}. The \gls{plural} of \gls{index} is
\glspl{index}. Some words have an \gls{altplural}. For example,
an alternative to \glspl{index} is 
\glsaltpl{index}.% custom command defined earlier

\section{Sorting}

The only type of sorting available is letter sorting. If you want
word sorting you'll need to use \gls{makeindex} or \gls{xindy}.
So ``\gls{sea lion}'' comes after ``\gls{seal}''.

The default sort is case-insensitive so \gls{kite} before
\gls{knuth} and \gls{knuth} before \gls{koala}.

\section{Using without indexing}

Here's a defined entry that won't get into the glossary.
Name: \glsdispentry{pglist}{Name}.
Description: \glsdispentry{pglist}{Description}.
(Unless I~later reference it using a command like \verb|\gls|.)

\section{Links to Entries}

You can reference and index entries using \verb|\gls|, \verb|\Gls|,
\verb|\glspl|, \verb|\Glspl|, \verb|\glssym| and \verb|\Glssym|.
(Note, if you're used to using the \texttt{glossaries} package
the syntax is different.)

Or you can reference a particular field using \verb|\useentry| or
\verb|\Useentry|. So here's the description for \gls{seal}:
\useentry{seal}{Description}.

If the \texttt{hyperref} package has been loaded, commands like
\verb|\gls| will link to the relevant entry in the glossary or
index. Referencing using \verb|\glsdispentry| and
\verb|\Glsdispentry| won't have hyperlinks.

\subsection{Enabling and Disabling Hyperlinks}

If the \texttt{hyperref} package has been loaded, hyperlinks can be
enabled and disabled. Either globally
\DTLgidxDisableHyper
(here's a reference to \gls{seal} without a hyperlink 
\DTLgidxEnableHyper
 and here's a reference to \gls{seal} with a hyperlink)
or locally
({%
  \DTLgidxDisableHyper
  here's a reference to \gls{seal} without a hyperlink
}%
and here's a reference to \gls{seal} with a hyperlink).

\section{Acronyms}

\glsadd{firstuse}Here's an \gls{acronym} referenced using \verb|\acr|: \acr{html}. And here
it is again: \acr{html}. If you're used to the \texttt{glossaries}
package, note the difference in using \verb|\gls|: \gls{html}.
And again (no difference): \gls{html}.

Now let's switch to displaying acronyms with a footnote.
 % syntax: \DTLgidxAcrStyle{long}{short}
\renewcommand*{\DTLgidxAcrStyle}[2]{%
  #2\footnote{#1.}%
}%
First use: \acr{xml}. Next use: \acr{xml}.

However it would look better if the footnote text started with a
capital letter, so let's tweak things a bit.
 % syntax: \DTLgidxFormatAcr{label}{long field}{short field}
\renewcommand*{\DTLgidxFormatAcr}[3]{%
  \DTLgidxAcrStyle{\Glsdispentry{#1}{#2}}{\useentry{#1}{#3}}%
}%
 % syntax: \DTLgidxFormatAcr{label}{long field}{short field}
\renewcommand*{\DTLgidxFormatAcrUC}[3]{%
  \DTLgidxAcrStyle{\Glsdispentry{#1}{#2}}{\Useentry{#1}{#3}}%
}%
Try with another acronym: \acr{css}. Next use: \acr{css}.

\glsadd{reset}Reset: \glsresetall{acronyms}%
\renewcommand*{\DTLgidxAcrStyle}[2]{#1 (#2)}%
\renewcommand*{\DTLgidxFormatAcr}[3]{%
  \DTLgidxAcrStyle{\glsdispentry{#1}{#2}}{\useentry{#1}{#3}}%
}%
\renewcommand*{\DTLgidxFormatAcrUC}[3]{%
  \DTLgidxAcrStyle{\Glsdispentry{#1}{#2}}{\useentry{#1}{#3}}%
}%
Here are the acronyms again:
\acr{html}, \acr{xml} and \acr{css}.
Next use:
\acr{html}, \acr{xml} and \acr{css}.
Full form:
\gls{html}, \gls{xml} and \gls{css}.

Reset again. \glsresetall{acronyms}%
Start with a capital. \Acr{html}.
Next: \Acr{html}. Full: \Gls{html}.

Prefer small-caps?
\renewcommand{\acronymfont}[1]{\textsc{#1}}%
\Acr{css}. Next: \acr{css}. Full: \gls{css}.

Prefer capitals?
\renewcommand{\acronymfont}[1]{\MakeTextUppercase{#1}}%
\Acr{xml}. Next: \acr{xml}. Full: \gls{xml}.

\section{Conditionals}

You can test if a term has been defined using \verb|\iftermexists|.
For example: \iftermexists{seal}{seal exists}{seal doesn't exist}.
Another example: \iftermexists{jabberwocky}{jabberwocky
exists}{jabberwocky doesn't exist}.

You can test if a term has been used via \verb|ifentryused|.
For example: \ifentryused{seal}{seal has been used}{seal hasn't been
used.}
Another example: \ifentryused{pglist}{pglist has been used}{pglist
hasn't been used}.


\section{Symbols}

Terms may have an associated symbol. The symbol can be accessed
using \verb|\glssym| or if you don't want to add information to the
location list you can use \verb|\glsdispentry|. Here's the symbol
associated with the \gls{cardinality} entry:
\glsdispentry{cardinality}{Symbol}.

A \gls{set} (denoted \glssym{set}) is a collection of objects.
The \gls{universal} is the set of everything.
The \gls{empty} contains no elements.
The \gls{cardinality} of a set (denoted \glssym{cardinality}) is the
number of elements in the set.

\section{Location Ranges}

A range is formed if a location sequence contains more than 2
locations. Here's \gls{seal} again.

\backmatter
 % suppress section numbering
\setcounter{secnumdepth}{-1}

\chapter{Glossaries}

\printterms
 [
   database=glossary,% 'glossary' database
   columns=1,% one column page layout
   postdesc=dot,% put a full stop after the description
   style=gloss,% use 'gloss' style (sub-entries numbered)
   namefont={\textbf},% put the name in bold
   namecase=firstuc,% make the first letter of the name upper case
   child=noname,% don't print sub item names
   childsort=false,% don't sort the child lists
%   location=hide% hide the location list
 ]

\printterms
 [
   database=acronyms,% 'acronyms' database
   postdesc=dot,% put a full stop after the description
   columns=1,% one column page layout
   namefont={\textbf},% put the name (i.e. the abbreviation) in bold
   namecase=uc,% make the name upper case
   style=align,% use the 'align' style
%   location=hide% hide the location list
 ]

\printterms
 [
   database=notation,% 'notation' database
   postdesc=dot,% put a full stop after the description
   columns=1,% one page column layout
   namefont={\textbf},% make the name bold
   style=indexalign,
   namecase=firstuc,% make first letter of name a capital
   symboldesc={desc (symbol)},% put symbol to the right of the description
   sort={}% don't sort
 ]

\printterms
 [
   database=index,% 'index' database
   prelocation=dotfill,% put a dotted line before the location list
   columns=2,% page layout 
   style=index,% use 'index' style
   %balance=false,% don't balance columns
   postheading={Locations in bold indicate primary reference.
    Locations in italic indicate definitions in the
    glossaries.}
 ]


\end{document}