% \iffalse
%<*copyright>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% aeb_mlink.sty package,          2007-05-14           %%
%% Copyright (C) 2006  D. P. Story                      %%
%%   dpstory@acrotex.net                                %%
%%   storyd@owc.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 of the  %%
%% License, or (at your option) any later version.      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%</copyright>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{aeb_mlink}
%<package> [2010/09/26 v1.0 AeB MLink (dps)]
%<*driver>
\documentclass{ltxdoc}
\usepackage[dviwindo,colorlinks,hyperindex]{hyperref}
\pdfstringdefDisableCommands{\let\\\textbackslash}%
\EnableCrossrefs \CodelineIndex
\OnlyDescription  % comment out for implementation details
\begin{document}
  \GetFileInfo{aeb_mlink.sty}
  \title{The \textsf{aeb\_mlink} Package\texorpdfstring{\\}{: }
  A member of the AeB Pro family}
  \author{D. P. Story\\
    Email: \texttt{storyd@owc.edu}}
  \date{processed \today}
  \maketitle
  \tableofcontents
  \let\Email\texttt
  \DocInput{aeb_mlink.dtx}
  \PrintIndex
\end{document}
%</driver>
% \fi
% \section{Introduction}
% This package creates \underbar{m}ultiline-\underbar{links}.
% The package \textsf{hyperref} does create links, but generally
% these links cannot be broken across lines, unless \textsf{pdflatex}
% is used to create a PDF.
%
% This package uses the \texttt{QuadPoints} entry in the link annotation to create
% a bounding region; consequently, this package requires \textbf{Acrobat Distiller}
% to create a PDF. \texttt{QuadPoints} is a PDF 1.6 feature, so these multiline links
% will work in Adobe Reader 7.0 or later. If viewed in a version of Adobe Reader previous
% to 7.0, the viewer will use the underlying bounding box.
%
% LaTeX package requirements are the \textsf{eForms} and \textsf{hyperref}. Only the use
% of \textsf{dvips} and \textsf{dvipsone} is supported.
%
%The key to creating a multi-line is contained in Table~8.24 of the
%PDF Reference. The description of \texttt{QuadPoints} in the PDF Reference
%is as follows:
%
%\begin{quote}\small
%(Optional; PDF 1.6) An array of $8 \times n$ numbers specifying the
%coordinates of $n$ quadrilaterals in default user space that comprise
%the region in which the link should be activated. The coordinates
%for each quadrilateral are given in the order
%$$
%        x_1\ y_1\ x_2\ y_2\ x_3\ y_3\ x_4\ y_4
%$$
%specifying the four vertices of the quadrilateral in
%counterclockwise order. For orientation purposes, such as when
%applying an underline border style, the bottom of a quadrilateral is
%the line formed by $(x_1 , y_1)$ and $(x_2 , y_2)$. If this entry is not
%present or the viewer application does not recognize it, the region
%specified by the \texttt{Rect} entry should be used. \texttt{QuadPoints} should be
%ignored if any coordinate in the array lies outside the region
%specified by \texttt{Rect}.
%\end{quote}
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%    \begin{macro}{dvipsone}
% Set the driver for \texttt{dvipsone}
%    \begin{macrocode}
\DeclareOption{dvipsone}{\def\eq@drivernum{0}
    \def\eq@drivername{0}% dvipsone
    \PassOptionsToPackage{dvipsone}{eforms}
    \PassOptionsToPackage{dvipsone}{hyperref} %,colorlinks
}
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}{dvips}
% Set the driver for \texttt{dvips}
%    \begin{macrocode}
\DeclareOption{dvips}{\def\eq@drivernum{0}
    \def\eq@drivername{1}% dvips
    \PassOptionsToPackage{dvips}{eforms}
    \PassOptionsToPackage{dvips}{hyperref} %,colorlinks
}
%    \end{macrocode}
%    \end{macro}
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
% We require hyperref, eforms and soul.  For eforms, a recent version is needed,
% \texttt{2008/03/14} or later.
%    \begin{macrocode}
\RequirePackage{hyperref}
\RequirePackage{eforms}[2008/03/14]
\RequirePackage{soul}
%    \end{macrocode}
%
% \section{Driver Dependent Code}
%
% Driver dependent definitions for dvipsone and dvips.
%    \begin{macrocode}
\ifnum\eq@drivername=0\relax% dvipsone
%    \end{macrocode}
% This next \cs{special} defines some standard conversion
% formulas, {\TeX} to PDF and PDF to {\TeX} in the YandY TeX System.
%    \begin{macrocode}
\special{!/TeXtoPDF {65536 div mag 1000 div mul} def
/PDFtoTeX {65536 mul mag 1000 div div} def}
%    \end{macrocode}
% This command calculates the \cs{QuadPoints} array
% when we are using the \textsf{dvipsone} driver.
%    \begin{macrocode}
\def\setQuadBox{%
   currentpoint \aeb@bbox@dp\space add TeXtoPDF
   neg PageHeight add 72 sub                            % y1
   exch TeXtoPDF 72 add  exch                           % x1
   2 copy exch \aeb@bbox@wd\space TeXtoPDF add exch     % x2
   2 copy \aeb@bbox@ht\space TeXtoPDF add               % y3
   2 copy exch \aeb@bbox@wd\space TeXtoPDF sub exch     % x4
}
%    \end{macrocode}
% For the bounding rectangle, we just enclose the entire page. This
% simplifies things greatly.
%    \begin{macrocode}
\def\par@@Rect
{%
    72 neg PDFtoTeX PageHeight 72 sub PDFtoTeX
    PageWidth 72 sub PDFtoTeX 72 neg PDFtoTeX
}
\else % dvips
%    \end{macrocode}
% This next \cs{special} defines some standard conversion
% formulas, {\TeX} to PDF and PDF to {\TeX} for \textsf{dvips}.
%    \begin{macrocode}
\special{!userdict begin
   /TeXtoPDF {65536 div DVImag mul} def         % sp to pts
   /PDFtoDvips {72.27 div Resolution mul} def   % points to dots
   /PDFtoVDvips {72.27 div VResolution mul} def % points to dots
   /DvipstoPDF {72.27 mul Resolution div} def   % dots to points
   /HTeXtoDvips {TeXtoPDF PDFtoDvips} def       % sp to dots
   /VTeXtoDvips {TeXtoPDF PDFtoVDvips} def end} % sp to dots
%    \end{macrocode}
% This command calculates the \cs{QuadPoints} array
% when we are using the \textsf{dvips} driver.
%    \begin{macrocode}
\def\setQuadBox{%
    currentpoint DvipstoPDF \aeb@bbox@dp\space TeXtoPDF add
    neg vsize add 72 sub                                % y1
    exch DvipstoPDF 72 add exch                         % x1
    2 copy exch \aeb@bbox@wd\space TeXtoPDF add exch    % x2
    2 copy \aeb@bbox@ht\space TeXtoPDF add              % y3
    2 copy exch \aeb@bbox@wd\space TeXtoPDF sub exch    % x4
}
%    \end{macrocode}
% For the bounding rectangle, we just enclose the entire page. This
% simplifies things greatly.
%    \begin{macrocode}
\def\par@@Rect
{%
    72 neg PDFtoDvips vsize 72 sub PDFtoVDvips
    hsize 72 sub PDFtoDvips 72 neg PDFtoVDvips
}
\fi
%    \end{macrocode}
%
% \section{The Multi-line Linking Commands}
%
% We use a box, and two counters for this package.
%    \begin{macrocode}
\newbox\aeb@bbox
\newcount\aeb@arrayIndx \aeb@arrayIndx=0
\newcount\aeb@mLinkCnt \aeb@mLinkCnt=0
%    \end{macrocode}
%    \begin{macro}{\mlhypertext}
%
% This is a general purpose hypertext link. Not only is it
% a fine stand-alone linking command, but it also serves
% as a building block to some convenience commends that follow.
%
% The commands takes two arguments, the first an optional one the second
% one requires.
% \begin{enumerate}
%   \item[\texttt{[\#1]}] A standard optional argument for eForms, to change
%       the appearance of the link and/or to include actions.
%   \item[\texttt{\#2}] The text to be enclosed in a link.
% \end{enumerate}
%    \begin{macrocode}
\def\CurrentBorderColor{\@linkbordercolor}
\def\ml@nocolorHighlight{I}
\def\ml@nocolorLineStyle{S}
\def\ml@nocolorLineWidth{1}
\def\ml@setnocolorDefaults{%
\def\ml@nocolor@defaults{\H{\ml@nocolorHighlight}%
    \S{\ml@nocolorLineStyle}\W{\ml@nocolorLineWidth}%
    \Color{\CurrentBorderColor}}%
}
\ifHy@colorlinks
    \let\ml@nocolor@defaults\@empty
\else
    \ml@setnocolorDefaults
\fi
\def\ml@earlyExecProps#1{%
%    \expandafter\ifx\csname @equi\endcsname\relax\else
        \eq@setWidgetProps\relax{#1}%
%    \fi
}
\let\mlh@preambleCmdInsert\relax
\newcommand{\mlhypertext}[1][]{\global\aeb@arrayIndx=0\relax
    \global\advance\aeb@mLinkCnt1\relax
%    \end{macrocode}
% We do something different, we process the use options early, mostly
% to get any change in linktxtcolor, but only if the user-friendly ui is
% present.
%    \begin{macrocode}
    \special{ps: [ /_objdef {mLink\the\aeb@mLinkCnt}
        /type /array /OBJ pdfmark}%
    \def\mlh@preambleCmdInsert{\ml@earlyExecProps{#1}}%
    \def\mlh@postambleCmd{\setLinkPbox{\S{S}\W{0}%
        \presets{\ml@nocolor@defaults}%
        \QuadPoints{mLink\the\aeb@mLinkCnt}#1}\endgroup}%
    \aeb@mlh
}
\def\mlh@setQuadSyllable#1{%
    \setbox\aeb@bbox=\hbox{\strut#1}%
    {%
        \count\z@=\ht\aeb@bbox\xdef\aeb@bbox@ht{\the\count\z@}%
        \count\z@=\wd\aeb@bbox\xdef\aeb@bbox@wd{\the\count\z@}%
        \dp\aeb@bbox=1pt\relax
        \count\z@=\dp\aeb@bbox\xdef\aeb@bbox@dp{\the\count\z@}%
    }%
    \special{ps: [{mLink\the\aeb@mLinkCnt}
        \the\aeb@arrayIndx\space [\setQuadBox]
            \space /PUTINTERVAL pdfmark}%
    \global\advance\aeb@arrayIndx8\relax
}
%    \end{macrocode}
%    \end{macro}
% The next four commands are used internally, though \cs{aebnameref},
% \cs{labelRef} and \cs{atPage} are public, and can be used.
%    \begin{macrocode}
\def\aeb@exiii{\expandafter\expandafter\expandafter}
\def\aebnameref#1{\@ifundefined{r@#1}{??}
    {\aeb@exiii\@thirdoffive\csname r@#1\endcsname}}
\def\labelRef#1{\@ifundefined{r@#1}{Doc-Start}
   {\aeb@exiii\@fourthoffive\csname r@#1\endcsname}}
\def\atPage#1{\@ifundefined{r@#1}{1}
    {\aeb@exiii\@secondoffive\csname r@#1\endcsname}}
%    \end{macrocode}
%    \begin{macro}{\mlhyperlink}
%    \begin{macro}{\mlhyperref}
%    \begin{macro}{\mlnameref}
%    \begin{macro}{\mlNameref}
% These four commands mimic the hyperref commands of the same root name.
% The commands \cs{mlhyperlink} and \cs{mlhyperref} take three
% parameters (the first one optional). The optional parameter
% modifies the appearance of the link, the second is the
% target/destination of the link, the third is the text the link is
% wrapped around. In the case of \cs{mlhyperlink} that target is a
% defined by \cs{hypertarget}; for \cs{mlhyperref} the target is a
% latex label.
%
% The commands \cs{mlnameref} and \cs{mlNameref} take two parameters
% (the first is optional). As before, the first modifies the
% appearance of the link, the second is the target, a latex label.
%    \begin{macrocode}
\newcommand\mlhyperlink[3][]{%
    \mlhypertext[#1\A{/S/GoTo/D (#2)}]{#3}}
\newcommand\mlhyperref[3][]{%
    \mlhypertext[#1\A{/S/GoTo/D (\labelRef{#2})}]{#3}}
\newcommand\mlnameref[2][]{\protected@edef\ml@temp{\aebnameref{#2}}%
    \def\ml@tempi{\mlhypertext[#1\A{/S/GoTo/D (\labelRef{#2})}]}%
    \expandafter\ml@tempi\expandafter{\ml@temp}}
%    \end{macrocode}
% We use a work around to a |\relax| problem encountered in the
% |\mlNameRef| command. {\LaTeX} inserts a |relax| at the end of label
% titles, which stops soul. We insert |\let\SOUL@stop\ml@SOUL@stop|,
% this seems to work, no guarantees.
%    \begin{macrocode}
\newcommand\mlNameref[2][]{\let\SOUL@stop\ml@SOUL@stop
     \protected@edef\ml@temp{`\aebnameref{#2}' on page~\atPage{#2}}%
    \def\ml@tempi{\mlhypertext[#1\A{/S/GoTo/D (\labelRef{#2})}]}%
    \expandafter\ml@tempi\expandafter{\ml@temp}}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%    \end{macro}
%    \end{macro}
%    \begin{macro}{\mlhref}
% This command is similar to \cs{href}. This command also takes
% three arguments, one optional. The first is usual optional argument
% that allow one to modify the appearance of the link, the second one
% is the URL that we are linking to, the third is the text that we are
% wrapping this link around.
%
% The next three commands are modifications some low hyperref commands
% found in the \texttt{pdfmark.def} file. Depending on the parsing,
% \cs{href} calls one of these three; we intercept them, and insert
% our own command \cs{mlhypertext} so the link string gets wrapped around
% if needed.
%    \begin{macrocode}
\def\ml@hyper@linkurl#1#2{\hyper@chars
    \let\ef@thislinkcolor\@urlcolor
    \let\CurrentBorderColor\@urlbordercolor
    \mlhypertext[\presets{\mlhref@args}\A{/S/URI/URI(#2)}]{#1}%
    \endgroup
}%
\def\ml@hyper@linkfile#1#2#3{%
    \let\ef@thislinkcolor\@filecolor
    \let\CurrentBorderColor\@filebordercolor
    \mlhypertext[\presets{\mlhref@args}\A{/S/GoToR
       \ifHy@newwindow /NewWindow true \fi
       /F (#2) /D \ifx\\#3\\[0 \@pdfstartview]\else(#3)\fi}]{#1}%
    \endgroup
}
\def\ml@hyper@launch run:#1\\#2#3{%
    \let\ef@thislinkcolor\@filecolor
    \let\CurrentBorderColor\@runbordercolor
    \mlhypertext[\presets{\mlhref@args}\A{/S/Launch
       \ifHy@newwindow /NewWindow true \fi
       /F (#1) \ifx\\#3\\\else /Win << /P (#3) /F (#1) >> \fi}]{#2}%
    \endgroup
}
%    \end{macrocode}
% Below is the code for \cs{mlhref}. We first let the old commands found in \texttt{pdfmark.def}
% equal to the new versions, then we call \cs{href} to do all the parsing. Things
% eventually comes back to the above three commands.
%    \begin{macrocode}
\let\aeb@saved@href\href
\newcommand{\mlhref}[1][]{%
    \begingroup
        \def\mlhref@args{#1}%
        \let\hyper@linkurl\ml@hyper@linkurl
        \let\hyper@linkfile\ml@hyper@linkfile
        \let\@hyper@launch\ml@hyper@launch
        \aeb@saved@href
}
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}{\mlurl}
% The multi-line version of Donald Arseneau's url package. There
% are problems with this one, will continue to work.
%    \begin{macrocode}
%\newcommand{\mlurl}[2][]{\mlhref[#1]{#2}{\relax\Hurl{#2}}}
%    \end{macrocode}
%    \end{macro}
% \section{Macros used by the SOUL Interface}
%    \begin{macrocode}
\ifHy@colorlinks
    \def\ef@colorthislink{\color{\ef@thislinkcolor}}
\else
    \let\ef@colorthislink\relax
\fi
%    \end{macrocode}
% I've inserted \verb|\let\protect\@empty| to make |mlnameref| and |mlNameref| work.
%    \begin{macrocode}
\def\ml@SOUL@stop{\relax}
\def\SOUL@mlhpreamble{\begingroup
    \mlh@preambleCmdInsert\ef@colorthislink\let\protect\@empty}
\def\SOUL@mlheverysyllable{%
    \mlh@setQuadSyllable{\the\SOUL@syllable}%
    \the\SOUL@syllable%
    \SOUL@setkern\SOUL@charkern}%
\def\SOUL@mlheveryspace#1{#1\space\hskip\spaceskip}%
\def\SOUL@mlheveryhyphen{%
    \discretionary{%
           \unkern
            \SOUL@setkern\SOUL@hyphkern
            \SOUL@sethyphenchar
    }{}{}%
}
\def\SOUL@mlheveryexhyphen#1{%
    \mlh@setQuadSyllable{\SOUL@setkern\SOUL@hyphkern#1}%
    \SOUL@setkern\SOUL@hyphkern#1%
    \discretionary{}{}{%
        \SOUL@setkern\SOUL@charkern
    }%
}
\def\mlh@postambleCmd{\relax}
\def\SOUL@mlhpostamble{\mlh@postambleCmd}
\def\SOUL@mlhsetup{\SOUL@setup
    \let\SOUL@preamble\SOUL@mlhpreamble
    \let\SOUL@everysyllable\SOUL@mlheverysyllable
    \let\SOUL@everyspace\SOUL@mlheveryspace
    \let\SOUL@everyhyphen\SOUL@mlheveryhyphen
    \let\SOUL@everyexhyphen\SOUL@mlheveryexhyphen
    \def\SOUL@postamble{\SOUL@mlhpostamble}%
}
\DeclareRobustCommand*\aeb@mlh{\SOUL@mlhsetup\SOUL@}
%    \end{macrocode}
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%  \Finale
\endinput
