summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/glossaries-extra/sample-alttree-marginpar.tex
blob: 261e878f7333134ce607b45087724de5c3259c87 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
% arara: pdflatex
% arara: makeglossaries if found("aux", "@istfilename")
% arara: pdflatex
\documentclass[12pt]{book}

\usepackage[T1]{fontenc}
\usepackage{tgtermes}
\usepackage[dvipsnames]{xcolor}
\usepackage{pifont}
\usepackage{tikz}

\usepackage[colorlinks]{hyperref}
\usepackage[stylemods=tree,style=alttree,savenumberlist]{glossaries-extra}

\makeglossaries

\loadglsentries{example-glossaries-multipar}

\glssetcategoryattribute{general}{glossname}{firstuc}

\renewcommand*{\GlsXtrFormatLocationList}[1]{%
 {%
  \hypersetup{hidelinks}%
  \textcolor{Plum}{\ding{230}}~\textbf{#1}%
 }%
}

% Suppress hanging paragraphs:
%\renewcommand*{\glsxtrAltTreeSetHangIndent}{}

\newlength\maxlocwidth

\renewcommand*{\glsxtralttreeInit}{%
% setup lengths
  \glsFindWidestAnyNameLocation[\currentglossary]%
    {\maxlocwidth}%
  \settowidth
    {\glsxtrtreetopindent}%
    {\glstreenamefmt{\glsgetwidestname}}%
  \addtolength{\glsxtrtreetopindent}%
   {\dimexpr1em+2\nameinnersep+2\nameoutersep}%
  \addtolength{\maxlocwidth}{1em}%
  \glsxtrAltTreeIndent=\parindent
}

\newlength\nameinnersep
\nameinnersep=4pt
\newlength\nameoutersep
\nameoutersep=2pt

\renewcommand*{\glstreenamebox}[2]{%
  \makebox[#1][l]%
  {%
    \begin{tikzpicture}[baseline=(X.base)]
    \node[fill=Orchid,
          align=center,
          text width=\dimexpr#1-2\nameinnersep-2\nameoutersep,
          inner sep=\nameinnersep,
          outer sep=\nameoutersep
         ] (X) {#2};
    \end{tikzpicture}%
  }%
}

\newcommand*{\locbox}[1]{%
 \begin{tikzpicture}[baseline=(X.base)]
 \node[text width=\maxlocwidth,
       draw=CadetBlue,
       fill=CornflowerBlue,
       double,
       thick,
       align=center,
       rounded corners] 
  (X) {#1};
 \end{tikzpicture}%
}

\renewcommand{\glsxtralttreeSymbolDescLocation}[2]{%
  \marginpar[\hfill\locbox{#2}]{\locbox{#2}}%
  % scope \par change
  {%
    \let\par\glsxtrAltTreePar
    \glossentrydesc{#1}\glspostdescription\par
  }%
}

\begin{document}

\frontmatter
\chapter{Front Matter Test}
\forallglsentries{\thislabel}{\gls{\thislabel}.\newpage}

\mainmatter

\chapter{Main Matter Test}
\forallglsentries{\thislabel}{\gls{\thislabel}.\newpage}

\printglossaries

\end{document}