summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/xcpdftips/xcpdftips.sty
blob: bbbe40639e42821939426fcc1d58e0beca4cb09c (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
%%
%% This is file `xcpdftips.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xcpdftips.dtx  (with options: `package')
%% 
%% =============================================
%% IMPORTANT NOTICE:
%% 
%% This program is free software: you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%% 
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%% 
%% You should have received a copy of the GNU General Public License
%% along with this program.  If not, see <https://www.gnu.org/licenses/>.
%% 
%% This is a generated file.
%% It may not be distributed without the original source file xcpdftips.dtx.
%% 
%% Full documentation can be obtained by LaTeXing that original file.
%% Only a few abbreviated comments remain here to describe the usage.
%% =============================================
%% 
%% Copyright (c) 2019 Mikica Kocic

\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{xcpdftips}
[2019/03/18 xcpdftips.sty v1.1 - (c) 2019 Mikica Kocic]

\RequirePackage{bibentry}
\RequirePackage{pdfcomment}
\RequirePackage{xparse}
\RequirePackage{etoolbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\ifXCP@redefcite\XCP@redefcitefalse
\newif\ifXCP@useocg\XCP@useocgfalse
\newif\ifXCP@usetcolorbox\XCP@usetcolorboxfalse

\DeclareOption{redefcite}{\XCP@redefcitetrue}
\DeclareOption{ocg}{\XCP@useocgtrue}
\DeclareOption{tcolorbox}{\XCP@usetcolorboxtrue}

\ProcessOptions\relax
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifXCP@useocg
 \ifXCP@usetcolorbox
  \ifx\tcolorbox\undefined
    \RequirePackage{tcolorbox}
  \fi
  \newcommand{\XCP@tooltipbox}[3]{%
    \begin{tcolorbox}[colframe=#1, colback=#2,%
        width=1.02\columnwidth, arc=2pt,%
        boxsep=2pt, top=0ex, bottom=0ex, left=0.1em, right=0.1em%
      ]\normalfont\small #3\end{tcolorbox}%
  }
 \else
  \newcommand{\XCP@tooltipbox}[3]{%
    \fcolorbox{#1}{#2}%
      {\parbox[t]{\columnwidth}{\normalfont\small #3}}%
  }
 \fi
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifXCP@useocg

\RequirePackage{pdfbase,ocgbase}

\RequirePackage{expl3}
\RequirePackage{calc,linegoal}
\RequirePackage{xcolor}


\ExplSyntaxOn

\msg_set:nnnn{xcpdftips}{support~outdated}{
  Support~package~`#1'~too~old.
}{
  Get~an~up~to~date~version~of~`#1'.\\Aborting.
}
\@ifpackagelater{pdfbase}{2018/04/06}{}{
  \msg_error:nnn{xcpdftips}{support~outdated}{pdfbase.sty}
  \tex_endinput:D
}
\@ifpackagelater{ocgbase}{2018/04/06}{}{
  \msg_error:nnn{xcpdftips}{support~outdated}{ocgbase.sty}
  \tex_endinput:D
}

\let\XCP@pdfLink\pbs_pdflink:nn  % Alias for the pdflink from pdfbase

\ExplSyntaxOff


\ifx\Hy@setpdfborder\undefined\else
  \let\Hy@setpdfborderOrig\Hy@setpdfborder
  \def\Hy@setpdfborder{\ocgbase@insert@oc\Hy@setpdfborderOrig}%
\fi

\newsavebox{\XCP@tipText} % Temporary savebox
\newlength{\XCP@hOffset} \setlength\XCP@hOffset{-0.1em}
\newlength{\XCP@vOffset} \setlength\XCP@vOffset{0.2ex}
\newlength{\XCP@lineGoal}

\NewDocumentCommand{\XCP@ocgtooltip}{%
  m % link text
  O{yellow!5} % tooltip box color
  m % tooltip text
}{{%
  \leavevmode%
  % Create a new PDF layer
  \ocgbase@new@ocg{ref [\XCP@keys]}{%
    /Print<</PrintState/OFF>> %
    /Export<</ExportState/OFF>> %
    /View<</ViewState/OFF>> %
  }{invisible}%
  \edef\XCP@currentOcg{\ocgbase@last@ocg}%
  % Insert the PDF layer into the order hierarchy (shown in the 'Layers' tab)
  \ocgbase@tree@node@begin%
  \XCP@currentOcg%
  \ocgbase@tree@node@end%
  % Disable the simultaneous visibility of multiple tooltips
  \ocgbase@add@ocg@to@radiobtn@grp{tool@tips}{\ocgbase@last@ocg}%
  % Emit the <link text> using \pbs_pdflink:nn
  \XCP@pdfLink{%
    /Subtype/Link/Border[0 0 0]/A %
      <</S/SetOCGState/State [/Toggle \XCP@currentOcg]>> %
  }{#1}%
  % Create a savebox for the <tooltip text> on the PDF layer
  \sbox\XCP@tipText{%
    \ocgbase@oc@bdc{\XCP@currentOcg}%
    \ocgbase@open@stack@push{\XCP@currentOcg}%
      \XCP@tooltipbox{black!50}{#2}{#3}%
    \ocgbase@oc@emc%
    \ocgbase@open@stack@pop%
    \null%
  }%
  % Emit the savebox (at this point we have dimensions to calc the offset)
  \raisebox{%
    \heightof{#1} + \the\dp\XCP@tipText + \XCP@vOffset%
  }[0pt][0pt]{%
    \makebox[0pt][l]{\relax%
      \setlength\XCP@lineGoal{\linegoal}%
      \hspace{\dimexpr\XCP@lineGoal - \linewidth + \XCP@hOffset \relax}%
      \usebox{\XCP@tipText}%
    }%
  }%
}}

\fi%XCP@useocg
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newsavebox{\XCP@keynum} % Temp box for getting citation numbers using \citenum

\ExplSyntaxOn

\NewDocumentCommand{ \XCP@enumeratetips }%
{ > { \SplitList , } m }%
{%
  \global\undef\XCP@tips%
  \global\undef\XCP@keys%
  \tl_map_inline:nn {#1}%
  {%
    \ifx\XCP@tips\undefined%
      \global\def\XCP@keys{}%
      \sbox\XCP@keynum{\citenum{##1}}%
      \expandafter\xdef\csname XCP@k@##1\endcsname{\NAT@num}%
      \xappto{\XCP@keys}{\NAT@num}%
      \global\def\XCP@tips{}%
      \gappto{\XCP@tips}{[\textbf{\@nameuse{XCP@k@##1}}]\ %
        {\@nameuse{BR@r@##1\@extra@b@citeb}}}%
    \else%
      \sbox\XCP@keynum{\citenum{##1}}%
      \expandafter\xdef\csname XCP@k@##1\@extra@b@citeb\endcsname{\NAT@num}%
      \xappto{\XCP@keys}{,\NAT@num}%
      \gappto{\XCP@tips}{,\textCR[\textbf{\@nameuse{XCP@k@##1}}]\ %
        {\@nameuse{BR@r@##1\@extra@b@citeb}}}%
    \fi%
  }%
}

\ExplSyntaxOff
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef\XCP@opt@author{{}}
\newcommand{\xcsetauthor}[1]{\gdef\XCP@opt@author{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef\XCP@opt@markup{Underline}
\newcommand{\xcsetmarkup}[1]{\gdef\XCP@opt@markup{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef\XCP@opt@color{1 1 0}
\newcommand{\xcsetcolor}[1]{\gdef\XCP@opt@color{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef\XCP@opt@opacity{0}
\newcommand{\xcsetopacity}[1]{\gdef\XCP@opt@opacity{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\XCP@citetp{\@ifnextchar[{\XCP@@citetp}{\XCP@@citetp[]}}

\newcommand\XCP@@citetp{}
\def\XCP@@citetp[#1]{\@ifnextchar[{\XCP@citex[#1]}{\XCP@citex[][#1]}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\XCP@citex{}
\gdef\XCP@citex[#1][#2]#3%
  {%{\protect\NoHyper%
    \ifXCP@useocg%
      \let\textCR\par%
      \XCP@enumeratetips{#3}%
      \XCP@ocgtooltip%
        {{{\protect\NoHyper\XCP@oldcite[#1][#2]{#3}\protect\endNoHyper}}}%
        {\XCP@tips}%
    \else%
      \XCP@enumeratetips{#3}%
      \pdftooltip{\XCP@oldcite[#1][#2]{#3}}{\XCP@tips}%
      \pdfmarkupcomment[%
        author=\XCP@opt@author,%
        markup=\XCP@opt@markup,%
        color=\XCP@opt@color,%
        opacity=\XCP@opt@opacity,%
      ]{\vphantom{.}}{\XCP@tips}%
    \fi%
  }%\protect\endNoHyper}}

\let\XCP@oldcite\citep  % Save \citep (in the case if it becomes redefined)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\let\xpdfcite\XCP@citetp
\robustify{\xpdfcite}

\AtBeginDocument{\nobibliography*} % Necessary to get bibentries.

\ifXCP@redefcite % Override \cite
  \let\cite\xpdfcite
  \robustify{\cite} % Required for, e.g., captions
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 
%% <<<<< End of generated file <<<<<<
%% 
%%
%% End of file `xcpdftips.sty'.