summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/interfaces/interfaces-bookmark.sty
blob: 305e7af0b6fcfb01a4b79d94dd17b3cdabf830f2 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
%%
%% This is file `interfaces-bookmark.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% interfaces.dtx  (with options: `bookmark')
%% 
%% This is a generated file.
%% 
%% interfaces : 2011/02/19 v3.1 - interfaces : interfaces with keys for other packages (FC)
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 of this license or (at your option) any later
%% version. The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% 
%% This work consists of the main source file interfaces.dtx
%% and the derived files
%%     interfaces.sty, interfaces.pdf, interfaces.ins,
%%     interfaces-base.sty,
%%     interfaces-LaTeX.sty,
%%     interfaces-tikz.sty,
%%     interfaces-titlesec.sty,
%%     interfaces-hyperref.sty,
%%     interfaces-bookmark.sty,
%%     interfaces-hypbmsec.sty,
%%     interfaces-fancyhdr.sty,
%%     interfaces-marks.sty,
%%     interfaces-tocloft.sty,
%%     interfaces-makecell.sty,
%%     interfaces-enumitem.sty,
%%     interfaces-truncate.sty,
%%     interfaces-appendix.sty,
%%     interfaces-embedfile.sty,
%%     interfaces-environ.sty,
%%     interfaces-umrand.sty,
%%     interfaces-scrlfile.sty,
%%     interfaces-pgfkeys.sty,
%%     interfaces-etoolbox.sty
%% 
%% interfaces: interfaces with keys for other packages (FC)
%% Copyright (C) 2010 by Florent Chervet <florent.chervet@free.fr>
%% 
\ProvidesPackage{interfaces-bookmark}
   [2011/02/19 v3.1 more control on bookmarks (FC)]
\RequirePackage{interfaces-base}
\RequirePackage{interfaces-hyperref}
\RequirePackage{refcount}
\itf@Check@Package{bookmark}
\expandafter\itf@patch\expandafter\patchcmd\csname\string\bookmark\endcsname
   {\immediate\write\@mainaux}{\itf@BKM@write}
   {\@PackageInfoNoLine{interfaces-bookmark}
      {\expandafter\string\csname\string\bookmark\endcsname\space
      successfully patched!}}
   {\@PackageWarningNoLine{interfaces-bookmark}
      {Command \expandafter\string\csname\string\bookmark\endcsname\space
      could not be patched\MessageBreak
      Loading of interfaces-bookmark is canceled}%
      \endinput}
\global\let\itf@BKM@enable\@ne % 0 = disable*, 1=enable, \@M = disable
\pgfqkeys{/itf/bookmark}{%
   disable/.true=\global\let\itf@BKM@enable\@M,%
   disable/.false=\global\let\itf@BKM@enable\@ne,%
   disable*/.true=\global\let\itf@BKM@enable\z@,%
   disable*/.false=\global\let\itf@BKM@enable\@ne,%
   atend/.true=\ifnum\itf@BKM@enable>0\edef\itf@BKM@enable{\number-\itf@BKM@enable}\fi,%
   atend/.false=\ifnum\itf@BKM@enable<0\edef\itf@BKM@enable{\number-\itf@BKM@enable}\fi,%
   bold*/.true=\pgfqkeys{/itf/bookmark}{@save={bold=true}},%
   bold*/.false=\pgfqkeys{/itf/bookmark}{@save={bold=false}},%
   bold*/@blank/.code=\pgfqkeys{/itf/bookmark/@restore}{bold},%
   bold*/.blank=@blank,%
   italic*/.true=\pgfqkeys{/itf/bookmark}{@save={italic=true}},%
   italic*/.false=\pgfkeys{/itf/bookmark}{@save={italic=false}},%
   italic*/@blank/.code=\pgfqkeys{/itf/bookmark/@restore}{italic},%
   italic*/.blank=@blank,%
   color*/.code={\ifblank{#1}
      {\pgfqkeys{/itf/bookmark/@restore}{color}}
      {\pgfqkeys{/itf/bookmark}{@save={color={#1}}}}%
   },%
   @save/.code={%
      \pgfkeysifdefined{/itf/bookmark/@save/color}{}
         {\pgfkeyslet{/itf/bookmark/@save/color}\BKM@color}%
      \pgfkeysifdefined{/itf/bookmark/@save/FontStyle}{}
         {\pgfkeyslet{/itf/bookmark/@save/FontStyle}\BS@BKM@FontStyle}%
      \pgfkeysifdefined{/itf/bookmark/@save/grouplevel}{}
         {\pgfkeysEsetvalue{/itf/bookmark/@save/grouplevel}{\the\currentgrouplevel}}%
      \pgfkeysaddvalue{/itf/bookmark/*}{}{,#1}%
      \bookmarksetup{#1}%
   },%
   @restore/color/.code=%
      \pgfkeysifdefined{/itf/bookmark/@save/color}
         {\pgfkeysgetvalue{/itf/bookmark/@save/color}\BKM@color}
         {},%
   @restore/FontStyle/.code=%
      \pgfkeysifdefined{/itf/bookmark/@save/FontStyle}
         {\pgfkeysgetvalue{/itf/bookmark/@save/FontStyle}\BS@BKM@FontStyle}
         {},%
   @restore/.code={%
      \pgfkeysifdefined{/itf/bookmark/@save/color}
         {\pgfkeysgetvalue{/itf/bookmark/@save/color}\BKM@color}
         {}%
      \pgfkeysifdefined{/itf/bookmark/@save/FontStyle}
         {\pgfkeysgetvalue{/itf/bookmark/@save/FontStyle}\BS@BKM@FontStyle}
         {}%
      \pgfkeysifdefined{/itf/bookmark/@save/grouplevel}
         {% shortcut: \bookmarksetup{bold*} called inside main group (level 0)
         \ifnum\pgfkeysvalueof{/itf/bookmark/@save/grouplevel}=\z@
            \global\pgfkeyslet{/itf/bookmark/@save/FontStyle}\@undefined
            \global\pgfkeyslet{/itf/bookmark/@save/color}\@undefined
            \global\pgfkeyslet{/itf/bookmark/@save/grouplevel}\@undefined
            \global\pgfkeyslet{/itf/bookmark/*}\@undefined
            \global\let\BKM@color\BKM@color
            \global\let\BS@BKM@FontStyle\BS@BKM@FontStyle
         \else % restore after each group as needed
            \pgfkeyslet{/itf/bookmark/@save/FontStyle}\@undefined
            \pgfkeyslet{/itf/bookmark/@save/color}\@undefined
            \pgfkeyslet{/itf/bookmark/*}\@undefined
            \ifnum\currentgrouplevel>\z@
               \aftergroup\itf@BKM@restore
            \else
               \pgfkeyslet{/itf/bookmark/@save/grouplevel}\@undefined
         \fi\fi
         }
         {}%
   },%
   @restore/bold/.code={% bold is "hidden" in \BS@BKM@FontStyle
      \begingroup
         \edef\itf@tp{\bookmarkget{bold}}%
         \pgfqkeys{/itf/bookmark/@restore}{FontStyle}%
         \count@=\bookmarkget{bold}%
         \edef\itf@tp{\endgroup
            \ifnum\itf@tp=\count@
            \else \noexpand\bookmarksetup{%
                        bold\ifcase\count@ =false\fi}\fi
         }\itf@tp},%
   @restore/italic/.code={% italic is "hidden" in \BS@BKM@FontStyle
      \begingroup
         \edef\itf@tp{\bookmarkget{italic}}%
         \pgfqkeys{/itf/bookmark/@restore}{FontStyle}%
         \count@=\bookmarkget{italic}%
         \edef\itf@tp{\endgroup
            \ifnum\itf@tp=\count@
            \else \noexpand\bookmarksetup{%
                        italic\ifcase\count@ =false\fi}\fi
         }\itf@tp},%
}
\def\itf@BKM@restore{%
   \pgfkeysifdefined{/itf/bookmark/@save/grouplevel}
      {\pgfkeysalso{/itf/bookmark/@restore}}
      {}%
}% \itf@BKM@restore
%% Plug the BKM keys in the interfaces pgfkeys (not efficient but quickly written...)
\define@key{BKM}{disable}[true]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/disable={#1}}}
\define@key{BKM}{disable*}[true]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/disable*={#1}}}
\define@key{BKM}{bold*}[true]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/bold*={#1}}}
\define@key{BKM}{italic*}[true]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/italic*={#1}}}
\define@key{BKM}{color*}[]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/color*={#1}}}
\define@key{BKM}{atend}[true]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/atend={#1}}}%
\def\itf@BKM@write#1{%
   \aftergroup\itf@BKM@restore
   \ifcase\itf@BKM@enable
      \global\let\itf@BKM@enable\@ne
   \or
      \immediate\write\@mainaux{#1}%
   \else
      \ifcase -\itf@BKM@enable  % (case -0 = 0 tested before)
      \or                       % (case -1 = enable but At End)
         \let\itf@BKM@enable\@ne
         \edef\itf@tp{\immediate\write\@mainaux{#1}}%
         \expandafter\BookmarkAtEnd\expandafter{\itf@tp}%
      \fi
   \fi
}% \itf@BKM@write
%% pageref=  key for \bookmark (using refcount : \getpagerefnumber)
\def\itf@BKM@pageref[#1]{%
   \expandafter\itf@BKM@@pageref
      \csname r@#1\endcsname{#1}%
}% \itf@BKM@pageref
\def\itf@BKM@@pageref#1#2{%
   \ifx#1\relax
      \protect\G@refundefinedtrue
      \@latex@warning{%
         Hyper reference `#2' on page \thepage \space undefined
         \MessageBreak for bookmark destination page
       }%
   \fi
   \edef\BKM@page{\getrefbykeydefault{#2}{page}{1}}%
}% \itf@BKM@@pageref
\define@key{BKM}{pageref}{%
   \Hy@babelnormalise\itf@BKM@pageref[{#1}]}
%% ref=  key for \bookmark
\def\itf@BKM@ref[#1]{%
   \expandafter\itf@BKM@@ref
      \csname r@#1\endcsname{#1}%
}% \itf@BKM@ref
\def\itf@BKM@@ref#1#2{%
   \ifx#1\relax
      \protect\G@refundefinedtrue
      \@latex@warning{%
         Hyper reference `#2' on page \thepage \space undefined
         \MessageBreak for bookmark destination
       }%
      \def\BKM@dest{??}%
   \else
      \edef\BKM@dest{\expandafter\@fourthoffive#1\@empty\@empty}%
   \fi
}% \BKM@@ref
\define@key{BKM}{ref}{%
   \Hy@babelnormalise\itf@BKM@ref[{#1}]}
\endinput
%%
%% End of file `interfaces-bookmark.sty'.