summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/glossaries/samples/sample-nomathhyper.tex
blob: c1efc549d073d1979cb2d025c390131d4c096eb9 (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
 % 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 }
\documentclass{report}

\usepackage[colorlinks]{hyperref}
\usepackage{glossaries}

\makeglossaries

 % switch off hyperlinks:
\glsdisablehyper

 % redefine \glsentryfmt so that it adds a hyperlink
 % if not in math mode
\renewcommand*{\glsentryfmt}{%
  \ifmmode
    \glsgenentryfmt
  \else
    % Temporarily enable hyperlinks:
    \glsenablehyper
    \glshyperlink[\glsgenentryfmt]{\glslabel}%
    % Disable hyperlinks again
    \glsdisablehyper
  \fi
}

\renewcommand{\glossarypreamble}{\glsenablehyper}
\renewcommand{\glossarypostamble}{\glsdisablehyper}

 % define a sample entry:
\newglossaryentry{x}{name={x},description={sample entry}}

\begin{document}
\chapter{Sample}
In text mode: \gls{x}. Inline maths: $\gls{x}$. Displayed
maths:
\[
  \gls{x}
\]

Back to text mode again: \gls{x}.

\printglossaries
\end{document}