[tex-eplain] Patch for \enablehyperlinks, \leavevmode and some improvements

geolsoft at mail.ru geolsoft at mail.ru
Thu Jul 28 15:12:08 CEST 2005


Hello,

This patch covers the following:

  1) \enablehyperlink macro replaces \hldriver as previously
     discussed.  I also moved the code which frees the
     drivers to a place _after_ the call to driver's
     initialization routine, so that now _all_ drivers can
     be freed (no init routine is ever used after setting up
     a driver).

  2) New variable \@selectedhldriver introduced.  It is
     undefined if no driver is selected, and is set to the
     name of the driver when one is selected.  Might turn
     out to be useful.

  3) \leavevmode added at the beginning of \hlstart.

  4) \ignorespaces added at the end of \hlstart and \hldest.

  5) Macro name construction in \hl at checkopt was missing an @,
     so I corrected that (hunk -3283,12 +3284,14).

  6) Several occurrences of the form
       \expandafter\def\expandafter\@saveoptarg\expandafter{\@optionalarg}
     I replaced by equivalent but more efficient
       \let\@saveoptarg\@optionalarg

Order of the patches:

  patch
  patch3-cite
  patch4-btxmac
  patch5-foot
  patch6

Hyperlink support for indexing macros should be coming shortly.

-- 
Best regards,
Oleg Katsitadze
-------------- next part --------------
--- eplain2.8.4.patched/xeplain.tex	2005-07-28 15:20:55.000000000 +0300
+++ eplain2.8.4/xeplain.tex	2005-07-28 15:30:28.000000000 +0300
@@ -1055,10 +1055,10 @@
 \def\li{\@getoptionalarg\@finli}%
 \def\@finli{%
   % Save \@optionalarg in case \interitemskip garble it.
-  \expandafter\def\expandafter\@lioptarg\expandafter{\@optionalarg}%
+  \let\@lioptarg\@optionalarg
   % Write xref definition but do not define hyperlink destination
   % (\printitem will do it).
-  \ifx\@optionalarg\empty \else
+  \ifx\@lioptarg\empty \else
     \begingroup
       \hldestoff
       \expandafter\writeitemxref\expandafter{\@lioptarg}%
@@ -1519,7 +1519,7 @@
   \hlstart{\xrefnhltype}{\xrefnhlopts}{#1}%
   \ifx\@optionalarg\empty \else
     % Save \@optionalarg before it is trashed by \readauxfile.
-    \expandafter\def\expandafter\@xrefnoptarg\expandafter{\@optionalarg}%
+    \let\@xrefnoptarg\@optionalarg
     % Read .aux file -- \@optionalarg may contain cross-references.
     \readauxfile
     % Typeset the \@optionalarg
@@ -1616,7 +1616,7 @@
 %
 \def\@generalref#1#2#3{%
   % Save \@optionalarg before it is trashed by \readauxfile.
-  \expandafter\def\expandafter\@generalrefoptarg\expandafter{\@optionalarg}%
+  \let\@generalrefoptarg\@optionalarg
   \readauxfile
   % Get the class of the label.
   \edef\temp{\getproperty{\xrlabel{#3}}{class}}%
@@ -1852,7 +1852,7 @@
 \def\eqref at start#1{%
   % Save \@optionalarg in case \phantomeqlabel is redefined by the
   % user to something that trashes it.
-  \expandafter\def\expandafter\@eqrefoptarg\expandafter{\@optionalarg}%
+  \let\@eqrefoptarg\@optionalarg
   % Hyperlink (fetch last `phantom' equation label if LABEL is empty).
   \ifempty{#1}%
     \hlstart{\eqhltype}{\eqhlopts}{\phantomeqlabel}%
@@ -3203,8 +3203,8 @@
 % the form `opt=value'; permitted values for TYPE and OPTIONS depend
 % on selected hyperlink driver.
 %
-% \hldest will be \let to \@hldest by \hldriver.  TYPE, OPTIONS and
-% LABEL will be read by \hl at getparam.
+% \hldest will be \let to \@hldest by \enablehyperlinks.  TYPE,
+% OPTIONS and LABEL will be read by \hl at getparam.
 \def\@hldest{%
   \def\hl at suffix{dest}%
   \let\after at hl@getparam\hldest at aftergetparam
@@ -3236,15 +3236,16 @@
 % the form `opt=value'; permitted values of TYPE and OPTIONS depend on
 % selected hyperlink driver.  End the link with \hlend.
 %
-% \hlstart will be \let to \@hlstart by \hldriver.  TYPE, OPTIONS and
-% LABEL will be read by \hl at getparam.
+% \hlstart will be \let to \@hlstart by \enablehyperlinks.  TYPE,
+% OPTIONS and LABEL will be read by \hl at getparam.
 \def\@hlstart{%
+  \leavevmode
   \let\hl at suffix\empty
   \let\after at hl@getparam\hl at driver
   \hl at getparam
 }%
-% \hlend will be \let to \@hlend by \hldriver.  \@hlend will be
-% defined by a driver.
+% \hlend will be \let to \@hlend by \enablehyperlinks.  \@hlend will
+% be defined by a driver.
 %
 % Macros which are used commonly by \hldest and \hlstart to parse and
 % save parameters.  \hl at suffix must be set to `dest' by \hldest and to
@@ -3283,12 +3284,14 @@
     % Execute the commands specific to destination / link
     \after at hl@getparam
   \endgroup
+  % Ignore spaces after \hlstart and \hldest.
+  \ignorespaces
 }%
 % Parse an option.
 \def\hl at checkopt#1=#2,{%
   % For each supported option OPTION, a driver should define
   % \hl[dest]opt at OPTION.
-  \expandafter\ifx\csname hl\hl at suffix opt#1\endcsname \relax
+  \expandafter\ifx\csname hl\hl at suffix opt@#1\endcsname \relax
     \errmessage{Invalid option `#1'}%
   \fi
   % Save the value of the option.
@@ -3303,28 +3306,57 @@
 %
 % Hyperlink drivers.
 %
-% \hldriver{DRIVER} picks up the driver DRIVER, if it is available.
-\def\hldriver#1{%
-  % Check that the driver's initialization routine is available.
-  \expandafter\ifx\csname hldriver@#1\endcsname \relax
-    \errmessage{No hyperlink driver `#1' available}%
+% The code below should go away when eplain starts using ifpdf.sty.
+\newif\ifpdf
+\ifx\pdfoutput\undefined
+\else
+  \ifx\pdfoutput\relax
+  \else
+    \ifnum\pdfoutput<1
+    \else
+      \pdftrue
+    \fi
   \fi
-  % Free memory taken up by unneeded drivers.
-  \edef\temp{#1}%
-  \for\@hldriver:=nolinks,pdftex,dvipdfm\do{%
-    \ifx\@hldriver\temp \else
-      \expandafter\let\csname hldriver@\@hldriver\endcsname\undefined
+\fi
+% End of code that should go away when eplain starts using ifpdf.sty.
+%
+% \enablehyperlinks[DRIVER] will enable hyperlinks by selecting the
+% driver DRIVER.  If DRIVER is omitted, appropriate driver will be
+% detected, if possible; if not, it falls back on `dvipdfm' (currently
+% this means `pdftex' when \ifpdf, and `dvipdfm' otherwise).
+\def\enablehyperlinks{\@getoptionalarg\@finenablehyperlinks}%
+\def\@finenablehyperlinks{%
+  \ifx\@optionalarg\empty
+    % The user did not specify a driver, detect.
+    \ifpdf
+      \def\@selectedhldriver{pdftex}%
+      \message{^^JUsing `pdftex' hyperlink driver.}%
+    \else
+      \def\@selectedhldriver{dvipdfm}%
+      \message{^^JUsing `dvipdfm' hyperlink driver.}%
     \fi
-  }%
+  \else
+    % Check that the requested driver's initialization routine is
+    % available.
+    \expandafter\ifx\csname hldriver@\@optionalarg\endcsname \relax
+      \errmessage{No hyperlink driver `\@optionalarg' available}%
+    \fi
+    \let\@selectedhldriver\@optionalarg
+  \fi
   % Call the driver's initialization routine.
-  \csname hldriver@#1\endcsname
-  % Driver should not be changed.
-  \def\hldriver{\errmessage{Hyperlink driver `#1' already selected}}%
-  % Use these to turn links / destinations on/off (see comments to the
-  % driver `nolinks').
-  \def\hloff{\let\hlstart\gobblethree \let\hlend\relax}%
+  \csname hldriver@\@selectedhldriver\endcsname
+  % Driver should not be changed later.
+  \def\@finenablehyperlinks{\errmessage{Hyperlink driver `\@selectedhldriver'
+                                        already selected}}%
+  % Free memory taken up by the drivers.
+  \let\hldriver at nolinks\undefined
+  \let\hldriver at pdftex \undefined
+  \let\hldriver at dvipdfm\undefined
+  % The user can use these to turn the links / destinations on/off
+  % (see comments to the driver `nolinks').
+  \def\hloff{\def\hlstart####1####2####3{\leavevmode\ignorespaces}\let\hlend\relax}%
   \def\hlon{\let\hlstart\@hlstart \let\hlend\@hlend}%
-  \def\hldestoff{\let\hldest\gobblethree}%
+  \def\hldestoff{\def\hldest####1####2####3{\ignorespaces}}%
   \def\hldeston{\let\hldest\@hldest}%
   % Turn everything on by default.
   \hlon \hldeston
@@ -3380,12 +3412,8 @@
 % Driver `pdftex'.
 %
 \def\hldriver at pdftex{%
+\ifpdf % PDF output is enabled.
   \def\hl at raw@word{raw}%
-  % Check that pdftex is running.
-  \ifx\pdfoutput\undefined
-    \message{\linenumber Warning: hyperlink driver `pdftex' requested
-                         but pdftex does not seem to be running.}%
-  \fi
   %
   % Hyperlink destinations.
   %
@@ -3539,6 +3567,12 @@
   }%
   %
   \let\@hlend\pdfendlink
+%
+\else % PDF output is not enabled.
+  \message{Warning: `pdftex' hyperlink driver: PDF output is
+           not enabled, falling back on `nolinks' driver.}%
+  \hldriver at nolinks
+\fi
 }%
 %
 % Driver `dvipdfm'.
@@ -3729,11 +3763,20 @@
   %
   \def\@hlend{\special{pdf: endann}}%
 }%
-% Make all hyperlink macros no-op by default (cross-referencing macros
-% call them).
+%
+% Cross-reference macros call hyperlink macros, so define them to
+% produce nothing by default.  However, we still want \hldest and
+% \hlstart to produce \leavevmode and/or \ignorespaces, to make
+% cross-reference macros consistent.  Note that this, strictly
+% speaking, makes cross-reference macros incompatible with
+% pre-hyperlink releases of eplain, in cases where paragraph is
+% started by a cross-reference macro.  It is quite unlikely though
+% that any problem will arise.
 \let\hldeston\relax \let\hldestoff\relax
 \let\hlon\relax \let\hloff\relax
-\let\hldest\gobblethree \let\hlstart\gobblethree \let\hlend\relax
+\def\hldest#1#2#3{\ignorespaces}%
+\def\hlstart#1#2#3{\leavevmode\ignorespaces}%
+\let\hlend\relax
 %
 % Internal hyperlink macros.
 %


More information about the tex-eplain mailing list