summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/glossaries/samples/sample-nomathhyper.tex
blob: 21c797c3a4c23950a16ef89558e1881a4e4589c5 (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
% 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 }
%
%http://mirrors.ctan.org/macros/latex/contrib/glossaries/glossaries-user.html#sample-nomathhyper
\documentclass{report}

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

\GlsDeclareNoHyperList{main}

\makeglossaries

% redefine \glsentryfmt so that it adds a hyperlink
% if not in math mode and the hyperlinks haven't been forced on
\renewcommand*{\glsentryfmt}{%
  \ifmmode
    \glsgenentryfmt
  \else
    \glsifhyperon
    {\glsgenentryfmt}% hyperlink already on
    {\glshyperlink[\glsgenentryfmt]{\glslabel}}%
  \fi
}

% 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}. Don't check the first use flag:
\glstext{x}. Force on the hyperlink: \glstext+{x}.

\printglossaries
\end{document}