[tex-eplain] Hyperlink in citations

geolsoft at mail.ru geolsoft at mail.ru
Fri Jul 22 13:39:25 CEST 2005


I send patches which enable hyperlink support for citations
and bibliography:

  patch3-cite       patch for xeplain.tex (as patched by my
                    original patch named `patch');
  patch4-btxmac     patch for btxmac.tex;
  hlcite.tex        test file.

I hate to add three more macros to btxmac.tex for
controlling appearance of citations and bibliography, as
there already quite many of them (see below for discussion).
Here they are:

  \printcitepreitem{LABEL} is expanded before each item in a
                    list of citations (like [1,2,3]), and
                    takes label for the item;

  \printcitepostitem is expanded after each item in a list
                    of citations;

  \bblitemhook is expanded before each bibliography entry
                    (before \biblabelprint) and takes label
                    for the entry.

To avoid \bblitemhook we could have \@finishbibitem save
the label in, say, \@bibitemlabel, and redefine
\biblabelprint to produce hyperlink destination with this
label.  This is actually what is done now, but less
general.

While I think avoiding \printcitepreitem and
\printcitepostitem is possible by saving the label and by
some canny use of \printcitestart, \printbetweencitations
and \printcitefinish, it would still require significant
rearrangement of \@cite and, what's more, when the user will
want to redefine \printcitestart, \printbetweencitations and
\printcitefinish, they would have to adopt to the tricks.
So I think it is better to stick to \printcitepreitem and
\printcitepostitem.

Another (minor) problem is that, the way they are defined
now to avoid warnings about undefined hyperlink
destinations, \printcitepreitem and \printcitepostitem
themselves cannot be easily used by the user (although they
weren't there before).  I left a limited capability for
extending them by defining \eplainprintcitepreitem and
\eplainprintcitepostitem, so the users could prepend /
append / redefine these two definitions.  The problem is
that these two are not used during the first run, when .bbl
file is not yet present.

-- 
Best regards,
Oleg Katsitadze
-------------- next part --------------
--- eplain2.8.4.patched/xeplain.tex	2005-07-20 13:33:32.000000000 +0300
+++ eplain2.8.4/xeplain.tex	2005-07-22 12:55:28.000000000 +0300
@@ -389,6 +389,42 @@
     \immediate\write\@auxfile{#1}%
   \fi
 }%
+%
+%
+% We want \biblabelprint to define hyperlink destination.  For that,
+% we save the label for the current bibliography entry from within
+% \bblitemhook.
+\def\bblitemhook#1{\gdef\@hlbblitemlabel{#1}}%
+%
+\def\biblabelprint#1{%
+   \noindent
+   \hbox to \biblabelwidth{%
+      \hldest{\bibhldesttype}{\bibhldestopts,raise=\bibhldestraise}{\@hlbblitemlabel}%
+      \biblabelprecontents
+      \biblabelcontents{#1}%
+      \biblabelpostcontents
+   }%
+   \kern\biblabelextraspace
+}%
+% We want each citation item to be hyperlink to bibliography entry.
+% To avoid unnecessary warnings about undefined destinations (e.g.,
+% from pdfTeX), produce the link only when .bbl file (which does the
+% \hldest's) is present.
+\def\eplainprintcitepreitem#1{\hlstart{\citehltype}{\citehlopts}{#1}}%
+\def\eplainprintcitepostitem{\hlend}%
+%
+%
+\def\printcitepreitem#1{%
+  \testfileexistence[\bblfilebasename]{bbl}%
+  \iffileexists
+    \global\let\printcitepreitem\eplainprintcitepreitem
+    \global\let\printcitepostitem\eplainprintcitepostitem
+  \else
+    \global\let\printcitepreitem\gobble
+    \global\let\printcitepostitem\relax
+  \fi
+  \printcitepreitem{#1}%
+}%
 % 
 % 
 % 
@@ -3098,11 +3134,13 @@
 \let\xrdefhldesttype\empty
 \let\lihldesttype\empty
 \let\eqhldesttype\empty % \eqdef and friends
+\let\bibhldesttype\empty % \biblabelprint (BibTeX)
 % Options for destinations.
 \let\definexrefhldestopts\empty
 \let\xrdefhldestopts\empty
 \let\lihldestopts\empty
 \let\eqhldestopts\empty % \eqdef and friends
+\let\bibhldestopts\empty % \biblabelprint (BibTeX)
 % We want to control the option `raise' separately because the other
 % options are usually set once and for all while `raise' may need
 % adjustment per instance (especially with equations).
@@ -3110,17 +3148,20 @@
 \def\xrdefhldestraise{\normalbaselineskip}%
 \def\lihldestraise{\normalbaselineskip}%
 \def\eqhldestraise{1.7\normalbaselineskip}% \eqdef and friends
+\def\bibhldestraise{\normalbaselineskip}% \biblabelprint (BibTeX)
 %
 % Types of links.
 \let\xrefnhltype\empty % \refn and \xrefn
 \let\xrefhltype\empty
 \let\refhltype\empty % \ref and \refs
 \let\eqhltype\empty % \eqref and \eqrefn
+\let\citehltype\empty % \cite (BibTeX)
 % Options for links.
 \let\xrefnhlopts\empty % \refn and \xrefn
 \let\xrefhlopts\empty
 \let\refhlopts\empty % \ref and \refs
 \let\eqhlopts\empty % \eqref and \eqrefn
+\let\citehlopts\empty % \cite (BibTeX)
 %
 % Hyperlink destinations (driver-independent code).
 %
-------------- next part --------------
--- eplain2.8.4.patched/btxmac.tex	1996-03-11 17:42:30.000000000 +0300
+++ eplain2.8.4/btxmac.tex	2005-07-22 12:39:24.000000000 +0300
@@ -486,7 +486,9 @@
       }%
    \fi
    % Now produce the text, whether it was undefined or not.
+   \printcitepreitem{#1}%
    \csname\@citelabel{#1}\endcsname
+   \printcitepostitem
    \@notfirstcitationtrue
 }%
 %
@@ -579,6 +581,7 @@
       }%
       %
       \def\@finishbibitem##1{%
+         \bblitemhook{##1}%
          \biblabelprint{\csname\@citelabel{##1}\endcsname}%
          \@writeaux{\string\@citedef{##1}{\csname\@citelabel{##1}\endcsname}}%
          \ignorespaces
@@ -676,6 +679,12 @@
 %
 \let\bblhook = \empty
 %
+% And here you can add code to be executed before each item (before
+% \biblabelprint is called).  The parameter is citation label for this
+% bibliography entry.
+%
+\let\bblitemhook = \@gobble
+%
 %
 % Here are the four default definitions for formatting the in-text
 % citations.  These are what you redefine (after your \input btxmac but
@@ -685,6 +694,8 @@
 \def\printcitestart{[}%         left bracket
 \def\printcitefinish{]}%        right bracket
 \def\printbetweencitations{, }% comma, space
+\let\printcitepreitem\@gobble % takes label
+\let\printcitepostitem\empty
 \def\printcitenote#1{, #1}%     comma, space, note (if it exists)
 %
 % That scheme is pretty flexible.  For example you could use
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hlcite.tex
Type: text/x-tex
Size: 1424 bytes
Desc: not available
Url : http://tug.org/pipermail/tex-eplain/attachments/20050722/5f357c48/hlcite.bin


More information about the tex-eplain mailing list