summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/oberdiek/bookmark.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/oberdiek/bookmark.dtx')
-rw-r--r--Master/texmf-dist/source/latex/oberdiek/bookmark.dtx1606
1 files changed, 1606 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/latex/oberdiek/bookmark.dtx b/Master/texmf-dist/source/latex/oberdiek/bookmark.dtx
new file mode 100644
index 00000000000..4b754fb8c24
--- /dev/null
+++ b/Master/texmf-dist/source/latex/oberdiek/bookmark.dtx
@@ -0,0 +1,1606 @@
+% \iffalse meta-comment
+%
+% Copyright (C) 2007 by Heiko Oberdiek <oberdiek@uni-freiburg.de>
+%
+% 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
+% 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 bookmark.dtx
+% and the derived files
+% bookmark.sty, bookmark.pdf, bookmark.ins, bookmark.drv,
+% bkm-dvipdfm.def, bkm-dvips.def, bkm-pdftex.def,
+% bookmark-example.tex.
+%
+% Distribution:
+% CTAN:macros/latex/contrib/oberdiek/bookmark.dtx
+% CTAN:macros/latex/contrib/oberdiek/bookmark.pdf
+%
+% Unpacking:
+% (a) If bookmark.ins is present:
+% tex bookmark.ins
+% (b) Without bookmark.ins:
+% tex bookmark.dtx
+% (c) If you insist on using LaTeX
+% latex \let\install=y\input{bookmark.dtx}
+% (quote the arguments according to the demands of your shell)
+%
+% Documentation:
+% (a) If bookmark.drv is present:
+% latex bookmark.drv
+% (b) Without bookmark.drv:
+% latex bookmark.dtx; ...
+% The class ltxdoc loads the configuration file ltxdoc.cfg
+% if available. Here you can specify further options, e.g.
+% use A4 as paper format:
+% \PassOptionsToClass{a4paper}{article}
+%
+% Programm calls to get the documentation (example):
+% pdflatex bookmark.dtx
+% makeindex -s gind.ist bookmark.idx
+% pdflatex bookmark.dtx
+% makeindex -s gind.ist bookmark.idx
+% pdflatex bookmark.dtx
+%
+% Installation:
+% TDS:tex/latex/oberdiek/bookmark.sty
+% TDS:tex/latex/oberdiek/bkm-dvipdfm.def
+% TDS:tex/latex/oberdiek/bkm-dvips.def
+% TDS:tex/latex/oberdiek/bkm-pdftex.def
+% TDS:doc/latex/oberdiek/bookmark.pdf
+% TDS:doc/latex/oberdiek/bookmark-example.tex
+% TDS:source/latex/oberdiek/bookmark.dtx
+%
+%<*ignore>
+\begingroup
+ \def\x{LaTeX2e}
+\expandafter\endgroup
+\ifcase 0\ifx\install y1\fi\expandafter
+ \ifx\csname processbatchFile\endcsname\relax\else1\fi
+ \ifx\fmtname\x\else 1\fi\relax
+\else\csname fi\endcsname
+%</ignore>
+%<*install>
+\input docstrip.tex
+\Msg{************************************************************************}
+\Msg{* Installation}
+\Msg{* Package: bookmark 2007/02/20 v0.2 PDF bookmarks (HO)}
+\Msg{************************************************************************}
+
+\keepsilent
+\askforoverwritefalse
+
+\preamble
+
+This is a generated file.
+
+Copyright (C) 2007 by Heiko Oberdiek <oberdiek@uni-freiburg.de>
+
+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
+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 bookmark.dtx
+and the derived files
+ bookmark.sty, bookmark.pdf, bookmark.ins, bookmark.drv,
+ bkm-dvipdfm.def, bkm-dvips.def, bkm-pdftex.def,
+ bookmark-example.tex.
+
+\endpreamble
+
+\generate{%
+ \file{bookmark.ins}{\from{bookmark.dtx}{install}}%
+ \file{bookmark.drv}{\from{bookmark.dtx}{driver}}%
+ \usedir{tex/latex/oberdiek}%
+ \file{bookmark.sty}{\from{bookmark.dtx}{package}}%
+ \file{bkm-dvipdfm.def}{\from{bookmark.dtx}{dvipdfm}}%
+ \file{bkm-dvips.def}{\from{bookmark.dtx}{dvips}}%
+ \file{bkm-pdftex.def}{\from{bookmark.dtx}{pdftex}}%
+ \usedir{doc/latex/oberdiek}%
+ \file{bookmark-example.tex}{\from{bookmark.dtx}{example}}%
+}
+
+\obeyspaces
+\Msg{************************************************************************}
+\Msg{*}
+\Msg{* To finish the installation you have to move the following}
+\Msg{* files into a directory searched by TeX:}
+\Msg{*}
+\Msg{* bookmark.sty, bkm-dvipdfm.def, bkm-dvips.def,}
+\Msg{* bkm-pdftex.def}
+\Msg{*}
+\Msg{* To produce the documentation run the file `bookmark.drv'}
+\Msg{* through LaTeX.}
+\Msg{*}
+\Msg{* Happy TeXing!}
+\Msg{*}
+\Msg{************************************************************************}
+
+\endbatchfile
+%</install>
+%<*ignore>
+\fi
+%</ignore>
+%<*driver>
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesFile{bookmark.drv}%
+ [2007/02/20 v0.2 PDF bookmarks (HO)]
+\documentclass{ltxdoc}
+\usepackage{holtxdoc}
+\begin{document}
+ \DocInput{bookmark.dtx}
+\end{document}
+%</driver>
+% \fi
+%
+% \CheckSum{1336}
+%
+% \CharacterTable
+% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
+% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
+% Digits \0\1\2\3\4\5\6\7\8\9
+% Exclamation \! Double quote \" Hash (number) \#
+% Dollar \$ Percent \% Ampersand \&
+% Acute accent \' Left paren \( Right paren \)
+% Asterisk \* Plus \+ Comma \,
+% Minus \- Point \. Solidus \/
+% Colon \: Semicolon \; Less than \<
+% Equals \= Greater than \> Question mark \?
+% Commercial at \@ Left bracket \[ Backslash \\
+% Right bracket \] Circumflex \^ Underscore \_
+% Grave accent \` Left brace \{ Vertical bar \|
+% Right brace \} Tilde \~}
+%
+% \GetFileInfo{bookmark.drv}
+%
+% \title{The \xpackage{bookmark} package}
+% \date{2007/02/20 v0.2}
+% \author{Heiko Oberdiek\\\xemail{oberdiek@uni-freiburg.de}}
+%
+% \maketitle
+%
+% \begin{abstract}
+% This package implements a new bookmark (outline) organization for
+% package \xpackage{hyperref}. Bookmark properties such
+% as style and color can now be set. Other action types
+% are available (URI, GoToR, Named). The bookmarks are
+% generated in the first compile run. Package \xpackage{hyperref}
+% uses two runs.
+% \end{abstract}
+%
+% \tableofcontents
+%
+% \section{Documentation}
+%
+% \subsection{Introduction}
+%
+% This package \xpackage{bookmark} tries to provide a more modern
+% management for bookmarks:
+% \begin{itemize}
+% \item The bookmarks are already generated in the first \TeX\ compile run.
+% \item The font style and color of the bookmarks can be changed.
+% \item More actions than simple GoTo actions are possible.
+% \end{itemize}
+%
+% In the same way as \xpackage{hyperref} the bookmarks are generated
+% in the order of the bookmark generating macros (\cs{bookmark}).
+% A level number is used to define the tree structure of the bookmarks.
+% The restrictions are less strict:
+% \begin{itemize}
+% \item The level values may jump and omit values. A \cs{subsubsection}
+% may follow a \cs{chapter}. This was an error in \xpackage{hyperref},
+% that prints a warning and tries to fix this.
+% \item Several bookmarks may point to the same destination.
+% In \xpackage{hyperref} this would mess up the bookmark tree
+% completely, because the algorithm assumes that the destination
+% names are keys (unique).
+% \end{itemize}
+%
+% \subsection{Options}
+%
+% Options can be given at three places:
+% \begin{enumerate}
+% \item \cs{usepackage}|[|\meta{options}|]{bookmark}|\\
+% This is the only place for driver options.
+% \item \cs{bookmarksetup}|{|\meta{options}|}|\\
+% This command is just for setting options.
+% \item \cs{pdfbookmark}|[|\meta{options}|]{|\meta{title}|}|\\
+% This command sets the bookmark. The option settings remain
+% limited to this bookmark.
+% \end{enumerate}
+%
+% \subsubsection{Driver options}
+%
+% Supported drivers are \xoption{pdftex}, \xoption{dvips},
+% and \xoption{dvipdfm} (\xoption{xetex}).
+% The \TeX\ engines pdf\TeX\ and Xe\TeX\ are automatically detected.
+% The default for the DVI drivers is \xoption{dvips}. This can
+% be changed in the configuration file \xfile{bookmark.cfg} by
+% \cs{BookmarkDefaultDriver}, e.g.:
+% \begin{quote}
+% |\def\BookmarkDefaultDriver{dvipdfm}|
+% \end{quote}
+%
+% \subsubsection{Style options}
+%
+% \paragraph{Font options.}
+%
+% \begin{description}
+% \item[\xoption{bold}:] The bookmark is shown with a bold font
+% if the PDF viewer supports this (since PDF 1.4).
+% \item[\xoption{italic}:] An italic font is used (since PDF 1.4).
+% \end{description}
+% Both \xoption{bold} and \xoption{italic} can be used together.
+% Using value |false| disables the font option.
+%
+% \paragraph{Color options.}
+%
+% Colored bookmarks are a feature of PDF 1.4, they are not supported
+% by all PDF viewers.
+% \begin{description}
+% \item[\xoption{rgbcolor}:] This option expects an RGB tripel,
+% three space separated values in the range 0 until 1.
+% Example for blue: |rgbcolor=0 0 1|
+% \item[\xoption{color}:] Here the color can be given as
+% color specification of packages \xpackage{color}/\xpackage{xcolor}.
+% Package \xpackage{xcolor} must be loaded first, before this option
+% can be used.
+% \end{description}
+% Both options are exclusive. Used together the second option overwrites
+% the previous color option settings. The use of color is disabled by
+% using the empty value, e.g.: |color={}|
+%
+% \subsubsection{Action options}
+%
+% \begin{description}
+% \item[\xoption{dest}:] Destination name.
+% \item[\xoption{page}:] Page number, first page is 1.
+% \item[\xoption{view}:] View specification, examples:\\
+% |view={FitB}|, |view={FitH 842}|, |view={XYZ 0 100 null}|
+% Some view specifications expect numbers as parameters
+% (unit bp). They can be given either as plain numbers or
+% as length expressions inside \cs{calc}. Expressions of
+% package \xpackage{calc} are supported if the package is loaded.
+% Otherwise \eTeX's \cs{dimexpr} is used. Example:\\
+% |view={FitH \calc{\paperheight-\topmargin-1in}}|\\
+% |view={XYZ 0 \calc{\paperheight} null}|
+% \item[\xoption{named}:] Named action name:\\
+% |FirstPage|, |LastPage|, |NextPage|, |PrevPage|
+% \item[\xoption{gotor}:] Name of the external PDF file.
+% \item[\xoption{uri}:] URI specification.
+% \item[\xoption{rawaction}:] Raw action specification.
+% Because these specification depends on the driver this option
+% should not be used.
+% \end{description}
+% The appropriate action for the bookmark is selected by
+% analyzing the specified options. The actions
+% are distinguished by different sets of options:
+% \begin{quote}
+% \begin{tabular}{@{}ll@{}}
+% \textbf{Action} & \textbf{Options}\\
+% \hline
+% \textsf{GoTo}: & \xoption{dest}\\
+% \textsf{GoTo}: & \xoption{page} + \xoption{view}\\
+% \textsf{GoToR}: & \xoption{gotor} + \xoption{dest}\\
+% \textsf{GoToR}: & \xoption{gotor} + \xoption{page} + \xoption{view}\\
+% \textsf{Named}: & \xoption{named}\\
+% \textsf{URI}: & \xoption{uri}
+% \end{tabular}
+% \end{quote}
+%
+% \subsection{Level options}
+%
+% The order of the bookmark entries are defined by the
+% appearance order of \cs{bookmark} commands. The tree structure
+% is constructed by the property \xoption{level} of the bookmark nodes.
+% The values of \xoption{level} are integers. If the level of a
+% bookmark entry has a higher value than the previous node, then
+% the entry becomes a child of the previous node. The absolute
+% value of the difference does not matter.
+%
+% Package \xpackage{bookmark} remembers the level of the previous
+% bookmark entry in a global property `current level'.
+%
+% The behaviour of the level system can be configured by following
+% options:
+% \begin{description}
+% \item[\xoption{level}:]
+% Sets the level, see the description above. If option \xoption{level}
+% is given without value, then the default behaviour is restored,
+% that the `current level' is used as level value.
+% \item[\xoption{rellevel}:]
+% Sets the level relative to the previous level.
+% A positive value means that the bookmark entry become
+% a child of the previous one.
+% \item[\xoption{keeplevel}:]
+% Use the level, set by \xoption{level} or \xoption{rellevel},
+% but do not change the global property `current level'.
+% The option can be disabled by setting to |false|.
+% \item[\xoption{startatroot}:]
+% At this time the bookmark tree starts at the top level again.
+% The next bookmark entry is not sorted as child to a previous entry.
+% Example szenario: A document uses part. However there are
+% last chapters that should not be put below the last part:
+% \begin{quote}
+%\begin{verbatim}
+%\documentclass{book}
+%[...]
+%\begin{document}
+% \part{First part}
+% \chapter{First chapter in first part}
+% [...]
+% \part{Second part}
+% \chapter{First chapter in second part}
+% [...]
+% \bookmarksetup{startatroot}
+% \chapter{Index}% does not belong to second part
+%\end{document}
+%\end{verbatim}
+% \end{quote}
+% \end{description}
+%
+% \subsection{Compatibility with \xpackage{hyperref}}
+%
+% Package \xpackage{bookmark} automatically disables
+% \xpackage{hyperref}'s bookmarks. However the package
+% uses some of the code of \xpackage{hyperref}. For example,
+% the package redefines the hook \cs{Hy@writebookmark} that
+% \xpackage{hyperref} inserts in \cs{addcontentsline} and
+% other commands. Therefore
+% \xpackage{hyperref}'s bookmarks should not be disabled.
+%
+% Package \xpackage{bookmark} uses \xpackage{hyperref}'s \cs{pdfstringdef}
+% and does not provide a replacement.
+%
+% Some options of \xpackage{hyperref} are also implemented
+% in package \xpackage{bookmark}:
+% \begin{quote}
+% \begin{tabular}{@{}ll@{}}
+% \xpackage{hyperref} & \xpackage{bookmark}\\
+% \hline
+% \xoption{bookmarksdepth} & \xoption{depth}\\
+% \xoption{bookmarksopen} & \xoption{open}\\
+% \xoption{bookmarksopenlevel} & \xoption{openlevel}\\
+% \end{tabular}
+% \end{quote}
+%
+% The following commands are also available:
+% \begin{quote}
+% \cs{pdfbookmark}\\
+% \cs{currentpdfbookmark}\\
+% \cs{subpdfbookmark}\\
+% \cs{belowpdfbookmark}
+% \end{quote}
+%
+% \subsection{Limitations/ToDos}
+%
+% \begin{itemize}
+% \item Support for missing drivers (V\TeX, \dots).
+% \item Support for missing actions (Launch, \dots).
+% \item Replacements for \cs{pdfescapehex}, \cs{pdfescapestring},
+% \dots\ for other \TeX\ engines than pdf\TeX.
+% \item \xpackage{hyperref}'s \xoption{bookmarkstype}.
+% \item Adding bookmarks at the end of the document
+% is difficult for \xoption{dvipdfm}, because the \cs{special}
+% must go into a page. The problem can be solved by two runs
+% using \xpackage{zref-abspage} for detecting the last page and
+% package \xpackage{everyshi} for adding the \cs{special}s at the
+% end of the last page.
+% \end{itemize}
+%
+% \section{Example}
+%
+% \begin{macrocode}
+%<*example>
+% \end{macrocode}
+% \begin{macrocode}
+\documentclass{article}
+\usepackage{xcolor}[2007/01/21]
+\usepackage{hyperref}
+\usepackage[
+ open,
+ openlevel=2
+]{bookmark}
+
+\bookmarksetup{color=blue}
+
+\begin{document}
+\section{First section}
+\subsection{Subsection A}
+\begin{figure}
+ \hypertarget{fig}{}%
+ \bookmark[
+ rellevel=1,
+ keeplevel,
+ dest=fig
+ ]{A figure}
+ A figure.
+\end{figure}
+\subsection{Subsection B}
+\subsubsection{Subsubsection C}
+\newpage
+\bookmarksetup{
+ bold,
+ rgbcolor=1 0 0
+}
+\section{Very important section}
+\bookmarksetup{
+ italic,
+ bold=false,
+ color=blue
+}
+\subsection{Italic section}
+\bookmarksetup{
+ italic=false
+}
+\part{Misc}
+\section{Diverse}
+\subsubsection{Subsubsection, omitting subsection}
+\bookmarksetup{
+ startatroot
+}
+\section{Last section outside part}
+\subsection{Subsection}
+\bookmarksetup{
+ color={}
+}
+\begingroup
+ \bookmarksetup{level=0, color=green!80!black}
+ \bookmark[named=FirstPage]{First page}
+ \bookmark[named=LastPage]{Last page}
+ \bookmark[named=PrevPage]{Previous page}
+ \bookmark[named=NextPage]{Next page}
+\endgroup
+\bookmark[
+ page=2,
+ view=FitH 800
+]{Page 2, FitH 800}
+\bookmark[
+ page=2,
+ view=FitBH \calc{\paperheight-\topmargin-1in-\headheight-\headsep}
+]{Page 2, FitBH top of text body}
+\bookmark[
+ uri={http://www.dante.de/},
+ color=magenta
+]{Dante homepage}
+\bookmark[
+ gotor={t.pdf},
+ page=1,
+ view={XYZ 0 1000 null},
+ color=cyan!75!black
+]{File t.pdf}
+\bookmark[named=FirstPage]{First page}
+\bookmark[rellevel=1, named=LastPage]{Last page (rellevel=1)}
+\bookmark[named=PrevPage]{Previous page}
+\bookmark[level=0, named=FirstPage]{First page (level=0)}
+\bookmark[
+ rellevel=1,
+ keeplevel,
+ named=LastPage
+]{Last page (rellevel=1, keeplevel)}
+\bookmark[named=PrevPage]{Previous page}
+\end{document}
+% \end{macrocode}
+% \begin{macrocode}
+%</example>
+% \end{macrocode}
+%
+% \StopEventually{
+% }
+%
+% \section{Implementation}
+%
+% \subsection{Package}
+%
+% \begin{macrocode}
+%<*package>
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{bookmark}%
+ [2007/02/20 v0.2 PDF bookmarks (HO)]
+% \end{macrocode}
+%
+% \subsubsection{Requirements}
+%
+% \begin{macrocode}
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname pdfescapehex\endcsname\relax
+ \PackageWarningNoLine{bookmark}{%
+ Some features of pdfTeX 1.30 are missing that\MessageBreak
+ protect some arguments. Replacements for these\MessageBreak
+ features are not implemented. Thus the pdf file\MessageBreak
+ can become invalid or the .aux file breaks%
+ }%
+ \let\BKM@escapename\@firstofone
+ \let\BKM@escapestring\@firstofone
+ \let\BKM@escapehex\@firstofone
+ \let\BKM@unescapehex\@firstofone
+\else
+ \let\BKM@escapename\pdfescapename
+ \let\BKM@escapestring\pdfescapestring
+ \let\BKM@escapehex\pdfescapehex
+ \let\BKM@unescapehex\pdfunescapehex
+\fi
+% \end{macrocode}
+%
+% \paragraph{Packages.}
+%
+% \begin{macrocode}
+\RequirePackage{ifpdf}
+\RequirePackage{ifxetex}
+\RequirePackage{hyperref}
+\RequirePackage{auxhook}
+\RequirePackage{flags}
+\RequirePackage{kvoptions}
+% \end{macrocode}
+%
+% \subsubsection{Package options}
+%
+% \begin{macrocode}
+\SetupKeyvalOptions{family=BKM,prefix=BKM@}
+\newcommand*{\bookmarksetup}{\setkeys{BKM}}
+\DeclareBoolOption{open}
+\DeclareStringOption[\maxdimen]{openlevel}
+\DeclareStringOption[\c@tocdepth]{depth}
+\DeclareStringOption[\BKM@currentlevel]{level}[\BKM@currentlevel]
+\DeclareBoolOption{keeplevel}
+\DeclareBoolOption{startatroot}
+\define@key{BKM}{rellevel}{%
+ \edef\BKM@level{\number\numexpr#1+\BKM@currentlevel\relax}%
+}
+\def\BKM@currentlevel{0}
+% \end{macrocode}
+%
+% \paragraph{Style options.}
+%
+% \begin{macrocode}
+\resetflags{BKM@style}
+\define@key{BKM}{italic}[true]{%
+ \expandafter\ifx\csname if#1\endcsname\iftrue
+ \setflag{BKM@style}{1}%
+ \else
+ \clearflag{BKM@style}{1}%
+ \fi
+}
+\define@key{BKM}{bold}[true]{%
+ \expandafter\ifx\csname if#1\endcsname\iftrue
+ \setflag{BKM@style}{2}%
+ \else
+ \clearflag{BKM@style}{2}%
+ \fi
+}
+% \end{macrocode}
+%
+% \paragraph{Options for color.}
+%
+% \begin{macrocode}
+\define@key{BKM}{rgbcolor}{%
+ \def\BKM@color{#1}%
+}
+\define@key{BKM}{color}{%
+ \ifx\\#1\\%
+ \let\BKM@color\@empty
+ \else
+ \@ifundefined{XC@bordercolor}{%
+ \PackageWarning{bookmark}{%
+ Load package `xcolor' (version >= 2.11) first.\MessageBreak
+ Ignoring color specification%
+ }%
+ }{%
+ \begingroup
+ \csname @safe@activestrue\endcsname
+ \XC@bordercolor{}{#1}%
+ \expandafter\endgroup
+ \expandafter\def\expandafter\BKM@color\expandafter{\@bordercolor}%
+ }%
+ \fi
+}
+\let\BKM@color\@empty
+% \end{macrocode}
+%
+% \subsubsection{Action options}
+%
+% \begin{macrocode}
+\DeclareStringOption{dest}
+\DeclareStringOption{named}
+\DeclareStringOption{uri}
+\DeclareStringOption{gotor}
+\DeclareStringOption{rawaction}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\define@key{BKM}{page}{%
+ \def\BKM@page{#1}%
+ \ifx\BKM@page\@empty
+ \else
+ \edef\BKM@page{\number\BKM@page}%
+ \ifnum\BKM@page>\z@
+ \else
+ \PackageError{bookmark}{Page must be positive}\@ehc
+ \def\BKM@page{1}%
+ \fi
+ \fi
+}
+\let\BKM@page\@empty
+% \end{macrocode}
+%
+% \begin{macrocode}
+\define@key{BKM}{view}{%
+ \BKM@CheckView{#1}%
+}
+\let\BKM@view\@empty
+\def\BKM@CheckView#1{%
+ \BKM@CheckViewType#1 \@nil
+}
+\def\BKM@CheckViewType#1 #2\@nil{%
+ \def\BKM@type{#1}%
+ \@onelevel@sanitize\BKM@type
+ \BKM@TestViewType{Fit}{}%
+ \BKM@TestViewType{FitB}{}%
+ \BKM@TestViewType{FitH}{%
+ \BKM@CheckParam#2 \@nil{top}%
+ }%
+ \BKM@TestViewType{FitBH}{%
+ \BKM@CheckParam#2 \@nil{top}%
+ }%
+ \BKM@TestViewType{FitV}{%
+ \BKM@CheckParam#2 \@nil{bottom}%
+ }%
+ \BKM@TestViewType{FitBV}{%
+ \BKM@CheckParam#2 \@nil{bottom}%
+ }%
+ \BKM@TestViewType{FitR}{%
+ \BKM@CheckRect{#2}{ }%
+ }%
+ \BKM@TestViewType{XYZ}{%
+ \BKM@CheckXYZ{#2}{ }%
+ }%
+ \@car{%
+ \PackageError{pdfbookmark}{%
+ Unknown view type `\BKM@type',\MessageBreak
+ using `FitH' instead%
+ }\@ehc
+ \def\BKM@view{FitH}%
+ }%
+ \@nil
+}
+\def\BKM@TestViewType#1{%
+ \def\BKM@temp{#1}%
+ \@onelevel@sanitize\BKM@temp
+ \ifx\BKM@type\BKM@temp
+ \let\BKM@view\BKM@temp
+ \expandafter\@car
+ \else
+ \expandafter\@gobble
+ \fi
+}
+\def\BKM@CheckParam#1 #2\@nil#3{%
+ \def\BKM@param{#1}%
+ \ifx\BKM@param\@empty
+ \PackageWarning{bookmark}{%
+ Missing parameter (#3) for `\BKM@type',\MessageBreak
+ using 0%
+ }%
+ \def\BKM@param{0}%
+ \else
+ \BKM@CalcParam
+ \fi
+ \edef\BKM@view{\BKM@view\space\BKM@param}%
+}
+\def\BKM@CheckRect#1#2{%
+ \BKM@@CheckRect#1#2#2#2#2\@nil
+}
+\def\BKM@@CheckRect#1 #2 #3 #4 #5\@nil{%
+ \def\BKM@temp{0}%
+ \def\BKM@param{#1}%
+ \ifx\BKM@param\@empty
+ \def\BKM@param{0}%
+ \def\BKM@temp{1}%
+ \else
+ \BKM@CalcParam
+ \fi
+ \edef\BKM@view{\BKM@view\space\BKM@param}%
+ \def\BKM@param{#2}%
+ \ifx\BKM@param\@empty
+ \def\BKM@param{0}%
+ \def\BKM@temp{1}%
+ \else
+ \BKM@CalcParam
+ \fi
+ \edef\BKM@view{\BKM@view\space\BKM@param}%
+ \def\BKM@param{#3}%
+ \ifx\BKM@param\@empty
+ \def\BKM@param{0}%
+ \def\BKM@temp{1}%
+ \else
+ \BKM@CalcParam
+ \fi
+ \edef\BKM@view{\BKM@view\space\BKM@param}%
+ \def\BKM@param{#4}%
+ \ifx\BKM@param\@empty
+ \def\BKM@param{0}%
+ \def\BKM@temp{1}%
+ \else
+ \BKM@CalcParam
+ \fi
+ \edef\BKM@view{\BKM@view\space\BKM@param}%
+ \ifnum\BKM@temp>\z@
+ \PackageWarning{bookmark}{Missing parameters for `\BKM@type'}%
+ \fi
+}
+\def\BKM@CheckXYZ#1#2{%
+ \BKM@@CheckXYZ#1#2#2#2\@nil
+}
+\def\BKM@@CheckXYZ#1 #2 #3 #4\@nil{%
+ \def\BKM@param{#1}%
+ \let\BKM@temp\BKM@param
+ \@onelevel@sanitize\BKM@temp
+ \ifx\BKM@param\@empty
+ \let\BKM@param\BKM@null
+ \else
+ \ifx\BKM@temp\BKM@null
+ \else
+ \BKM@CalcParam
+ \fi
+ \fi
+ \edef\BKM@view{\BKM@view\space\BKM@param}%
+ \def\BKM@param{#2}%
+ \let\BKM@temp\BKM@param
+ \@onelevel@sanitize\BKM@temp
+ \ifx\BKM@param\@empty
+ \let\BKM@param\BKM@null
+ \ifx\BKM@temp\BKM@null
+ \else
+ \BKM@CalcParam
+ \fi
+ \fi
+ \edef\BKM@view{\BKM@view\space\BKM@param}%
+ \def\BKM@param{#3}%
+ \ifx\BKM@param\@empty
+ \let\BKM@param\BKM@null
+ \fi
+ \edef\BKM@view{\BKM@view\space\BKM@param}%
+}
+\def\BKM@null{null}
+\@onelevel@sanitize\BKM@null
+% \end{macrocode}
+%
+% \begin{macrocode}
+\def\BKM@CalcParam{%
+ \begingroup
+ \let\calc\@firstofone
+ \expandafter\BKM@@CalcParam\BKM@param\@empty\@empty\@nil
+}
+\def\BKM@@CalcParam#1#2#3\@nil{%
+ \ifx\calc#1%
+ \@ifundefined{calc@assign@dimen}{%
+ \setlength{\dimen@}{\dimexpr#2\relax}%
+ }{%
+ \setlength{\dimen@}{#2}%
+ }%
+ \dimen@.99626\dimen@
+ \edef\BKM@param{\strip@pt\dimen@}%
+ \expandafter\endgroup
+ \expandafter\def\expandafter\BKM@param\expandafter{\BKM@param}%
+ \else
+ \endgroup
+ \fi
+}
+% \end{macrocode}
+%
+% \subsubsection{Driver setup and loading}
+%
+% \paragraph{Driver detection.}
+%
+% \begin{macrocode}
+\define@key{BKM}{pdftex}[]{%
+ \def\BKM@driver{pdftex}%
+}
+\define@key{BKM}{dvips}[]{%
+ \def\BKM@driver{dvips}%
+}
+\define@key{BKM}{dvipdfm}[]{%
+ \def\BKM@driver{dvipdfm}%
+}
+\define@key{BKM}{dvipdfmx}[]{%
+ \def\BKM@driver{dvipdfm}%
+}
+\define@key{BKM}{xetex}[]{%
+ \def\BKM@driver{dvipdfm}%
+}
+\InputIfFileExists{bookmark.cfg}{}{}
+\providecommand*{\BookmarkDriverDefault}{dvips}
+\ifpdf
+ \def\BKM@driver{pdftex}%
+\else
+ \ifxetex
+ \def\BKM@driver{dvipdfm}%
+ \else
+ \let\BKM@driver\BookmarkDriverDefault
+ \fi
+\fi
+% \end{macrocode}
+%
+% \paragraph{Process options.}
+%
+% \begin{macrocode}
+\ProcessKeyvalOptions*
+\DisableKeyvalOption{BKM}{pdftex}
+\DisableKeyvalOption{BKM}{dvips}
+\DisableKeyvalOption{BKM}{dvipdfm}
+\DisableKeyvalOption{BKM}{dvipdfmx}
+\DisableKeyvalOption{BKM}{xetex}
+% \end{macrocode}
+%
+% \paragraph{Driver validation and loading.}
+%
+% \begin{macrocode}
+\def\BKM@temp{pdftex}%
+\ifpdf
+ \ifx\BKM@temp\BKM@driver
+ \else
+ \PackageWarningNoLine{bookmark}{%
+ Wrong driver `\BKM@driver', using `pdftex' instead%
+ }%
+ \let\BKM@driver\BKM@temp
+ \fi
+\else
+ \ifx\BKM@temp\BKM@driver
+ \PackageError{bookmark}{%
+ Wrong driver, pdfTeX is not running in PDF mode.\MessageBreak
+ Package loading is aborted%
+ }\@ehc
+ \expandafter\expandafter\expandafter\endinput
+ \fi
+ \def\BKM@temp{dvipdfm}%
+ \ifxetex
+ \ifx\BKM@temp\BKM@driver
+ \else
+ \PackageWarningNoLine{bookmark}{%
+ Wrong driver `\BKM@driver',\MessageBreak
+ using `dvipdfm' for XeTeX instead%
+ }%
+ \let\BKM@driver\BKM@temp
+ \fi
+ \fi
+\fi
+\InputIfFileExists{bkm-\BKM@driver.def}{}{%
+ \PackageError{bookmark}{%
+ Unsupported driver `\BKM@driver'.\MessageBreak
+ Package loading is aborted%
+ }\@ehc
+ \endinput
+}
+% \end{macrocode}
+%
+% \subsubsection{Compatibility for \xpackage{hyperref}}
+%
+% \begin{macrocode}
+\renewcommand*{\pdfbookmark}[3][0]{%
+ \bookmark[level=#1,dest={#3.#1}]{#2}%
+ \hyper@anchorstart{#3.#1}\hyper@anchorend
+}
+\renewcommand*{\currentpdfbookmark}{%
+ \pdfbookmark[\BKM@currentlevel]%
+}
+\renewcommand*{\subpdfbookmark}{%
+ \expandafter\pdfbookmark\expandafter[%
+ \the\numexpr\BKM@currentlevel+1\relax
+ ]%
+}
+\renewcommand*{\belowpdfbookmark}[2]{%
+ \xdef\BKM@gtemp{\number\BKM@currentlevel}%
+ \subpdfbookmark{#1}{#2}%
+ \global\let\BKM@currentlevel\BKM@gtemp
+}
+% \end{macrocode}
+%
+% section number, text, label, level, file
+% \begin{macrocode}
+\renewcommand*{\Hy@writebookmark}[5]{%
+ \ifnum#4>\Hy@bookmarksdepth\relax
+ \else
+ \begingroup
+ \ifHy@bookmarksnumbered
+ \let\numberline\Hy@numberline
+ \let\partnumberline\Hy@numberline
+ \let\chapternumberline\Hy@numberline
+ \else
+ \let\numberline\@gobble
+ \let\partnumberline\@gobble
+ \let\chapternumberline\@gobble
+ \fi
+ \bookmark[level=#4,dest={#3}]{#2}%
+ \endgroup
+ \fi
+}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\let\ReadBookmarks\relax
+% \end{macrocode}
+%
+% \begin{macrocode}
+%</package>
+% \end{macrocode}
+%
+% \subsection{Driver for dvipdfm}
+%
+% \begin{macrocode}
+%<*dvipdfm>
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesFile{bkm-dvipdfm.def}%
+ [2007/02/20 v0.2 bookmark driver for dvipdfm (HO)]
+% \end{macrocode}
+%
+% \begin{macrocode}
+\newcount\BKM@id
+\BKM@id=\z@
+% \end{macrocode}
+%
+% \begin{macrocode}
+\def\BKM@0{000}
+% \end{macrocode}
+% \begin{macrocode}
+\newif\ifBKM@sw
+% \end{macrocode}
+%
+% \begin{macrocode}
+\newcommand*{\bookmark}[2][]{%
+ \if@filesw
+ \begingroup
+ \bookmarksetup{#1}%
+ \ifBKM@keeplevel
+ \else
+ \xdef\BKM@currentlevel{\BKM@level}%
+ \fi
+ \edef\BKM@prev{\the\BKM@id}%
+ \global\advance\BKM@id\@ne
+ \BKM@swtrue
+ \@whilesw\ifBKM@sw\fi{%
+ \def\BKM@abslevel{1}%
+ \ifnum\ifBKM@startatroot\z@\else\BKM@prev\fi=\z@
+ \global\BKM@startatrootfalse
+ \expandafter\xdef\csname BKM@\the\BKM@id\endcsname{%
+ 0{\BKM@level}\BKM@abslevel
+ }%
+ \BKM@swfalse
+ \else
+ \expandafter\expandafter\expandafter\BKM@getx
+ \csname BKM@\BKM@prev\endcsname
+ \ifnum\BKM@level>\BKM@x@level\relax
+ \edef\BKM@abslevel{\the\numexpr\BKM@x@abslevel+1\relax}%
+ \expandafter\xdef\csname BKM@\the\BKM@id\endcsname{%
+ {\BKM@prev}{\BKM@level}\BKM@abslevel
+ }%
+ \BKM@swfalse
+ \else
+ \let\BKM@prev\BKM@x@parent
+ \fi
+ \fi
+ }%
+ \pdfstringdef\BKM@title{#2}%
+ \edef\BKM@FLAGS{\printflags{BKM@style}}%
+ \let\BKM@action\@empty
+ \ifx\BKM@gotor\@empty
+ \ifx\BKM@dest\@empty
+ \ifx\BKM@named\@empty
+ \ifx\BKM@rawaction\@empty
+ \ifx\BKM@uri\@empty
+ \ifx\BKM@page\@empty
+ \PackageError{bookmark}{Missing action}\@ehc
+ \edef\BKM@action{/Dest[@page1/Fit]}%
+ \else
+ \ifx\BKM@view\@empty
+ \def\BKM@view{Fit}%
+ \fi
+ \edef\BKM@action{/Dest[@page\BKM@page/\BKM@view]}%
+ \fi
+ \else
+ \edef\BKM@action{%
+ /A<<%
+ /S/URI%
+ /URI(\BKM@escapestring{\BKM@uri})%
+ >>%
+ }%
+ \fi
+ \else
+ \edef\BKM@action{/A<<\BKM@rawaction>>}%
+ \fi
+ \else
+ \edef\BKM@action{%
+ /A<</S/Named/N/\BKM@escapename{\BKM@named}>>%
+ }%
+ \fi
+ \else
+ \edef\BKM@action{%
+ /A<<%
+ /S/GoTo%
+ /D(\BKM@escapestring{\BKM@dest})%
+ >>%
+ }%
+ \fi
+ \else
+ \ifx\BKM@dest\@empty
+ \ifx\BKM@page\@empty
+ \def\BKM@page{0}%
+ \else
+ \edef\BKM@page{\the\numexpr\BKM@page-1\relax}%
+ \fi
+ \ifx\BKM@view\@empty
+ \def\BKM@view{Fit}%
+ \fi
+ \edef\BKM@action{/D[\BKM@page/\BKM@view]}%
+ \else
+ \edef\BKM@action{/D(\BKM@escapestring{\BKM@dest})}%
+ \fi
+ \edef\BKM@action{%
+ /A<<%
+ /S/GoToR%
+ /F(\BKM@escapestring{\BKM@gotor})%
+ \BKM@action
+ >>%
+ }%
+ \fi
+ \special{pdf:%
+ out \BKM@abslevel
+ <<%
+ /Title(\BKM@title)%
+ \ifx\BKM@color\@empty
+ \else
+ /C[\BKM@color]%
+ \fi
+ \ifnum\BKM@FLAGS>\z@
+ /F \BKM@FLAGS
+ \fi
+ \BKM@action
+ >>%
+ }%
+ \endgroup
+ \fi
+}
+% \end{macrocode}
+% \begin{macrocode}
+\def\BKM@getx#1#2#3{%
+ \def\BKM@x@parent{#1}%
+ \def\BKM@x@level{#2}%
+ \def\BKM@x@abslevel{#3}%
+}
+% \end{macrocode}
+%
+% \begin{macrocode}
+%</dvipdfm>
+% \end{macrocode}
+%
+% \subsection{Driver for \pdfTeX}
+%
+% \begin{macrocode}
+%<*pdftex>
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesFile{bkm-pdftex.def}%
+ [2007/02/20 v0.2 bookmark driver for pdftex (HO)]
+% \end{macrocode}
+%
+% \begin{macrocode}
+\def\BKM@DO@entry#1#2{%
+ \begingroup
+ \setkeys{BKM@DO}{#1}%
+ \edef\BKM@DO@title{\BKM@unescapehex{#2}}%
+ \expandafter\expandafter\expandafter\BKM@getx
+ \csname BKM@\BKM@DO@id\endcsname\@empty\@empty
+ \let\BKM@attr\@empty
+ \ifx\BKM@DO@flags\@empty
+ \else
+ \edef\BKM@attr{\BKM@attr/F \BKM@DO@flags}%
+ \fi
+ \ifx\BKM@DO@color\@empty
+ \else
+ \edef\BKM@attr{\BKM@attr/C[\BKM@DO@color]}%
+ \fi
+ \ifx\BKM@attr\@empty
+ \else
+ \edef\BKM@attr{attr{\BKM@attr}}%
+ \fi
+ \let\BKM@action\@empty
+ \ifx\BKM@DO@gotor\@empty
+ \ifx\BKM@DO@dest\@empty
+ \ifx\BKM@DO@named\@empty
+ \ifx\BKM@DO@rawaction\@empty
+ \ifx\BKM@DO@uri\@empty
+ \ifx\BKM@DO@page\@empty
+ \PackageError{bookmark}{Missing action}\@ehc
+ \edef\BKM@action{goto page1{/Fit}}%
+ \else
+ \ifx\BKM@DO@view\@empty
+ \def\BKM@DO@view{Fit}%
+ \fi
+ \edef\BKM@action{goto page\BKM@DO@page{/\BKM@DO@view}}%
+ \fi
+ \else
+ \edef\BKM@action{user{<</S/URI/URI(%
+ \BKM@escapestring{\BKM@unescapehex{\BKM@DO@uri}})>>}}%
+ \fi
+ \else
+ \edef\BKM@action{%
+ user{%
+ <<%
+ \BKM@unescapehex{\BKM@DO@rawaction}%
+ >>%
+ }%
+ }%
+ \fi
+ \else
+ \edef\BKM@action{%
+ user{<</S/Named/N/\BKM@escapename{\BKM@DO@named}>>}%
+ }%
+ \fi
+ \else
+ \edef\BKM@action{goto name{\BKM@DO@dest}}%
+ \fi
+ \else
+ \ifx\BKM@DO@dest\@empty
+ \ifx\BKM@DO@page\@empty
+ \def\BKM@DO@page{0}%
+ \else
+ \edef\BKM@DO@page{\the\numexpr\BKM@DO@page-1\relax}%
+ \fi
+ \ifx\BKM@DO@view\@empty
+ \def\BKM@DO@view{Fit}%
+ \fi
+ \edef\BKM@action{/D[\BKM@DO@page/\BKM@DO@view]}%
+ \else
+ \edef\BKM@action{/D(\BKM@escapestring{\BKM@DO@dest})}%
+ \fi
+ \edef\BKM@action{%
+ user{%
+ <<%
+ /S/GoToR%
+ /F(\BKM@escapestring{\BKM@unescapehex{\BKM@DO@gotor}})%
+ \BKM@action
+ >>%
+ }%
+ }%
+ \fi
+ \pdfoutline\BKM@attr\BKM@action
+ count\ifBKM@DO@open\else-\fi\BKM@x@childs
+ {\BKM@DO@title}%
+ \endgroup
+}
+% \end{macrocode}
+%
+% \begin{macrocode}
+%</pdftex>
+% \end{macrocode}
+%
+% \subsection{Driver for dvips}
+%
+% \begin{macrocode}
+%<*dvips>
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesFile{bkm-dvips.def}%
+ [2007/02/20 v0.2 bookmark driver for dvips (HO)]
+% \end{macrocode}
+%
+% \begin{macrocode}
+\def\BKM@filename{\jobname.out.ps}
+\special{header=\BKM@filename}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\AtEndDocument{\BKM@dvips@out}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\def\BKM@dvips@out{%
+ \newwrite\BKM@file
+ \immediate\openout\BKM@file=\BKM@filename\relax
+ \BKM@write{\@percentchar!}%
+ \BKM@write{/pdfmark where{pop}}%
+ \BKM@write{%
+ {%
+ /globaldict where{pop globaldict}{userdict}ifelse%
+ /pdfmark/cleartomark load put%
+ }%
+ }%
+ \BKM@write{ifelse}
+}
+\def\BKM@write#{%
+ \immediate\write\BKM@file
+}
+% \end{macrocode}
+%
+% The specification for pdfmark says that |/Color| is the
+% name of the key for color, however ghostscript only passes
+% the key into the PDF file, thus the key name must be |/C|.
+% \begin{macrocode}
+\def\BKM@DO@entry#1#2{%
+ \begingroup
+ \setkeys{BKM@DO}{#1}%
+ \edef\BKM@DO@title{\BKM@unescapehex{#2}}%
+ \expandafter\expandafter\expandafter\BKM@getx
+ \csname BKM@\BKM@DO@id\endcsname\@empty\@empty
+ \let\BKM@attr\@empty
+ \ifx\BKM@DO@flags\@empty
+ \else
+ \edef\BKM@attr{\BKM@attr/F \BKM@DO@flags}%
+ \fi
+ \ifx\BKM@DO@color\@empty
+ \else
+ \edef\BKM@attr{\BKM@attr/C[\BKM@DO@color]}%
+ \fi
+ \let\BKM@action\@empty
+ \ifx\BKM@DO@gotor\@empty
+ \ifx\BKM@DO@dest\@empty
+ \ifx\BKM@DO@named\@empty
+ \ifx\BKM@DO@rawaction\@empty
+ \ifx\BKM@DO@uri\@empty
+ \ifx\BKM@DO@page\@empty
+ \PackageError{bookmark}{Missing action}\@ehc
+ \edef\BKM@action{%
+ /Action/GoTo%
+ /Page 1%
+ /View[/Fit]%
+ }%
+ \else
+ \ifx\BKM@DO@view\@empty
+ \def\BKM@DO@view{Fit}%
+ \fi
+ \edef\BKM@action{%
+ /Action/GoTo%
+ /Page \BKM@DO@page
+ /View[/\BKM@DO@view]%
+ }%
+ \fi
+ \else
+ \edef\BKM@action{%
+ /Action<<%
+ /Subtype/URI%
+ /URI(\BKM@escapestring{\BKM@unescapehex{\BKM@DO@uri}})%
+ >>%
+ }%
+ \fi
+ \else
+ \edef\BKM@action{%
+ /Action<<%
+ \BKM@unescapehex{\BKM@DO@rawaction}%
+ >>%
+ }%
+ \fi
+ \else
+ \edef\BKM@action{%
+ /Action<<%
+ /Subtype/Named%
+ /N/\BKM@escapename{\BKM@DO@named}%
+ >>%
+ }%
+ \fi
+ \else
+ \edef\BKM@action{%
+ /Action/GoTo%
+ /Dest(\BKM@escapestring{\BKM@DO@dest})cvn%
+ }%
+ \fi
+ \else
+ \ifx\BKM@DO@dest\@empty
+ \ifx\BKM@DO@page\@empty
+ \def\BKM@DO@page{1}%
+ \fi
+ \ifx\BKM@DO@view\@empty
+ \def\BKM@DO@view{Fit}%
+ \fi
+ \edef\BKM@action{%
+ /Page \BKM@DO@page
+ /View[/\BKM@DO@view]%
+ }%
+ \else
+ \edef\BKM@action{%
+ /Dest(\BKM@escapestring{\BKM@DO@dest})cvn%
+ }%
+ \fi
+ \edef\BKM@action{%
+ /Action/GoToR%
+ /F(\BKM@escapestring{\BKM@unescapehex{\BKM@DO@gotor}})%
+ \BKM@action
+ }%
+ \fi
+ \BKM@write{[}%
+ \BKM@write{/Title(\BKM@DO@title)}%
+ \ifnum\BKM@x@childs>\z@
+ \BKM@write{/Count \ifBKM@DO@open\else-\fi\BKM@x@childs}%
+ \fi
+ \ifx\BKM@attr\@empty
+ \else
+ \BKM@write{\BKM@attr}%
+ \fi
+ \BKM@write{\BKM@action}%
+ \BKM@write{/OUT pdfmark}%
+ \endgroup
+}
+% \end{macrocode}
+% \begin{macrocode}
+%</dvips>
+% \end{macrocode}
+%
+% \subsection{Common part for \xoption{pdftex} and \xoption{dvips}}
+%
+% \begin{macrocode}
+%<*pdftex|dvips>
+% \end{macrocode}
+%
+% \subsubsection{Write auxiliary file}
+%
+% \begin{macrocode}
+\RequirePackage{auxhook}
+% \end{macrocode}
+% \begin{macrocode}
+\AddLineBeginMainAux{%
+ \string\providecommand\string\BKM@entry[2]{}%
+}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\newcount\BKM@id
+\BKM@id=\z@
+% \end{macrocode}
+%
+% \begin{macrocode}
+\def\BKM@0{000}
+% \end{macrocode}
+% \begin{macrocode}
+\newif\ifBKM@sw
+% \end{macrocode}
+%
+% \begin{macrocode}
+\newcommand*{\bookmark}[2][]{%
+ \if@filesw
+ \begingroup
+ \bookmarksetup{#1}%
+ \ifBKM@keeplevel
+ \else
+ \xdef\BKM@currentlevel{\BKM@level}%
+ \fi
+ \edef\BKM@prev{\the\BKM@id}%
+ \global\advance\BKM@id\@ne
+ \BKM@swtrue
+ \@whilesw\ifBKM@sw\fi{%
+ \ifnum\ifBKM@startatroot\z@\else\BKM@prev\fi=\z@
+ \global\BKM@startatrootfalse
+ \expandafter\xdef\csname BKM@\the\BKM@id\endcsname{%
+ 0{\BKM@level}0%
+ }%
+ \BKM@swfalse
+ \else
+ \expandafter\expandafter\expandafter\BKM@getx
+ \csname BKM@\BKM@prev\endcsname
+ \ifnum\BKM@level>\BKM@x@level\relax
+ \expandafter\xdef\csname BKM@\the\BKM@id\endcsname{%
+ {\BKM@prev}{\BKM@level}0%
+ }%
+ \ifnum\BKM@prev>\z@
+ \expandafter\xdef\csname BKM@\BKM@prev\endcsname{%
+ {\BKM@x@parent}{\BKM@x@level}{%
+ \the\numexpr\BKM@x@childs+1\relax
+ }%
+ }%
+ \fi
+ \BKM@swfalse
+ \else
+ \let\BKM@prev\BKM@x@parent
+ \fi
+ \fi
+ }%
+ \pdfstringdef\BKM@title{#2}%
+ \edef\BKM@FLAGS{\printflags{BKM@style}}%
+ \immediate\write\@mainaux{%
+ \string\BKM@entry{%
+ id=\number\BKM@id
+ \ifBKM@open
+ \ifnum\BKM@level<\BKM@openlevel
+ ,open%
+ \fi
+ \fi
+ \ifx\BKM@dest\@empty
+ \else
+ ,dest={\BKM@dest}%
+ \fi
+ \ifx\BKM@named\@empty
+ \else
+ ,named={\BKM@named}%
+ \fi
+ \ifx\BKM@uri\@empty
+ \else
+ ,uri={\BKM@escapehex{\BKM@uri}}%
+ \fi
+ \ifx\BKM@gotor\@empty
+ \else
+ ,gotor={\BKM@escapehex{\BKM@gotor}}%
+ \fi
+ \ifx\BKM@page\@empty
+ \else
+ ,page=\BKM@page
+ \fi
+ \ifx\BKM@view\@empty
+ \else
+ ,view={\BKM@view}%
+ \fi
+ \ifx\BKM@rawaction\@empty
+ \else
+ ,rawaction={\BKM@escapehex{\BKM@rawaction}}%
+ \fi
+ \ifnum\BKM@FLAGS>\z@
+ ,flags=\BKM@FLAGS
+ \fi
+ \ifx\BKM@color\@empty
+ \else
+ ,color={\BKM@color}%
+ \fi
+ }{\BKM@escapehex{\BKM@title}}%
+ }%
+ \endgroup
+ \fi
+}
+% \end{macrocode}
+% \begin{macrocode}
+\def\BKM@getx#1#2#3{%
+ \def\BKM@x@parent{#1}%
+ \def\BKM@x@level{#2}%
+ \def\BKM@x@childs{#3}%
+}
+% \end{macrocode}
+%
+% \subsubsection{Read auxiliary data}
+%
+% \begin{macrocode}
+\SetupKeyvalOptions{family=BKM@DO,prefix=BKM@DO@}
+\DeclareStringOption[0]{id}
+\DeclareBoolOption{open}
+\DeclareStringOption{flags}
+\DeclareStringOption{color}
+\DeclareStringOption{dest}
+\DeclareStringOption{named}
+\DeclareStringOption{uri}
+\DeclareStringOption{gotor}
+\DeclareStringOption{page}
+\DeclareStringOption{view}
+\DeclareStringOption{rawaction}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\AtBeginDocument{%
+ \let\BKM@entry\BKM@DO@entry
+}
+% \end{macrocode}
+%
+% \begin{macrocode}
+%</pdftex|dvips>
+% \end{macrocode}
+%
+%
+% \section{Installation}
+%
+% \paragraph{CTAN.} This package is available on
+% CTAN\footnote{\url{ftp://ftp.ctan.org/tex-archive/}}:
+% \begin{description}
+% \item[\CTAN{macros/latex/contrib/oberdiek/bookmark.dtx}] The source file.
+% \item[\CTAN{macros/latex/contrib/oberdiek/bookmark.pdf}] Documentation.
+% \end{description}
+%
+% \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
+% \docstrip\ archive. The files are extracted by running the
+% \xfile{.dtx} through \plainTeX:
+% \begin{quote}
+% \verb|tex bookmark.dtx|
+% \end{quote}
+%
+% \paragraph{TDS.} Now the different files must be moved into
+% the different directories in your installation TDS tree
+% (also known as \xfile{texmf} tree):
+% \begin{quote}
+% \sbox0{^^A
+% \begin{tabular}{@{}>{\ttfamily}l@{$\quad\rightarrow\quad$}>{\ttfamily}l@{}}
+% bookmark.sty & tex/latex/oberdiek/bookmark.sty\\
+% bkm-dvipdfm.def & tex/latex/oberdiek/bkm-dvipdfm.def\\
+% bkm-dvips.def & tex/latex/oberdiek/bkm-dvips.def\\
+% bkm-pdftex.def & tex/latex/oberdiek/bkm-pdftex.def\\
+% bookmark.pdf & doc/latex/oberdiek/bookmark.pdf\\
+% bookmark-example.tex & doc/latex/oberdiek/bookmark-example.tex\\
+% bookmark.dtx & source/latex/oberdiek/bookmark.dtx\\
+% \end{tabular}^^A
+% }%
+% \ifdim\wd0>\linewidth
+% \mbox{}\nobreak\hskip0pt minus\leftmargin
+% \usebox0
+% \nobreak\hskip0pt minus\rightmargin
+% \else
+% \usebox0
+% \fi
+% \end{quote}
+% If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
+% TDS installing feature, then some files can already be in the right
+% place, see the documentation of \docstrip.
+%
+% \paragraph{Refresh file databases.} If your \TeX~distribution
+% (\teTeX, \mikTeX, \dots) rely on file databases, you must refresh
+% these. For example, \teTeX\ users run \verb|texhash| or
+% \verb|mktexlsr|.
+%
+% \subsection{Some details for the interested}
+%
+% \paragraph{Attached source.}
+%
+% The PDF documentation on CTAN also includes the
+% \xfile{.dtx} source file. It can be extracted by
+% AcrobatReader 6 or higher. Another option is \textsf{pdftk},
+% e.g. unpack the file into the current directory:
+% \begin{quote}
+% \verb|pdftk bookmark.pdf unpack_files output .|
+% \end{quote}
+%
+% \paragraph{Unpacking with \LaTeX.}
+% The \xfile{.dtx} chooses its action depending on the format:
+% \begin{description}
+% \item[\plainTeX:] Run \docstrip\ and extract the files.
+% \item[\LaTeX:] Generate the documentation.
+% \end{description}
+% If you insist on using \LaTeX\ for \docstrip\ (really,
+% \docstrip\ does not need \LaTeX), then inform the autodetect routine
+% about your intention:
+% \begin{quote}
+% \verb|latex \let\install=y\input{bookmark.dtx}|
+% \end{quote}
+% Do not forget to quote the argument according to the demands
+% of your shell.
+%
+% \paragraph{Generating the documentation.}
+% You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
+% the documentation. The process can be configured by the
+% configuration file \xfile{ltxdoc.cfg}. For instance, put this
+% line into this file, if you want to have A4 as paper format:
+% \begin{quote}
+% \verb|\PassOptionsToClass{a4paper}{article}|
+% \end{quote}
+% An example follows how to generate the
+% documentation with pdf\LaTeX:
+% \begin{quote}
+%\begin{verbatim}
+%pdflatex bookmark.dtx
+%makeindex -s gind.ist bookmark.idx
+%pdflatex bookmark.dtx
+%makeindex -s gind.ist bookmark.idx
+%pdflatex bookmark.dtx
+%\end{verbatim}
+% \end{quote}
+%
+% \begin{History}
+% \begin{Version}{2007/02/19 v0.1}
+% \item
+% First experimental version.
+% \end{Version}
+% \begin{Version}{2007/02/20 v0.2}
+% \item
+% Option \xoption{startatroot} added.
+% \item
+% Dummies for \cs{pdf(un)escape...} commands added to get
+% the package basically work for non-pdfTeX users.
+% \end{Version}
+% \end{History}
+%
+% \PrintIndex
+%
+% \Finale
+\endinput