summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/xbmks/xbmks.dtx
blob: b2ed3074c1bb5395bb35fba92a81d046fde6781e (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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
%\iffalse
% makeindex -s gglo.ist -o xbmks.gls xbmks.glo
% makeindex -s gind.ist -o xbmks.ind xbmks.idx
%<*copyright>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% xbmks.sty package,                                    %%
%% Copyright (C) 2016--2018                              %%
%%   dpstory@uakron.edu                                  %%
%%                                                       %%
%% This program can redistributed and/or modified under  %%
%% the terms of the LaTeX Project Public License         %%
%% Distributed from CTAN archives in directory           %%
%% macros/latex/base/lppl.txt; either version 1.2 of the %%
%% License, or (at your option) any later version.       %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%</copyright>
%<package>\NeedsTeXFormat{LaTeX2e}[1997/12/01]
%<package>\ProvidesPackage{xbmks}
%<package> [2018/07/04 v2.0.2 xbmks: Cross-document bookmarks (dps)]
%<*driver>
\documentclass{ltxdoc}
\usepackage{xcolor}
\usepackage[colorlinks,hyperindex=false,bookmarksopen]{hyperref}
\usepackage{fancyvrb,array,calc}
\usepackage{xbmks}
\xbmksetup{colors={int=red},styles={intbf}}
%\pdfstringdefDisableCommands{\let\\\textbackslash}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\bgroup\ttfamily
\gdef\brpr#1{\char123\relax#1\char125\relax}\egroup
\let\darg\brpr
\let\env\texttt
\let\opt\texttt
\let\pkg\textsf
\let\app\textsf
\def\visispace{\symbol{32}}
%\def\hardspace{{\fontfamily{cmtt}\selectfont\symbol{32}}}
\def\ameta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}}
\def\meta#1{\textsl{\texttt{#1}}}
\def\SUB#1{\ensuremath{{}_{\mbox{\scriptsize\ttfamily#1}}}}
\def\cs#1{\texttt{\bslash#1}}
\DeclareRobustCommand{\tmspace}[3]{%
  \ifmmode\mskip#1#2\else\kern#1#3\fi\relax}
\renewcommand{\,}{\tmspace+\thinmuskip{.1667em}}
\let\thinspace\,
\renewcommand{\!}{\tmspace-\thinmuskip{.1667em}}
\let\negthinspace\!
\renewcommand{\:}{\tmspace+\medmuskip{.2222em}}
\let\medspace\:
\newcommand{\negmedspace}{\tmspace-\medmuskip{.2222em}}
\renewcommand{\;}{\tmspace+\thickmuskip{.2777em}}
\let\thickspace\;
\newcommand{\negthickspace}{\tmspace-\thickmuskip{.2777em}}
\makeatletter
\renewcommand{\paragraph}
    {\@startsection{paragraph}{4}{0pt}{6pt}{-3pt}
    {\normalfont\normalsize\bfseries}}
\renewenvironment{quote}[1][]
   {\def\@rgi{#1}\ifx\@rgi\@empty
    \let\rghtm\@empty\else\def\rghtm{\rightmargin\leftmargin}\fi
    \list{}{\rghtm} %{\rightmargin\leftmargin}%
    \item\relax}
   {\endlist}
\makeatother
\InputIfFileExists{aebdocfmt.def}{\PackageInfo{xbmks}{Inputting aebdocfmt.def}}
    {\def\IndexOpt{\DescribeMacro}\def\IndexKey{\DescribeMacro}\let\setupFullwidth\relax
     \PackageInfo{xbmks}{aebdocfmt.def cannot be found}}
\begin{document}
\def\CMD#1{\textbackslash#1}
  \GetFileInfo{xbmks.sty}
  \title{\textsf{xbmks}: Cross-document bookmarks}
  \author{D. P. Story\\
    Email: \texttt{dpstory@acrotex.net}}
  \date{processed \today}
  \maketitle
  \tableofcontents
  \let\Email\texttt
  \DocInput{xbmks.dtx}
\IfFileExists{\jobname.ind}{\newpage\setupFullwidth\par\PrintIndex}{\paragraph*{Index} The index goes here.\\Execute
    \texttt{makeindex -s gind.ist -o xbmks.ind xbmks.idx}\\on the command line and recompile
    \texttt{xbmks.dtx}.}
\IfFileExists{\jobname.gls}{\PrintChanges}{\paragraph*{Change History} The list of changes goes here.\\Execute
    \texttt{makeindex -s gglo.ist -o xbmks.gls xbmks.glo}\\on the command line and recompile
    \texttt{xbmks.dtx}.}
\end{document}
%</driver>
% \fi
% \MakeShortVerb{|}
%
% \InputIfFileExists{aebdonotindex.def}{\PackageInfo{web}{Inputting aebdonotindex.def}}
%    {\PackageInfo{web}{cannot find aebdonotindex.def}}
%
%    \begin{macrocode}
% Begin package
%<*package>
\RequirePackage{xkeyval}
\RequirePackage{ifpdf}[2006/02/20]
\RequirePackage{ifxetex}[2006/08/21]
%    \end{macrocode}
%
%\section{Description}
% More than a couple decades ago (counting back from 2018), I wrote two mathematics tutorials: \textsl{\href{http://www.math.uakron.edu/~dpstory/e-calculus.html}{eCalculus}} and
% \textsl{\href{http://www.math.uakron.edu/~dpstory/mpt_home.html}{Algebra Review in Ten Lessons}}. The tutorials consisted of a number of lessons, each in a separate PDF.
% The bookmarks of each lessons contained the table of contents for the whole tutorial. A student, in theory, could then
% jump from one lesson to another by selecting an entry of interest from the bookmarks. In the intervening years I have not seen
% a {\LaTeX} package for merging the table of contents of a set of PDFs and merge them in this each member of the
% set. This package attempts to do just that.
%
% \section{Drivers and options}
% We support the drivers \app{dvips} (and \app{dvipsone}), \app{pdflatex}, \app{lualatex}, and \app{xelatex}; these
% options are then named \opt{dvipsone}, \opt{dvips}, \opt{pdftex}, \opt{luatex}, and \opt{xetex}.
% \changes{v1.1}{2018/06/13}{Fixed misspelling of drive command for pdfmark case}
%    \begin{macrocode}
\def\xbmk@driver{xbmks-pdfmark.def}
\DeclareOptionX{dvipsone}{\def\xbmk@driver{xbmks-pdfmark.def}}
\DeclareOptionX{dvips}{\def\xbmk@driver{xbmks-pdfmark.def}}
\DeclareOptionX{pdftex}{\def\xbmk@driver{xbmks-pdftex.def}}
\DeclareOptionX{luatex}{\def\xbmk@driver{xbmks-pdftex.def}}
\DeclareOptionX{xetex}{\def\xbmk@driver{xbmks-xetex.def}}
%    \end{macrocode}
%    \section{Process the options}
%    \begin{macrocode}
\ifpdf\ExecuteOptionsX{pdftex}\else
\ifxetex\ExecuteOptionsX{xetex}\else
  \let\ExecuteOptions@SAVE\ExecuteOptions
  \let\ExecuteOptions\ExecuteOptionsX
  \InputIfFileExists{web.cfg}{}
  {\@ifundefined{l@tex@@@@driver}{\ExecuteOptionsX{dvips}}
      {\ExecuteOptionsX{dvipsone}}}%
  \let\ExecuteOptions\ExecuteOptions@SAVE
\fi\fi
\ProcessOptionsX
%    \end{macrocode}
% \section{Requirements}
% The minimal requirement is \pkg{hyperref} and its built-in bookmark system. It is important to note that
% the \pkg{bookmark} package is not supported.
%    \begin{macrocode}
\RequirePackage{hyperref}
%    \end{macrocode}
%    \begin{macro}{\xbmksetup}
%    Set the cross-document options:
% \changes{v1.1}{2018/06/13}{Allow an empty value of docbundle, its value is set to \string\cs{jobname}}%
%\begin{quote}\ttfamily\obeylines
%\string\xbmksetup\darg{%
%\qquad docbundle=\darg{\ameta{doc\SUB1},\ameta{doc\SUB2},...,\ameta{doc\SUB{n}}},
%\qquad colors=\darg{int=\ameta{color},ext=\ameta{color}},
%\qquad styles=\darg{intbf,extbf,intit,extit}
%}
%\end{quote}
%This command must appear in one and only one of the document bundle, perhaps one
%of the documents you are calling the `main file'. It writes
%the key-values to the file \texttt{xbmks.cfg} which is then read back in by the other
%members of the document bundle, as specified by the \texttt{dobundle} key. The base names
%of the document bundle must match the name given to it by \cs{jobname}, exact spelling, case
%sensitive.
%
%\paragraph*{Key-values for \cs{xbmksetup}.} The keys belonging to the \texttt{xbmksetup} family:
%\IndexOpt{docbundle}\texttt{docbundle}, \IndexOpt{colors}\texttt{colors}, and \IndexOpt{styles}\texttt{styles}.
%    \begin{macrocode}
\define@key{xbmksetup}{docbundle}[]{\def\x@bmks@docs{#1}}
\let\x@bmks@docs\@empty
\define@key{xbmksetup}{colors}[]{\def\x@bmks@colors{#1}}
\let\x@bmks@colors\@empty
\define@key{xbmksetup}{styles}[]{\def\x@bmks@styles{#1}}
\let\x@bmks@styles\@empty
%    \end{macrocode}
%\subparagraph*{Values for the key \texttt{colors}.} The value recognized are
%\begin{quote}\ttfamily
%  colors=\darg{int=\ameta{color},ext=\ameta{color}}
%\end{quote}
%If the value of \texttt{int} or \texttt{ext} is empty, then the PDF viewer's default
%colors are using (black).
%    \begin{macrocode}
\define@key{xbmk@colors}{int}[]{%
  \HyColor@BookmarkColor{#1}{\xbmks@intC}{xbmks}{int}%
  \ifx\xbmks@intC\@empty\else
  \edef\xbmks@intC{/C[\xbmks@intC]}\fi
}
\let\xbmks@intC\@empty
\define@key{xbmk@colors}{ext}[]{%
  \HyColor@BookmarkColor{#1}{\xbmks@extC}{xbmks}{ext}%
  \ifx\xbmks@extC\@empty\else
  \edef\xbmks@extC{/C[\xbmks@extC]}\fi
}
\let\xbmks@extC\@empty
\let\xbmks@Yes=y \let\xbmks@No=n
%    \end{macrocode}
%\subparagraph*{Values for the key \texttt{colors}.} The value recognized are
%\begin{quote}\ttfamily
%  styles=\darg{intbf,intit,extbf,extit}
%\end{quote}
%These are valueless keys (Boolean keys, actually).  \texttt{intbf} means the interior document bookmarks
%are set in bold while \texttt{intbf,intit} creates bold and italic font.
%    \begin{macrocode}
\define@boolkey{xbmk@styles}{intbf}[true]{}
\define@boolkey{xbmk@styles}{extbf}[true]{}
\define@boolkey{xbmk@styles}{intit}[true]{}
\define@boolkey{xbmk@styles}{extit}[true]{}
%    \end{macrocode}
%    We evaluate the values of \cs{xbmksetup} by getting the values of
%    the \texttt{xbmksetup} family.
%    \begin{macrocode}
\newcommand{\xbmksetup}[1]{\setkeys{xbmksetup}{docbundle,#1}%
%    \end{macrocode}
%    \changes{v2.0.2}{2018/07/04}{Added an empty docbundle argument. This solves a problem
%    that the bookmarks not appearing after an even number of compiles.}
%    \begin{macrocode}
  \ifx\x@bmks@docs\@empty
%    \end{macrocode}
%     If there is no \texttt{docbundle} is specified, we use \cs{jobname} as its
%     value.
%    \begin{macrocode}
    \PackageInfo{xbmks}{The docbundle key of \string\xbmksetup\space
    is empty,\MessageBreak
    I will give it a value of `\jobname',\MessageBreak
    in hopes this is your intention}%
    \gdef\xbmk@cnt{1}%
    \def\xbmks@next{\write@xbmks@cfg{docbundle={\jobname},#1}}\else
    \def\xbmks@next{\write@xbmks@cfg{#1}}\fi\xbmks@next
}
%    \end{macrocode}
%    We write the key-values of \cs{xbmksetup} to the hard drive in the file
%    \texttt{xbmks.cfg}, this is \cs{xbmksetupi\darg{\ameta{KVPairs}}}. \cs{xbmksetupi}
%    is defined below, it is the command that actually does the heavy lifting in
%    processing the key-values.
%    \begin{macrocode}
\def\write@xbmks@cfg#1{%
  \newwrite\xbmks@setup \immediate\openout \xbmks@setup xbmks.cfg
  \set@display@protect
  \immediate\write\xbmks@setup{\protect\xbmksetupi{#1}}%
  \set@typeset@protect
  \immediate\closeout\xbmks@setup
}
%    \end{macrocode}
%    \cs{xbmksetupi} is an internal command that sets the key-values across all files in the \texttt{docbundle}.
%    \begin{macrocode}
\newcommand{\xbmksetupi}[1]{%
  \setkeys{xbmksetup}{#1}%
  \edef\x{\noexpand\x@docbundle{\x@bmks@docs}}\x
  \edef\x{\noexpand
    \setkeys{xbmk@colors}{\x@bmks@colors}}\x
  \edef\x{\noexpand
    \setkeys{xbmk@styles}{\x@bmks@styles}}\x
  \let\xbmk@intF\@empty
  \ifKV@xbmk@styles@intit
    \ifKV@xbmk@styles@intbf
      \def\xbmk@intF{/F 3}\else
      \def\xbmk@intF{/F 1}\fi
  \else
    \ifKV@xbmk@styles@intbf
      \def\xbmk@intF{/F 2}\fi
  \fi
  \let\xbmk@extF\@empty
  \ifKV@xbmk@styles@extit
    \ifKV@xbmk@styles@extbf
      \def\xbmk@extF{/F 3}\else
      \def\xbmk@extF{/F 1}\fi
  \else
    \ifKV@xbmk@styles@extbf
      \def\xbmk@extF{/F 2}\fi
  \fi
}
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}{\x@docbundle}
%    is a comma-delimited list of document base names:
%\begin{quote}\ttfamily\obeylines
%\string\x@docbundle\darg{\ameta{doc\SUB1},\ameta{doc\SUB2},...,\ameta{doc\SUB{n}}}
%\end{quote}
%This command is called internally by \cs{xbmksetupi}.
%    \begin{macrocode}
\def\xbmkcsarg#1#2{\expandafter#1\csname#2\endcsname}
\xdef\xbmk@cnt{0}
\newcommand{\x@docbundle}[1]{\bgroup
  \def\thisDoc{\jobname}\count\z@=0 %
  \edef\@tmpexp{\noexpand\@for\noexpand\@arg:=#1}%
  \@tmpexp\do{\advance\count\z@ by 1\relax
    \edef\x{\noexpand\xbmk@recordDoc{\@arg}}\x
    \edef\x{\noexpand\xbmk@docID{\@arg}}\x
  }%
  \xdef\xbmk@cnt{\the\count\z@}\egroup
}
\newcommand{\xbmk@recordDoc}[1]{%
  \xbmkcsarg\xdef{xbmk@doc\the\count\z@}{#1}}
%    \end{macrocode}
%    Because we are bringing in multiple outline files, there may be duplicate anchor names.
%    We assign each file in the document bundle a unique ID `\texttt{x1\ameta{anchor}}', `\texttt{x2\ameta{anchor}}', etc.
%    The IDs are ultimately assigned through \cs{pdfbookmarkx}.
%    \begin{macrocode}
\newcommand{\xbmk@docID}[1]{%
  \xbmkcsarg\xdef{x#1}{x\the\count\z@}}
\xbmkcsarg\xdef{x\jobname}{x0}
%    \end{macrocode}
%    \end{macro}
%
%    \section{Extending bookmarks to arbitrary actions}
%
%    It is possible to create bookmarks with arbitrary actions, just as the \pkg{bookmark}
%    package, does. Here we try to use \pkg{hyperref}'s native bookmark support. The
%    \pkg{hyperref} commands \cs{pdfbookmark}, \cs{currentbookmark}, \cs{subpdfbookmark}, and
%    \cs{belowpdfbookmark} are modified.
%    \begin{macro}{\pdfbookmarkx}\hskip-\marginparsep\,
%    \texttt{[\ameta{level}]\darg{\ameta{text}}[\ameta{xbmkskeys-kvp}]\darg{\ameta{name}}}\\
%    Defines a bookmark at \ameta{level}. If \ameta{level} is not provided, the level 1 is assumed.
%    We write to the outline file the action desired for this bookmark.
%    \cs{currentAction} is defined below. We do not set an anchor; if the
%    document author wants an anchor, he should use \cs{pdfbookmark}. As with
%    \cs{pdfbookmark}, the \cs{pdfbookmarkx} should not normally be directly
%    used.
%    \paragraph*{Key-values for the `\cs{...bookmarkx}' commands.} Recognized keys are
%    \IndexKey{action}\texttt{action}, \IndexKey{color}\texttt{color}, and \IndexKey{style}\texttt{style}.
%    Note that these keys are singular, as opposed to \texttt{colors} and \texttt{styles} defined in the
%    \texttt{xbmksetup} family. This is the \texttt{xbmkskeys} family.
%    \changes{v2.0}{2018/06/21}{Added `\string\cs{...bookmarkx} commands}
%    \changes{v2.0.1}{2018/06/25}{Added key-values for action, color, and style for custom `\string\cs{...bookmarkx} commands}
%    \begin{macrocode}
\define@key{xbmkskeys}{action}{\def\x@bmks@action{#1}}
\let\x@bmks@action\@empty
\define@key{xbmkskeys}{color}[]{%
  \HyColor@BookmarkColor{#1}{\x@bmks@C}{xbmks}{color}%
  \ifx\x@bmks@C\@empty\else
  \edef\x@bmks@C{/C[\x@bmks@C]}\fi
}
\let\x@bmks@C\@empty
\define@key{xbmkskeys}{style}[]{%
  \edef\x{\noexpand\setkeys{xbmks@style}{#1}}\x
  \let\x@bmks@F\@empty
  \ifKV@xbmks@style@it
    \ifKV@xbmks@style@bf
      \def\x@bmks@F{/F 3}\else
      \def\x@bmks@F{/F 1}\fi
  \else
    \ifKV@xbmks@style@bf
      \def\x@bmks@F{/F 2}\fi
  \fi
}
\let\x@bmks@F\@empty
%    \end{macrocode}
%    The \texttt{style} key takes zero, one, or two values, these are \texttt{bf} and \texttt{it}.
%    \begin{macrocode}
\define@boolkey{xbmks@style}{bf}[true]{}
\define@boolkey{xbmks@style}{it}[true]{}
\def\x@rollCFIntoActionBmrk#1{%
  \xbmkcsarg\ifx{X_#1}\relax
    \let\x@bmks@C\@empty\let\x@bmks@F\@empty\fi
  \ifx\xbmk@J\xbmk@filename
    \ifx\x@bmks@C\@empty\let\thisCol\xbmks@intC\else
      \let\thisCol\x@bmks@C\fi
    \ifx\x@bmks@F\@empty\let\thisF\xbmk@intF\else
      \let\thisF\x@bmks@F\fi
  \else
    \ifx\x@bmks@C\@empty\let\thisCol\xbmks@extC\else
      \let\thisCol\x@bmks@C\fi
    \ifx\x@bmks@F\@empty\let\thisF\xbmk@extF\else
      \let\thisF\x@bmks@F\fi
  \fi
  \global\let\x@bmks@C\@empty\global\let\x@bmks@F\@empty
}
%    \end{macrocode}
%    We finally arrive at \cs{pdfbookmarkx} command.
%    \begin{macrocode}
\newcommand\pdfbookmarkx[2][0]{%
  \@ifnextchar[%]
    {\pdfbookmarkx@i{#1}{#2}}
    {\pdfbookmarkx@i{#1}{#2}[]}}
\def\pdfbookmarkx@i#1#2[#3]#4{% level, title, action, name
  \def\x@rgiii{#3}\ifx\x@rgiii\@empty
%    \end{macrocode}
% if there is no action, treat as a destination
%    \begin{macrocode}
    \Hy@writebookmark{}{#2}{#4.#1}{#1}{toc}%
    \hyper@anchorstart{#4.#1}\hyper@anchorend
  \else
  \protected@write\@outlinefile{}{%
    \string\nextAction% assign doc ID
      {\@nameuse{x\jobname}#4.#1}{#3}}%
  \Hy@writebookmark{}{#2}{\@nameuse{x\jobname}#4.#1}{#1}{toc}%
  \fi
}
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}{\currentpdfbookmarkx}
%    \hskip-\marginparsep\,\texttt{\darg{\ameta{text}}[\ameta{xbmkskeys-kvp}]\darg{\ameta{name}}}\\
%    The \texttt{action=\ameta{action}} is raw PDF code, for example,
%\begin{quote}\ttfamily
%\string\currentpdfbookmarkx[/S/URI/URI(http://www.acrotex.net)]\\\null
%\qquad\darg{http://www.acrotex.net}\darg{home}
%\end{quote}
%   The command creates a bookmark at the current
%   bookmark level in the outline tree and associates the specified \ameta{action}. The argument
%   \ameta{text} appears in the bookmark panel. The \ameta{name} is used for identification purposes.
%    \begin{macrocode}
\newcommand{\currentpdfbookmarkx}[1]{%
  \@ifnextchar[%]
    {\currentpdfbookmarkx@i{#1}}
    {\currentpdfbookmarkx@i{#1}[]}}
\def\currentpdfbookmarkx@i#1[#2]#3{%
  \pdfbookmarkx[\Hy@currentbookmarklevel]{#1}[{#2}]{#3}}
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}{\subpdfbookmarkx}
%    \hskip-\marginparsep\,\texttt{\darg{\ameta{text}}[\ameta{\ameta{xbmkskeys-kvp}}]\darg{\ameta{name}}}\\
%    Reduces the current bookmark level by one, then creates
%    the bookmark at that level. The reduced level is the new current
%    bookmark level.
%    \begin{macrocode}
\newcommand{\subpdfbookmarkx}[1]{%
  \@ifnextchar[%]
    {\subpdfbookmarkx@i{#1}}
    {\subpdfbookmarkx@i{#1}[]}}
\def\subpdfbookmarkx@i#1[#2]#3{%
  \@tempcnta\Hy@currentbookmarklevel
  \Hy@StepCount\@tempcnta
  \expandafter
  \pdfbookmarkx\expandafter[\the\@tempcnta]{#1}[{#2}]{#3}}
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}{\belowpdfbookmarkx}
%    \hskip-\marginparsep\,\texttt{\darg{\ameta{text}}[\ameta{xbmkskeys-kvp}]\darg{\ameta{name}}}\\
%    Creates a bookmark at one level below the current
%    bookmark level without changing the value of the current bookmark
%    level.
%    \begin{macrocode}
\newcommand{\belowpdfbookmarkx}[1]{%
  \@ifnextchar[%]
    {\belowpdfbookmarkx@i{#1}}
    {\belowpdfbookmarkx@i{#1}[]}}
\def\belowpdfbookmarkx@i#1[#2]#3{%
  \@tempcnta\Hy@currentbookmarklevel
  \Hy@StepCount\@tempcnta
  \expandafter
  \pdfbookmarkx\expandafter[\the\@tempcnta]{#1}[{#2}]{#3}%
  \advance\@tempcnta by -1 %
  \xdef\Hy@currentbookmarklevel{\the\@tempcnta}}
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}{\nextAction@i}
%     \hskip-\marginparsep\,\texttt{\darg{\ameta{anchor.level}}\darg{\ameta{xbmkskeys-kvp}}}\\
%     This command is used internally, the document author need not do anything.
%     The command \cs{nextAction} is \cs{let} to \cs{nextAction@i} just prior to when
%     the outline file is input; and is \cs{let} to \cs{@gobbletwo}, otherwise.
%    \begin{macrocode}
\def\nextAction@i#1#2{\@ifundefined{X_#1}{%
    \setkeys{xbmkskeys}{#2}%
    \xbmkcsarg\xdef{X_#1}{\x@bmks@action}%
    }{\global\xbmkcsarg\let{X_#1}\relax
    \PackageWarning{xbmks}
    {The anchor name `#1' is already defined,\MessageBreak
    change this name, the bookmark will be created\MessageBreak
    but it will have no associated action}}}
%    \end{macrocode}
%    \end{macro}
%    \begin{macrocode}
\def\x@outWarningMsg{\PackageWarningNoLine{xbmks}{%
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\MessageBreak
@@ Outline files were not input, compile again @@\MessageBreak
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}}%
%    \end{macrocode}
%    These commands are implemented in the driver dependent sections.
%    \begin{macrocode}
% End package
%</package>
%<*pdfmark>
%    \end{macrocode}
%    \section{Driver dependent code}
%    \subsection{The pdfmark driver}
%    We redefine/modify the \cs{ReadBookmarks} command of \pkg{hyperref},
%    this definition is driver dependent.
%    \begin{macrocode}
\def\ReadBookmarks{%
  \pdf@ifdraftmode{}{%
    \begingroup\def\\{\@backslashchar\@backslashchar}% dps
      \def\calc@bm@number##1{%
      \@tempcnta=\check@bm@number{##1}\relax
      \advance\@tempcnta by 1 %
      \expandafter\edef\csname B_##1\endcsname{\the\@tempcnta}%
      }%
      \def\do##1{%
        \ifnum\catcode`##1=\active
          \@makeother##1%
        \else
          \ifnum\catcode`##1=6 %
            \@makeother##1%
          \fi
        \fi
      }%
      \dospecials
      \Hy@safe@activestrue
      \escapechar=`\\%
      \ifx\WriteBookmarks\relax
        \global\let\WriteBookmarks\relax
      \fi
      \begingroup
        \def\WriteBookmarks{0}%
        \count\z@=0\relax
        \edef\xbmk@J{\jobname}%
        \@whilenum \count\z@<\xbmk@cnt\relax\do{%
          \advance\count\z@ by 1 %
          \edef\xbmk@thisdoc{xbmk@doc\the\count\z@}%
          \edef\xbmk@filename{\@nameuse{\xbmk@thisdoc}}%
          \@onelevel@sanitize\xbmk@filename
          \bgroup
          \def\@@BOOKMARK[##1][##2]##3##4##5{%
            \calc@bm@number{##5}%
          }%
          \let\nextAction\@gobbletwo
          \InputIfFileExists{\xbmk@filename.out}{}{\x@outWarningMsg}%
          \def\@@BOOKMARK[##1][##2]##3##4##5{%
            \def\Hy@temp{##4}%
%    \end{macrocode}
%    If `\texttt{X\_\#\#3}' is undefined (\cs{relax}), it is a  normal bookmark.
%    \begin{macrocode}
            \xbmkcsarg\ifx{X_##3}\relax
              \ifx\xbmk@J\xbmk@filename
                \pdfmark{%
                  pdfmark=/OUT,%
                  Count={##2\check@bm@number{##3}},%
                  Raw={\xbmks@intC\xbmk@intF},%
                  Dest={##3},%
                  Title=\expandafter\strip@prefix\meaning\Hy@temp
                }%
              \else
                \pdfmark{%
                  pdfmark=/OUT,%
                  Count={##2\check@bm@number{##3}},%
                  Raw={\xbmks@extC\xbmk@extF},%
                  Action=/GoToR,%
                  File={\xbmk@filename.pdf},%
                  Dest={##3},%
                  Title=\expandafter\strip@prefix\meaning\Hy@temp
                }%
              \fi
            \else
%    \end{macrocode}
%    The anchor has an `\texttt{X\_}' definition, it is a bookmark created
%    from one of the `\texttt{bookmarkx}' commands. We treat this as a separate case.
%    \begin{macrocode}
              \x@rollCFIntoActionBmrk{##3}%
              \pdfmark{%
                pdfmark=/OUT,%
                Count={##2\check@bm@number{##3}},%
                Raw={/Action<<\@nameuse{X_##3}>>\thisCol\thisF},%
                Title=\expandafter\strip@prefix\meaning\Hy@temp
              }%
            \fi
          }% bookmark
          \let\nextAction\nextAction@i
          \InputIfFileExists{\xbmk@filename.out}{}{}%
          \egroup
        }% \@whilenum
      \endgroup
    \endgroup
  }%
  \ifx\WriteBookmarks\relax\else
    \if@filesw
      \newwrite\@outlinefile
      \Hy@OutlineRerunCheck
     \immediate\openout\@outlinefile=\jobname.out\relax
      \ifHy@typexml
        \immediate\write\@outlinefile{<relaxxml>\relax}%
      \fi
    \fi
  \fi
}
%</pdfmark>
%    \end{macrocode}
%    \subsection{Code for pdftex/luatex driver}
%    We redefine/modify the \cs{ReadBookmarks} command of \pkg{hyperref},
%    this definition is driver dependent.
%    \begin{macrocode}
%<*pdftex>
\def\ReadBookmarks{%
  \pdf@ifdraftmode{}{%
    \begingroup\def\\{\@backslashchar\@backslashchar}% dps
    \def\calc@bm@number##1{%
      \@tempcnta=\check@bm@number{##1}\relax
      \advance\@tempcnta by 1 %
      \expandafter\edef\csname B_##1\endcsname{\the\@tempcnta}%
    }%
    \def\Hy@OutlineName##1##2##3##4{\def\@rgi{##1}%
      \expandafter\pdfoutline\ifx\@rgi\@empty\else
      attr {##1} \fi
      user {##2} count##3{##4}%
    %  goto name{#2} count#3{#4}%
    }%
    \def\do##1{%
      \ifnum\catcode`##1=\active
        \@makeother##1%
      \else
        \ifnum\catcode`##1=6 %
          \@makeother##1%
        \fi
      \fi
    }%
    \dospecials
    \Hy@safe@activestrue
    \escapechar=`\\%
    \ifx\WriteBookmarks\relax
      \global\let\WriteBookmarks\relax
    \fi
    \begingroup
    \def\WriteBookmarks{0}%
    \count\z@=0\relax
    \edef\xbmk@J{\jobname}%
    \@whilenum \count\z@<\xbmk@cnt\relax\do{%
      \advance\count\z@ by 1 %
      \edef\xbmk@thisdoc{xbmk@doc\the\count\z@}%
      \edef\xbmk@filename{\@nameuse{\xbmk@thisdoc}}%
      \@onelevel@sanitize\xbmk@filename
      \bgroup
      \gdef\@@BOOKMARK[##1][##2]##3##4##5{%
        \calc@bm@number{##5}%
      }%
      \let\nextAction\@gobbletwo
      \InputIfFileExists{\xbmk@filename.out}{}{\x@outWarningMsg}%
      \gdef\@@BOOKMARK[##1][##2]##3##4##5{%
        \def\Hy@temp{##4}%
        \Hy@pstringdef\Hy@pstringName{\HyperDestNameFilter{##3}}%
        \xbmkcsarg\ifx{X_##3}\relax
%    \end{macrocode}
%     Ordinary bookmark
%    \begin{macrocode}
          \ifx\xbmk@J\xbmk@filename
            \Hy@OutlineName{\xbmks@intC\xbmk@intF}{<</S/GoTo%
              /D(\Hy@pstringName)>>}{%
              ##2\check@bm@number{\Hy@pstringName}%
            }{%
              \expandafter\strip@prefix\meaning\Hy@temp
            }%
          \else
            \Hy@OutlineName{\xbmks@extC\xbmk@extF}{<</S/GoToR%
              /F(\xbmk@filename.pdf)/D(\Hy@pstringName)>>}{%
              ##2\check@bm@number{##3}%
            }{%
              \expandafter\strip@prefix\meaning\Hy@temp
            }%
          \fi
        \else
%    \end{macrocode}
%     Bookmark created by one of the `\texttt{...bookmarkx} commands
%    \begin{macrocode}
          \x@rollCFIntoActionBmrk{##3}%
          \Hy@OutlineName{\thisCol\thisF}
          {<<\@nameuse{X_##3}>>}{%
              ##2\check@bm@number{\Hy@pstringName}%
          }{%
            \expandafter\strip@prefix\meaning\Hy@temp
          }%
        \fi
      }% bookmark
      \let\nextAction\nextAction@i
      \InputIfFileExists{\xbmk@filename.out}{}{}%
      \egroup
    } % \@whilenum
    \endgroup
  }%
  \ifx\WriteBookmarks\relax
  \else
    \if@filesw
      \newwrite\@outlinefile
      \Hy@OutlineRerunCheck
      \immediate\openout\@outlinefile=\jobname.out\relax
      \ifHy@typexml
        \immediate\write\@outlinefile{<relaxxml>\relax}%
      \fi
    \fi
  \fi
}
%</pdftex>
%<*xetex>
%    \end{macrocode}
%    \subsection{Code for xetex driver}
%    We redefine/modify the \cs{ReadBookmarks} command of \pkg{hyperref},
%    this definition is driver dependent.
%    \begin{macrocode}
\def\ReadBookmarks{%
  \pdf@ifdraftmode{}{%
    \begingroup\def\\{\@backslashchar\@backslashchar}% dps
      \def\calc@bm@number##1{%
        \@tempcnta=\check@bm@number{##1}\relax
        \advance\@tempcnta by 1 %
        \expandafter\edef\csname B_##1\endcsname{\the\@tempcnta}%
      }%
      \def\do##1{%
        \ifnum\catcode`##1=\active
          \@makeother##1%
        \else
          \ifnum\catcode`##1=6 %
            \@makeother##1%
          \fi
        \fi
      }%
      \dospecials
      \Hy@safe@activestrue
      \escapechar=`\\%
      \ifx\WriteBookmarks\relax
        \global\let\WriteBookmarks\relax
      \fi
      \begingroup
        \def\WriteBookmarks{0}%
        \count\z@=0\relax
        \edef\xbmk@J{\jobname}%
        \@whilenum \count\z@<\xbmk@cnt\relax\do{%
          \advance\count\z@ by 1 %
          \edef\xbmk@thisdoc{xbmk@doc\the\count\z@}%
          \edef\xbmk@filename{\@nameuse{\xbmk@thisdoc}}%
          \@onelevel@sanitize\xbmk@filename
          \bgroup
          \def\@@BOOKMARK[##1][##2]##3##4##5{%
            \calc@bm@number{##5}%
          }%
          \let\nextAction\@gobbletwo
          \InputIfFileExists{\xbmk@filename.out}{}{\x@outWarningMsg}%
          \def\@@BOOKMARK[##1][##2]##3##4##5{%
            \def\Hy@temp{##4}%
            \Hy@pstringdef\Hy@pstringName{\HyperDestNameFilter{##3}}%
            \x@rollCFIntoActionBmrk{##3}%
            \@pdfm@mark{%
              outline \ifHy@DvipdfmxOutlineOpen
                [\ifnum##21>\z@\else-\fi] \fi
              ##1<<%
              /Title(\expandafter\strip@prefix\meaning\Hy@temp)%
              \xbmkcsarg\ifx{X_##3}\relax
%    \end{macrocode}
%     Ordinary bookmark
%    \begin{macrocode}
                \ifx\xbmk@J\xbmk@filename
                  /A<<%
                    /S/GoTo%
                    /D(\Hy@pstringName)%
                  >>%
                \else
                  /A<<%
                    /S/GoToR/F(\xbmk@filename.pdf)%
                    /D(\Hy@pstringName)%
                  >>%
                \fi
              \else
%    \end{macrocode}
%     Bookmark created by one of the \texttt{\string\...bookmarkx} commands
%    \begin{macrocode}
                /A<<\@nameuse{X_##3}>>
              \fi
              \thisCol\thisF
              >>%
            }% \@pdfm@mark
            \let\thisC\@empty\let\thisF\@empty
          }% bookmark
          \let\nextAction\nextAction@i
          \InputIfFileExists{\xbmk@filename.out}{}{}%
          \egroup
        }% \@whilenum
      \endgroup
    \endgroup
  }%
  \ifx\WriteBookmarks\relax
  \else
    \if@filesw
      \newwrite\@outlinefile
      \Hy@OutlineRerunCheck
     \immediate\openout\@outlinefile=\jobname.out\relax
      \ifHy@typexml
        \immediate\write\@outlinefile{<relaxxml>\relax}%
      \fi
    \fi
  \fi
}
%</xetex>
%<*package>
\InputIfFileExists{xbmks.cfg}{}{}
\@ifpackageloaded{bookmark}{\PackageWarningNoLine{xbmks}{The
  bookmark package is not supported;\MessageBreak
  this package does nothing, as a result}}
{\InputIfFileExists{\xbmk@driver}{}{}}
%</package>
%    \end{macrocode}
%    \Finale