summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/glossaries/samples/sample-chap-hyperfirst.tex
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/glossaries/samples/sample-chap-hyperfirst.tex')
-rw-r--r--macros/latex/contrib/glossaries/samples/sample-chap-hyperfirst.tex59
1 files changed, 59 insertions, 0 deletions
diff --git a/macros/latex/contrib/glossaries/samples/sample-chap-hyperfirst.tex b/macros/latex/contrib/glossaries/samples/sample-chap-hyperfirst.tex
new file mode 100644
index 0000000000..4e74e2e059
--- /dev/null
+++ b/macros/latex/contrib/glossaries/samples/sample-chap-hyperfirst.tex
@@ -0,0 +1,59 @@
+ % This file is public domain
+ % If you want to use arara, you need the following directives:
+ % arara: pdflatex
+ % arara: makeglossaries
+ % arara: pdflatex
+\documentclass{report}
+
+\usepackage[colorlinks]{hyperref}
+\usepackage{glossaries}
+
+\makeglossaries
+
+\glsaddstoragekey{chapter}{0}{\glschapnum}
+
+\loadglsentries{example-glossaries-brief}
+
+\renewcommand*{\glslinkpostsetkeys}{%
+ \edef\currentchap{\arabic{chapter}}%
+ \ifnum\currentchap=\glschapnum{\glslabel}\relax
+ % Already used this entry in the current chapter, so switch
+ % off the hyperlink.
+ \setkeys{glslink}{hyper=false}%
+ \else
+ % Hasn't been used in the current chapter. Update the value
+ % of the "chapter" field unless the hyperlink has been switched
+ % off.
+ \glsifhyperon
+ {%
+ \glsfieldxdef{\glslabel}{chapter}{\currentchap}%
+ }%
+ {}%
+ \fi
+}
+
+\begin{document}
+\chapter{Sample}
+
+Use all entries: \forglsentries{\thislabel}{\gls{\thislabel}. }
+
+Use them again: \forglsentries{\thislabel}{\gls{\thislabel}. }
+
+\chapter{Another}
+
+Use all entries: \forglsentries{\thislabel}{\gls{\thislabel}. }
+
+Use them again: \forglsentries{\thislabel}{\gls{\thislabel}. }
+
+\chapter{Start with a Star}
+
+Use all entries but suppress hyperlink:
+\forglsentries{\thislabel}{\gls*{\thislabel}. }
+
+Use all entries: \forglsentries{\thislabel}{\gls{\thislabel}. }
+
+Use them again: \forglsentries{\thislabel}{\gls{\thislabel}. }
+
+\printglossaries
+
+\end{document}