Debian Codegraph @

texmf-dist/doc/latex/datatool/samples/sample-gidx.tex

raw
1 \documentclass{book}
2
3 \usepackage
4 [
5 % optimize=high,
6 % verbose
7 ]
8 {datagidx}
9
10 \usepackage[colorlinks]{hyperref}
11
12 % Define some convenient commands
13
14 \newcommand*{\principleloc}[1]{\textbf{#1}}
15 \newcommand*{\glossaryloc}[1]{\textit{#1}}
16 \newcommand*{\appname}[1]{\texttt{#1}}
17
18 % Don't let \appname interfere with the sorting and labelling of
19 % terms:
20
21 \appto\newtermlabelhook{\let\appname\DTLgidxNoFormat}
22
23 % (datagidx also does this for \MakeUppercase, \MakeTextUppercase,
24 % \MakeLowercase, \MakeTextLowercase, \textsc and \acronymfont.)
25
26 % Make an index database labelled 'index' with given title.
27 % (Omit optional argument to affect all indexing databases
28 % or use a comma-separated list of labels for each database
29 % to affect.)
30
31 \newgidx[heading=\chapter]{index}{Index}
32
33 % Add custom fields to the 'index' database
34
35 \newtermaddfield[index]{Ed}{ed}{\field{text}ed}
36
37 \newtermaddfield[index]{Ing}{ing}{\field{text}ing}
38
39 \newtermaddfield[index]{AltPlural}{altplural}{}% no default value
40
41 % Define some convenience commands to access these fields
42
43 \newcommand*{\glsed}[1]{\useentry{#1}{Ed}}
44 \newcommand*{\glsing}[1]{\useentry{#1}{Ing}}
45 \newcommand*{\glsaltpl}[1]{\useentry{#1}{AltPlural}}
46
47 % Make a glossary database labelled 'glossary' with given title.
48
49 \newgidx[heading=\section]{glossary}{Glossary}
50
51 % Make an acronym database labelled 'acronyms' with given title.
52 % A different heading for the table of contents is supplied.
53
54 \newgidx[heading={\section[Acronyms]}]{acronyms}{List of Acronyms}
55
56 % Make a notation database labelled 'notation' with given title
57
58 \newgidx[heading=\section]{notation}{Notation}
59
60 % Define some terms for the index
61
62 % Either use "database" key in optional argument
63 % or set the default database. It's less typing to set the default
64 % database, so let's do that:
65
66 \DTLgidxSetDefaultDB{index}
67
68 % These definitions will add terms to the "index" database:
69
70 \newterm{walk}
71
72 \newterm{singular}
73 \newterm{plural}
74 \newterm
75 [% options
76 label=pluralalt,
77 parent=plural,
78 see={altplural}
79 ]
80 {alternative}
81 \newterm[label=altplural]{alternative plural}
82 \newterm{group}
83 \newterm[see=group]{scope}
84
85 \newterm[label={ind-glossary}]{glossary}
86
87 \newterm
88 [%
89 label={ind-index},
90 seealso={ind-glossary},
91 ]
92 {index}
93
94 \newterm
95 [
96 seealso={ind-glossary}
97 ]
98 {acronym}
99 \newterm[parent=acronym]{reset}
100
101 \newterm
102 [%
103 parent=acronym,
104 label={firstuse},
105 ]
106 {first use}
107
108 \newterm
109 [%
110 parent=acronym,
111 label={acronymlist},
112 text={list of acronyms},
113 plural={lists of acronyms}
114 ]
115 {list}
116
117 % Be careful if a value contains a comma or an equal sign. The
118 % entire value must be grouped.
119 \newterm
120 [%
121 label={comma},
122 sort={,},
123 text={comma (,)},
124 plural={commas (,)}
125 ]%
126 {, (comma)}
127
128 \newterm
129 [%
130 label={equals},
131 sort={=},
132 text={equal sign (=)},
133 plural={equal signs (=)},
134 ]%
135 {= (equal sign)}
136
137 % Don't need to worry about makeindex's special characters (since
138 % we're not using makeindex!)
139 \newterm
140 [%
141 label={"},
142 sort={"},
143 text={double quote (")},
144 plural={double quotes (")},
145 ]%
146 {" (double quote)}
147
148 \newterm
149 [%
150 label={!},
151 sort={!},
152 text={exclamation mark (!)},
153 plural={exclamation marks (!)},
154 ]%
155 {! (exclamation mark)}
156
157 \newterm
158 [%
159 label={|},
160 sort={|},
161 text={vertical bar (\textbar)},
162 plural={vertical bars (\textbar)},
163 ]%
164 {\textbar\ (vertical bar)}
165
166
167 % Be careful of special characters
168
169 \newterm
170 [%
171 label={amp},
172 sort={\DTLgidxStripBackslash{\&}},
173 text={ampersand (\&)},
174 plural={ampersands (\&)},
175 ]
176 {\& (ampersand)}
177
178 \newterm
179 [%
180 label={underscore},
181 sort={\DTLgidxStripBackslash{\_}},
182 text={underscore (\_)},
183 plural={underscores (\_)},
184 ]
185 {\_ (underscore)}
186
187 \newterm
188 [%
189 label={dollar},
190 sort={\DTLgidxStripBackslash{\$}},
191 text={dollar (\$)},
192 plural={dollars (\$)},
193 ]
194 {\$ (dollar)}
195
196 \newterm
197 [%
198 label={circum},
199 sort={\DTLgidxStripBackslash{\^}},
200 text={circumflex (\textasciicircum)},
201 plural={circumflexes (\textasciicircum)},
202 ]
203 {\textasciicircum\ (circumflex)}
204
205 \newterm
206 [%
207 label={tilde},
208 sort={\string~},
209 text={tilde (\textasciitilde)},
210 plural={tildes (\textasciitilde)},
211 ]
212 {\textasciitilde\ (tilde)}
213
214 \newterm
215 [
216 label={0},
217 sort={0},
218 ]
219 {0 (zero)}
220
221 \newterm
222 [
223 label={1},
224 sort={1},
225 ]
226 {1 (one)}
227
228 \newterm
229 [
230 label={2},
231 sort={2},
232 ]
233 {2 (two)}
234
235 \newterm
236 [
237 label={3},
238 sort={3},
239 ]
240 {3 (three)}
241
242 % Let's index a person
243 \newterm
244 [%
245 label={knuth},
246 text={Knuth},
247 ]
248 {Knuth, Donald E.}
249
250 % and have a few more entries in the same letter group to test case
251 % ordering:
252 \newterm{kite}
253 \newterm{koala}
254
255 % Earlier I modified \newtermlabelhook so
256 % that \appname won't interfere with the sorting
257 % and labelling mechanism, so I don't need to specify separate sort
258 % and label keys here:
259
260 \newterm{\appname{makeindex}}% label and sort both set to just 'makeindex'
261 \newterm{\appname{xindy}}% label and sort both set to just 'xindy'
262
263 % Define some terms for the glossary
264
265 \DTLgidxSetDefaultDB{glossary}
266
267 \newterm[description={sea mammal with flippers that eats fish}]{seal}
268 \newterm[description={large seal},seealso={seal}]{sea lion}
269
270 \newterm{bravo}
271 \newterm
272 [%
273 label=bravocry,
274 description={cry of approval (pl.\ bravos)},
275 parent=bravo
276 ]
277 {bravo}
278 \newterm
279 [% options
280 label=bravokiller,
281 description={hired ruffian or killer (pl.\ bravoes)},
282 plural=bravoes,
283 parent=bravo
284 ]
285 {bravo}
286
287 \newterm
288 [%
289 plural={indices\glsadd{ind-index}},
290 altplural={indexes},
291 text={index\glsadd{ind-index}},
292 description={an alphabetical list of names or subjects with
293 references to their location in the document (pl.\ indices or
294 indexes)}
295 ]
296 {index\glsadd{[glossaryloc]ind-index}}
297
298 \newterm
299 [% options
300 text={glossary\glsadd{ind-glossary}},
301 plural={glossaries\glsadd{ind-glossary}},
302 seealso={index}%
303 ]%
304 {glossary\glsadd{ind-glossary}}
305
306 \newterm
307 [% options
308 label=glossarycol,
309 text={glossary\glsadd{ind-glossary}},
310 plural={glossaries\glsadd{ind-glossary}},
311 description={collection of glosses},
312 parent=glossary
313 ]
314 {glossary\glsadd{[glossaryloc]ind-glossary}}
315
316 \newterm
317 [% options
318 label=glossarylist,
319 text={glossary\glsadd{ind-glossary}},
320 plural={glossaries\glsadd{ind-glossary}},
321 description={list of technical words},
322 parent=glossary
323 ]
324 {glossary\glsadd{[glossaryloc]ind-glossary}}
325
326 \newterm
327 [% options
328 label=pglist,
329 % description contains commas so it must be grouped
330 description={a list of individual pages or page ranges
331 (e.g.\ 1,2,4,7--9)}
332 ]
333 {page list}
334
335 % define some acronyms
336
337 \DTLgidxSetDefaultDB{acronyms}
338
339 % Let's redefine \newacro so that the short form is also indexed:
340
341 \renewcommand{\newacro}[3][]{%
342 \newterm[database=index,label={ind-#2-long},see={ind-#2}]{#3}%
343 \newterm[database=index,label={ind-#2}]{\acronymfont{#2}}%
344 \newterm
345 [%
346 description={\capitalisewords{#3}},% long form capitalised
347 text={\DTLgidxAcrStyle{#3}{\acronymfont{#2}}},% produced via \gls
348 plural={\DTLgidxAcrStyle{#3}{\acronymfont{#2}}},% produced via \glspl
349 short={\acronymfont{#2}\glsadd{ind-#2}},% short form
350 long={#3},% long form
351 sort={#2},% sort on short form
352 #1%
353 ]%
354 {#2\glsadd{[glossaryloc]ind-#2}}
355 }
356
357 \newacro{html}{hyper-text markup language}
358 \newacro{css}{cascading style sheet}
359 \newacro{xml}{extensible markup language}
360
361 % define some notation
362
363 \DTLgidxSetDefaultDB{notation}
364
365 \newterm
366 [%
367 symbol={\ensuremath{\mathcal{S}}},
368 description={a collection of distinct objects},
369 ]%
370 {set}
371
372 \newterm
373 [%
374 parent=set,
375 symbol={\ensuremath{\mathcal{U}}},
376 text={universal set},
377 description={the set containing everything}
378 ]%
379 {universal}
380
381 \newterm
382 [%
383 parent=set,
384 symbol={\ensuremath{\emptyset}},
385 text={empty set},
386 description={the set with no elements}
387 ]%
388 {empty}
389
390 \newterm
391 [%
392 symbol={\ensuremath{|\mathcal{S}|}},
393 description={the number of elements in the set \ensuremath{\mathcal{S}}}
394 ]%
395 {cardinality}
396
397 \title{Sample Document Using the datagidx Package}
398 \author{Nicola L. C. Talbot}
399
400 \begin{document}
401 \pagenumbering{alph}% Stop hyperref complaining about duplicate page identifiers
402 \maketitle
403 \thispagestyle{empty}%
404
405 \frontmatter
406
407 \tableofcontents
408
409 \chapter{Summary}
410
411 This is a sample document illustrating the use of the
412 \texttt{datagidx} package to create document \glspl{index},
413 \glspl{glossarylist} and \glspl{acronymlist} without the use of
414 external \glsing{ind-index} % custom command defined earlier
415 applications, such as \gls{makeindex} or
416 \gls{xindy}. Please read the user guide (datatool-user.pdf) for
417 further guidance.
418
419 \mainmatter
420
421 \chapter{Introduction}
422 %\renewcommand{\thepage}{\numberstring{page}}
423
424 Words can be \glsed{ind-index}. % custom command defined earlier.
425
426 A \gls{glossarylist}\glsadd{[principleloc]ind-glossary} is a useful addition to any technical document,
427 although a \gls{glossarycol} can also simply be a collection of
428 glosses, which is another thing entirely. Some documents have
429 multiple \glspl{glossarylist}.
430
431 A \gls{bravocry} is a cry of approval (plural \glspl{bravocry}) but a
432 \gls{bravokiller} can also be a hired ruffian or killer (plural
433 \glspl{bravokiller}).
434
435 \section{Characters}
436
437 When defining entries be careful of \glspl{comma} and \glspl{equals}
438 so they don't interfere with the key=value mechanism. The sort and
439 label keys get expanded so be careful of special characters, such as
440 \gls{amp}, \gls{underscore}, \gls{circum}, \gls{dollar} and \gls{tilde}.
441
442 Since we're not using \gls{makeindex}, we don't need to worry about
443 \gls{makeindex}'s special characters, such as \gls{"}, \gls{!} and
444 \gls{|}. (Unless they've been made active by packages such as
445 \texttt{ngerman} or \texttt{babel}.)
446
447 Non-alphabetical characters are usually grouped at the start of an
448 index, and are usually followed by the number group. That is, the
449 group of entries that are numerical, such as \gls{0}, \gls{1},
450 \gls{2} and \gls{3}.
451
452 \section{Custom Fields}
453
454 You can add custom fields. For example, this document has added
455 three custom fields to the `index' database.
456
457 \section{Plurals}
458
459 The \gls{plural} of \gls{glossarylist} is
460 \glspl{glossarylist}. The \gls{plural} of \gls{index} is
461 \glspl{index}. Some words have an \gls{altplural}. For example,
462 an alternative to \glspl{index} is
463 \glsaltpl{ind-index}.% custom command defined earlier
464
465 \section{Sorting}
466
467 The only type of sorting available is letter sorting. If you want
468 word sorting you'll need to use \gls{makeindex} or \gls{xindy}.
469 So ``\gls{sea lion}'' comes after ``\gls{seal}''.
470
471 The default sort is case-insensitive so \gls{kite} before
472 \gls{knuth} and \gls{knuth} before \gls{koala}.
473
474 \section{Using without indexing}
475
476 Here's a defined entry that won't get into the glossary.
477 Name: \glsdispentry{pglist}{Name}.
478 Description: \glsdispentry{pglist}{Description}.
479 (Unless I~later reference it using a command like \verb|\gls|.)
480
481 \section{Links to Entries}
482
483 You can reference and index entries using \verb|\gls|, \verb|\Gls|,
484 \verb|\glspl|, \verb|\Glspl|, \verb|\glssym| and \verb|\Glssym|.
485 (Note, if you're used to using the \texttt{glossaries} package
486 the syntax is different.)
487
488 Or you can reference a particular field using \verb|\useentry| or
489 \verb|\Useentry|. So here's the description for \gls{seal}:
490 \useentry{seal}{Description}.
491
492 If the \texttt{hyperref} package has been loaded, commands like
493 \verb|\gls| will link to the relevant entry in the glossary or
494 index. Referencing using \verb|\glsdispentry| and
495 \verb|\Glsdispentry| won't have hyperlinks.
496
497 \subsection{Enabling and Disabling Hyperlinks}
498
499 If the \texttt{hyperref} package has been loaded, hyperlinks can be
500 enabled and disabled. Either globally
501 \DTLgidxDisableHyper
502 (here's a reference to \gls{seal} without a hyperlink
503 \DTLgidxEnableHyper
504 and here's a reference to \gls{seal} with a hyperlink)
505 or locally
506 ({%
507 \DTLgidxDisableHyper
508 here's a reference to \gls{seal} without a hyperlink
509 }%
510 and here's a reference to \gls{seal} with a hyperlink).
511
512 \section{Acronyms}
513
514 \glsadd{firstuse}Here's an \gls{acronym} referenced using \verb|\acr|: \acr{html}. And here
515 it is again: \acr{html}. If you're used to the \texttt{glossaries}
516 package, note the difference in using \verb|\gls|: \gls{html}.
517 And again (no difference): \gls{html}.
518
519 Now let's switch to displaying acronyms with a footnote.
520 % syntax: \DTLgidxAcrStyle{long}{short}
521 \renewcommand*{\DTLgidxAcrStyle}[2]{%
522 #2\footnote{#1.}%
523 }%
524 First use: \acr{xml}. Next use: \acr{xml}.
525
526 However it would look better if the footnote text started with a
527 capital letter, so let's tweak things a bit.
528 % syntax: \DTLgidxFormatAcr{label}{long field}{short field}
529 \renewcommand*{\DTLgidxFormatAcr}[3]{%
530 \DTLgidxAcrStyle{\Glsdispentry{#1}{#2}}{\useentry{#1}{#3}}%
531 }%
532 % syntax: \DTLgidxFormatAcr{label}{long field}{short field}
533 \renewcommand*{\DTLgidxFormatAcrUC}[3]{%
534 \DTLgidxAcrStyle{\Glsdispentry{#1}{#2}}{\Useentry{#1}{#3}}%
535 }%
536 Try with another acronym: \acr{css}. Next use: \acr{css}.
537
538 \glsadd{reset}Reset: \glsresetall{acronyms}%
539 \renewcommand*{\DTLgidxAcrStyle}[2]{#1 (#2)}%
540 \renewcommand*{\DTLgidxFormatAcr}[3]{%
541 \DTLgidxAcrStyle{\glsdispentry{#1}{#2}}{\useentry{#1}{#3}}%
542 }%
543 \renewcommand*{\DTLgidxFormatAcrUC}[3]{%
544 \DTLgidxAcrStyle{\Glsdispentry{#1}{#2}}{\useentry{#1}{#3}}%
545 }%
546 Here are the acronyms again:
547 \acr{html}, \acr{xml} and \acr{css}.
548 Next use:
549 \acr{html}, \acr{xml} and \acr{css}.
550 Full form:
551 \gls{html}, \gls{xml} and \gls{css}.
552
553 Reset again. \glsresetall{acronyms}%
554 Start with a capital. \Acr{html}.
555 Next: \Acr{html}. Full: \Gls{html}.
556
557 Prefer small-caps?
558 \renewcommand{\acronymfont}[1]{\textsc{#1}}%
559 \Acr{css}. Next: \acr{css}. Full: \gls{css}.
560
561 Prefer capitals?
562 \renewcommand{\acronymfont}[1]{\MakeUppercase{#1}}%
563 \Acr{xml}. Next: \acr{xml}. Full: \gls{xml}.
564
565 \section{Conditionals}
566
567 You can test if a term has been defined using \verb|\iftermexists|.
568 For example: \iftermexists{seal}{seal exists}{seal doesn't exist}.
569 Another example: \iftermexists{jabberwocky}{jabberwocky
570 exists}{jabberwocky doesn't exist}.
571
572 You can test if a term has been used via \verb|ifentryused|.
573 For example: \ifentryused{seal}{seal has been used}{seal hasn't been
574 used.}
575 Another example: \ifentryused{pglist}{pglist has been used}{pglist
576 hasn't been used}.
577
578
579 \section{Symbols}
580
581 Terms may have an associated symbol. The symbol can be accessed
582 using \verb|\glssym| or if you don't want to add information to the
583 location list you can use \verb|\glsdispentry|. Here's the symbol
584 associated with the \gls{cardinality} entry:
585 \glsdispentry{cardinality}{Symbol}.
586
587 A \gls{set} (denoted \glssym{set}) is a collection of objects.
588 The \gls{universal} is the set of everything.
589 The \gls{empty} contains no elements.
590 The \gls{cardinality} of a set (denoted \glssym{cardinality}) is the
591 number of elements in the set.
592
593 \section{Location Ranges}
594
595 A range is formed if a location sequence contains more than 2
596 locations. Here's \gls{seal} again.
597
598 \backmatter
599 % suppress section numbering
600 \setcounter{secnumdepth}{-1}
601
602 \chapter{Glossaries}
603
604 \printterms
605 [
606 database=glossary,% 'glossary' database
607 columns=1,% one column page layout
608 postdesc=dot,% put a full stop after the description
609 style=gloss,% use 'gloss' style (sub-entries numbered)
610 namefont={\textbf},% put the name in bold
611 namecase=firstuc,% make the first letter of the name upper case
612 child=noname,% don't print sub item names
613 childsort=false,% don't sort the child lists
614 % location=hide% hide the location list
615 ]
616
617 \printterms
618 [
619 database=acronyms,% 'acronyms' database
620 postdesc=dot,% put a full stop after the description
621 columns=1,% one column page layout
622 namefont={\textbf},% put the name (i.e. the abbreviation) in bold
623 namecase=uc,% make the name upper case
624 style=align,% use the 'align' style
625 % location=hide% hide the location list
626 ]
627
628 \printterms
629 [
630 database=notation,% 'notation' database
631 postdesc=dot,% put a full stop after the description
632 columns=1,% one page column layout
633 namefont={\textbf},% make the name bold
634 style=indexalign,
635 namecase=firstuc,% make first letter of name a capital
636 symboldesc={desc (symbol)},% put symbol to the right of the description
637 sort={}% don't sort
638 ]
639
640 \printterms
641 [
642 database=index,% 'index' database
643 prelocation=dotfill,% put a dotted line before the location list
644 columns=2,% page layout
645 style=index,% use 'index' style
646 %balance=false,% don't balance columns
647 postheading={Locations in bold indicate primary reference.
648 Locations in italic indicate definitions in the
649 glossaries.}
650 ]
651
652
653 \end{document}