summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/oberdiek/zref-xr.sty
blob: c14b713c02ba93db6c345f42af407df8fe54ee8a (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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
%%
%% This is file `zref-xr.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% zref.dtx  (with options: `xr')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2006-2011 by
%%    Heiko Oberdiek <heiko.oberdiek at googlemail.com>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. This version of this license is in
%%    http://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% This Current Maintainer of this work is Heiko Oberdiek.
%% 
%% This work consists of the main source file zref.dtx
%% and the derived files
%%    zref.sty, zref.pdf, zref.ins, zref.drv, zref-base.sty,
%%    zref-abspage.sty, zref-abspos.sty, zref-counter.sty,
%%    zref-dotfill.sty, zref-env.sty, zref-hyperref.sty,
%%    zref-lastpage.sty, zref-marks.sty, zref-nextpage.sty,
%%    zref-pageattr.sty, zref-pagelayout.sty, zref-perpage.sty,
%%    zref-runs.sty, zref-savepos.sty, zref-thepage.sty,
%%    zref-titleref.sty, zref-totpages.sty, zref-user.sty,
%%    zref-xr.sty, zref-example.tex, zref-example-lastpage.tex,
%%    zref-example-nextpage.tex, zref-test1.tex,
%%    zref-test-base.tex, zref-test-runs.tex,
%%    zref-test-titleref-memoir.tex.
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-xr}%
  [2011/03/18 v2.21 Module xr for zref (HO)]%
\RequirePackage{zref-base}[2011/03/18]
\ifx\ZREF@base@ok Y%
\else
  \expandafter\endinput
\fi
\RequirePackage{keyval}
\RequirePackage{kvoptions}[2010/02/22]
\zref@newprop{url}{}%
\zref@newprop{urluse}{}%
\zref@newprop{externaldocument}{}%
\providecommand*{\zref@xr@ext}{%
  \ltx@ifundefined{XR@ext}{pdf}{\XR@ext}%
}%
\newif\ifZREF@xr@zreflabel
\SetupKeyvalOptions{%
  family=ZREF@XR,%
  prefix=ZREF@xr@%
}
\DeclareBoolOption[true]{tozreflabel}
\DeclareBoolOption[false]{toltxlabel}
\DeclareBoolOption{verbose}
\define@key{ZREF@XR}{ext}{%
  \def\zref@xr@{#1}%
}
\DeclareBoolOption[false]{urluse}
\newcommand*{\zxrsetup}{%
  \kvsetkeys{ZREF@XR}%
}%
\newcount\ZREF@xr@URL
\ZREF@xr@URL=\ltx@zero
\def\ZREF@xr@AddURL#1{%
  \begingroup
    \def\ZREF@temp{#1}%
    \count@=\ltx@one
    \ZREF@xr@@AddUrl
  \endgroup
}
\def\ZREF@xr@@AddUrl{%
  \ifnum\count@>\ZREF@xr@URL
    \global\advance\ZREF@xr@URL by\ltx@one
    \xdef\ZREF@xr@theURL{\romannumeral\ZREF@xr@URL}%
    \global\expandafter\let
        \csname Z@U@\ZREF@xr@theURL\endcsname\ZREF@temp
    \@PackageInfo{zref-xr}{%
      \ltx@backslashchar Z@U@\ZREF@xr@theURL:\MessageBreak
      \ZREF@temp\MessageBreak
    }%
  \else
    \expandafter
    \ifx\csname Z@U@\romannumeral\count@\endcsname\ZREF@temp
      \xdef\ZREF@xr@theURL{\romannumeral\count@}%
    \else
      \expandafter\expandafter\expandafter\ZREF@xr@@AddUrl
    \fi
  \fi
}
\ZREF@IfDefinable\zexternaldocument\def{%
  {%
    \ZREF@NewPropAnchor
    \ZREF@NewPropTitle
    \begingroup
      \csname @safe@actives@true\endcsname
      \makeatletter
      \@ifstar{%
        \ZREF@xr@zreflabelfalse
        \@testopt\ZREF@xr@externaldocument{}%
      }{%
        \ZREF@xr@zreflabeltrue
        \@testopt\ZREF@xr@externaldocument{}%
      }%
  }%
}%
\def\ZREF@xr@externaldocument[#1]#2{%
    \def\ZREF@xr@prefix{#1}%
    \let\ZREF@xr@filelist\ltx@empty
    \edef\ZREF@xr@externalfile{#2}%
    \edef\ZREF@xr@file{\ZREF@xr@externalfile.aux}%
    \filename@parse{#2}%
    \@testopt\ZREF@xr@graburl{#2.\zref@xr@ext}%
}%
\def\ZREF@xr@graburl[#1]{%
    \edef\ZREF@xr@url{#1}%
    \ifZREF@xr@urluse
      \expandafter\ZREF@xr@AddURL\expandafter{\ZREF@xr@url}%
      \expandafter\def\expandafter\ZREF@xr@url
      \expandafter{\csname Z@U@\ZREF@xr@theURL\endcsname}%
    \fi
    \ZREF@xr@checkfile
  \endgroup
}%
\def\ZREF@xr@checkfile{%
  \openin\@inputcheck\ZREF@xr@file\relax
  \ifeof\@inputcheck
    \PackageWarning{zref-xr}{%
      File `\ZREF@xr@file' not found or empty,\MessageBreak
      labels not imported%
    }%
  \else
    \PackageInfo{zref-xr}{%
      Label \ifZREF@xr@zreflabel (zref) \fi
      import from `\ZREF@xr@file'%
    }%
    \def\ZREF@xr@found{0}%
    \def\ZREF@xr@ignored@empty{0}%
    \def\ZREF@xr@ignored@zref{0}%
    \def\ZREF@xr@ignored@ltx{0}%
    \ZREF@xr@processfile
    \closein\@inputcheck
    \begingroup
      \let\on@line\ltx@empty
      \PackageInfo{zref-xr}{%
        Statistics for `\ZREF@xr@file':\MessageBreak
        \ZREF@xr@found\space
        \ifZREF@xr@zreflabel zref\else LaTeX\fi\space
        label(s) found%
        \ifnum\ZREF@xr@ignored@empty>0 %
          ,\MessageBreak
          \ZREF@xr@ignored@empty\space empty label(s) ignored%
        \fi
        \ifnum\ZREF@xr@ignored@zref>0 %
          ,\MessageBreak
          \ZREF@xr@ignored@zref\space
          duplicated zref label(s) ignored%
        \fi
        \ifnum\ZREF@xr@ignored@ltx>0 %
          ,\MessageBreak
          \ZREF@xr@ignored@ltx\space
          duplicated latex label(s) ignored%
        \fi
      }%
    \endgroup
  \fi
  \ifx\ZREF@xr@filelist\ltx@empty
  \else
    \edef\ZREF@xr@file{%
      \expandafter\ltx@car\ZREF@xr@filelist\@nil
    }%
    \edef\ZREF@xr@filelist{%
      \expandafter\ltx@cdr\ZREF@xr@filelist\ltx@empty\@nil
    }%
    \expandafter\ZREF@xr@checkfile
  \fi
}%
\def\ZREF@xr@processfile{%
  \read\@inputcheck to\ZREF@xr@line
  \expandafter\ZREF@xr@processline\ZREF@xr@line..\ZREF@nil
  \ifeof\@inputcheck
  \else
    \expandafter\ZREF@xr@processfile
  \fi
}%
\long\def\ZREF@xr@processline#1#2#3\ZREF@nil{%
  \def\x{#1}%
  \toks@{#2}%
  \ifZREF@xr@zreflabel
    \ifx\x\ZREF@xr@zref@newlabel
      \expandafter
      \ZREF@xr@process@zreflabel\ZREF@xr@line...\ZREF@nil
    \fi
  \else
    \ifx\x\ZREF@xr@newlabel
      \expandafter
      \ZREF@xr@process@label\ZREF@xr@line...[]\ZREF@nil
    \fi
  \fi
  \ifx\x\ZREF@xr@@input
    \edef\ZREF@xr@filelist{%
      \etex@unexpanded\expandafter{\ZREF@xr@filelist}%
      {\filename@area\the\toks@}%
    }%
  \fi
}%
\def\ZREF@xr@process@zreflabel\zref@newlabel#1#2#3\ZREF@nil{%
  \edef\ZREF@xr@refname{Z@R@\ZREF@xr@prefix#1}%
  \edef\ZREF@xr@found{\the\numexpr\ZREF@xr@found+1\relax}%
  \def\x{#2}%
  \edef\ZREF@xr@tempname{$temp$}%
  \edef\ZREF@xr@temprefname{Z@R@\ZREF@xr@tempname}%
  \let\ZREF@xr@list\x
  \ifx\ZREF@xr@list\ltx@empty
    \PackageWarningNoLine{zref-xr}{%
      Label `#1' without properties ignored\MessageBreak
      in file `\ZREF@xr@file'%
    }%
    \edef\ZREF@xr@ignored@empty{%
      \the\numexpr\ZREF@xr@ignored@empty+1\relax
    }%
  \else
    \expandafter\ZREF@xr@checklist\x\ZREF@nil
    \expandafter\let\csname\ZREF@xr@temprefname\endcsname\x
    \expandafter\ltx@LocalAppendToMacro
    \csname\ZREF@xr@temprefname\expandafter\endcsname
    \expandafter{%
      \expandafter\externaldocument\expandafter{%
        \ZREF@xr@externalfile
      }%
    }%
    \ZREF@xr@urlcheck\ZREF@xr@tempname
    \ifZREF@xr@tozreflabel
      \@ifundefined{\ZREF@xr@refname}{%
        \ifZREF@xr@verbose
          \PackageInfo{zref-xr}{%
            Import to zref label `\ZREF@xr@tempname#1'%
          }%
        \fi
        \global\expandafter
        \let\csname\ZREF@xr@refname\expandafter\endcsname
        \csname\ZREF@xr@temprefname\endcsname
      }{%
        \ZREF@xr@zref@ignorewarning{\ZREF@xr@prefix#1}%
      }%
    \fi
    \ifZREF@xr@toltxlabel
      \ZREF@xr@tolabel{\ZREF@xr@tempname}{\ZREF@xr@prefix#1}%
    \fi
  \fi
}%
\def\ZREF@xr@process@label\newlabel#1#2#3[#4]#5\ZREF@nil{%
  \def\ZREF@xr@refname{Z@R@\ZREF@xr@prefix#1}%
  \edef\ZREF@xr@found{\the\numexpr\ZREF@xr@found+1\relax}%
  \def\x{#2}%
  \edef\ZREF@xr@tempname{$temp$}%
  \edef\ZREF@xr@temprefname{Z@R@\ZREF@xr@tempname}%
  \expandafter\ZREF@xr@scanparams
      \csname\ZREF@xr@temprefname\expandafter\endcsname
      \x{}{}{}{}{}\ZREF@nil
  \ifx\\#4\\%
  \else
    % ntheorem knows an optional argument at the end of \newlabel
    \ZREF@NewPropTheotype
    \expandafter\ltx@LocalAppendToMacro
        \csname\ZREF@xr@temprefname\endcsname{\theotype{#4}}%
  \fi
  \expandafter\ltx@LocalAppendToMacro
  \csname\ZREF@xr@temprefname\expandafter\endcsname\expandafter{%
    \expandafter\externaldocument\expandafter{%
      \ZREF@xr@externalfile
    }%
  }%
  \ZREF@xr@urlcheck\ZREF@xr@tempname
  \ifZREF@xr@tozreflabel
    \@ifundefined{\ZREF@xr@refname}{%
      \ifZREF@xr@verbose
        \PackageInfo{zref-xr}{%
          Import to zref label `\ZREF@xr@prefix#1'%
        }%
      \fi
      \global\expandafter
      \let\csname\ZREF@xr@refname\expandafter\endcsname
      \csname\ZREF@xr@temprefname\endcsname
    }{%
      \ZREF@xr@zref@ignorewarning{\ZREF@xr@prefix#1}%
    }%
  \fi
  \ifZREF@xr@toltxlabel
    \ZREF@xr@tolabel{\ZREF@xr@tempname}{\ZREF@xr@prefix#1}%
  \fi
}
\def\ZREF@xr@zref@newlabel{\zref@newlabel}%
\def\ZREF@xr@newlabel{\newlabel}%
\def\ZREF@xr@@input{\@input}%
\def\ZREF@xr@relax{\relax}%
\def\ZREF@xr@tolabel#1#2{%
  \ifZREF@xr@verbose
    \PackageInfo{zref-xr}{%
      Import to LaTeX label `#2'%
    }%
  \fi
  \zref@wrapper@unexpanded{%
    \expandafter\xdef\csname r@#2\endcsname{%
      {%
        \ltx@ifundefined{M@TitleReference}{%
          \ltx@ifundefined{TR@TitleReference}{%
            \zref@extractdefault{#1}{default}{}%
          }{%
            \noexpand\TR@TitleReference
            {\zref@extractdefault{#1}{default}{}}%
            {\zref@extractdefault{#1}{title}{}}%
          }%
        }{%
          \noexpand\M@TitleReference
          {\zref@extractdefault{#1}{default}{}}%
          {\zref@extractdefault{#1}{title}{}}%
        }%
      }%
      {\zref@extractdefault{#1}{page}{}}%
      \ltx@ifpackageloaded{nameref}{%
        {\zref@extractdefault{#1}{title}{}}%
        {\zref@extractdefault{#1}{anchor}{}}%
        \zref@ifrefcontainsprop{#1}{urluse}{%
          {\zref@extractdefault{#1}{urluse}{}}%
        }{%
          {\zref@extractdefault{#1}{url}{}}%
        }%
      }{}%
    }%
  }%
}
\def\ZREF@xr@zref@ignorewarning#1{%
  \PackageWarningNoLine{zref-xr}{%
    Zref label `#1' is already in use\MessageBreak
    in file `\ZREF@xr@file'%
  }%
  \edef\ZREF@xr@ignored@zref{%
    \the\numexpr\ZREF@xr@ignored@zref+1%
  }%
}%
\def\ZREF@xr@ltx@ignorewarning#1{%
  \PackageWarningNoLine{zref-xr}{%
    LaTeX label `#1' is already in use\MessageBreak
    in file `\ZREF@xr@file'%
  }%
  \edef\ZREF@xr@ignored@ltx{%
    \the\numexpr\ZREF@xr@ignored@ltx+1%
  }%
}%
\def\ZREF@xr@checklist#1#2#3\ZREF@nil{%
  \ifx\@undefined#1\relax
    \expandafter\ZREF@xr@checkkey\string#1\@nil
  \fi
  \ifx\\#3\\%
  \else
    \ltx@ReturnAfterFi{%
      \ZREF@xr@checklist#3\ZREF@nil
    }%
  \fi
}%
\def\ZREF@xr@checkkey#1#2\@nil{%
  \zref@ifpropundefined{#2}{%
    \zref@newprop{#2}{}%
  }{}%
}%
\def\ZREF@xr@scanparams#1#2#3#4#5#6#7\ZREF@nil{%
  \let#1\ltx@empty
  \ZREF@foundfalse
  \ZREF@xr@scantitleref#1#2\TR@TitleReference{}{}\ZREF@nil
  \ifZREF@found
  \else
    \ltx@LocalAppendToMacro#1{\default{#2}}%
  \fi
  % page
  \ltx@LocalAppendToMacro#1{\page{#3}}%
  % nameref title
  \ifZREF@found
  \else
    \ifx\\#4\\%
    \else
      \def\ZREF@xr@temp{#4}%
      \ifx\ZREF@xr@temp\ZREF@xr@relax
      \else
        \ltx@LocalAppendToMacro#1{\title{#4}}%
      \fi
    \fi
  \fi
  % anchor
  \ifx\\#5\\%
  \else
    \ltx@LocalAppendToMacro#1{\anchor{#5}}%
  \fi
  \ifx\\#6\\%
  \else
    \ifZREF@xr@urluse
      \ZREF@xr@AddURL{#6}%
      \expandafter\ltx@LocalAppendToMacro\expandafter#1%
      \expandafter{%
        \expandafter\urluse\expandafter{%
          \csname Z@U@\ZREF@xr@theURL\endcsname
        }%
      }%
    \else
      \ltx@LocalAppendToMacro#1{\url{#6}}%
    \fi
  \fi
}%
\def\ZREF@xr@scantitleref#1#2\TR@TitleReference#3#4#5\ZREF@nil{%
  \ifx\\#5\\%
  \else
    \ltx@LocalAppendToMacro#1{%
      \default{#3}%
      \title{#4}%
    }%
    \ZREF@foundtrue
  \fi
}%
\def\ZREF@xr@urlcheck#1{%
  \zref@ifrefcontainsprop{#1}{anchor}{%
    \zref@ifrefcontainsprop{#1}{url}{%
    }{%
      \expandafter
      \ltx@LocalAppendToMacro\csname Z@R@#1\expandafter\endcsname
      \expandafter{%
        \csname url\ifZREF@xr@urluse use\fi
        \expandafter\endcsname\expandafter{\ZREF@xr@url}%
      }%
    }%
  }{%
  }%
}%
\endinput
%%
%% End of file `zref-xr.sty'.