Debian Codegraph @

texmf-dist/doc/latex/glossaries/samples/sample-chap-hyperfirst.tex

raw
1 % This file is public domain
2 % If you want to use arara, you need the following directives:
3 % arara: pdflatex
4 % arara: makeglossaries
5 % arara: pdflatex
6 %
7 %http://mirrors.ctan.org/macros/latex/contrib/glossaries/glossaries-user.html#sample-chap-hyperfirst
8 \documentclass{report}
9
10 \usepackage[colorlinks]{hyperref}
11 \usepackage{glossaries}
12
13 \makeglossaries
14
15 \glsaddstoragekey{chapter}{0}{\glschapnum}
16
17 \loadglsentries{example-glossaries-brief}
18
19 \renewcommand*{\glslinkpostsetkeys}{%
20 \edef\currentchap{\arabic{chapter}}%
21 \ifnum\currentchap=\glschapnum{\glslabel}\relax
22 % Already used this entry in the current chapter, so switch
23 % off the hyperlink.
24 \setkeys{glslink}{hyper=false}%
25 \else
26 % Hasn't been used in the current chapter. Update the value
27 % of the "chapter" field unless the hyperlink has been switched
28 % off.
29 \glsifhyperon
30 {%
31 \glsfieldxdef{\glslabel}{chapter}{\currentchap}%
32 }%
33 {}%
34 \fi
35 }
36
37 \begin{document}
38 \chapter{Sample}
39
40 Use all entries: \forglsentries{\thislabel}{\gls{\thislabel}. }
41
42 Use them again: \forglsentries{\thislabel}{\gls{\thislabel}. }
43
44 \chapter{Another}
45
46 Use all entries: \forglsentries{\thislabel}{\gls{\thislabel}. }
47
48 Use them again: \forglsentries{\thislabel}{\gls{\thislabel}. }
49
50 \chapter{Start with a Star}
51
52 Use all entries but suppress hyperlink:
53 \forglsentries{\thislabel}{\gls*{\thislabel}. }
54
55 Use all entries: \forglsentries{\thislabel}{\gls{\thislabel}. }
56
57 Use them again: \forglsentries{\thislabel}{\gls{\thislabel}. }
58
59 \printglossaries
60
61 \end{document}