HyperText Documents with L A TEX 2 ε V4.2d
Michael Mehlich 1999/03/09
Contents
1 Introduction 3
2 Usage 3
3 Macros Provided 4
4 Viewing HyperLATEX 2ε–documents 6
5 Bugs 6
6 Related Work, Acknowledgement 7
7 History 8
8 The Realization 12
8.1 The Package Header . . . 12
8.2 Special Characters . . . 12
8.3 The Basic Anchor/Reference-Entries . . . 12
8.4 Colored Anchors/References. . . 20
8.5 Automatic Generation of Anchor Names . . . 21
8.6 HyperText Cross–Referencing for LATEX 2ε . . . 21
8.7 Other Cross–Referencing Features . . . 23
8.8 Handling Page Numbers . . . 24
8.9 Table of Contents . . . 27
8.10 Bibliography . . . 30
8.11 Equations . . . 31
8.12 Float Captions . . . 31
8.13 Footnotes . . . 32
8.14 Lists . . . 37
8.15 Index and Glossary . . . 37
8.16 Theorems . . . 39
8.17 Additional Patches . . . 40
8.18 Handling Options . . . 40
8.19 Compatibility with Ordinary LATEX. . . 45
9 Supported Packages 51 9.1 AMS-LATEX 2ε . . . 51
9.1.1 The Classes . . . 51
9.1.2 The Packages . . . 54
9.2 Cross References between Documents. . . 57
9.3 Fancy Headings . . . 58
9.4 Long Tables . . . 61
9.5 Right Column Footnotes in Double Column Documents . . . 61
9.6 Thenatbib-Package . . . 62
9.7 The Subequationarray Package . . . 65
9.8 The Theorem Package . . . 66
9.9 The CWEB Document Class . . . 68
10Needed Packages (Part of this Distribution) 73 10.1 Pattern–Like Definition of Macros . . . 73
11Extensions 74
HyperL A TEX 2 ε
March 6, 2010
1 Introduction
Traditional texts only have a linear structure given by its series of characters. But this is not sufficient for any kind of documents one may think of. Thus, recently the number of documents using a more complex graphical structure (called “hyper text” documents) have increased.
This package provides the generation of such documents based on the already given structure of LATEX 2ε-documents without the document writer having to consider new commands.
2 Usage
Just insert \usepackage{hyper}in the preamble of your LATEX2e–document as the last package to be loaded.
If you use the theorem package define the theorems via \newtheorem after inserting the hyper package.
You may also give some options for the package, i.e. instead of the command above you may use\usepackage[<option list>]{hyper}in your preamble.
Currently the following options are known:
• yes,nodetermine whether the hypertext marks are inserted or not (default isyes)
• fixhyperboxmodifies the position of the html-marks in thedvi-file so that dvipscreates the right bounding boxes for the hyper references; it is highly recommended to use this option (though for compatibility reasons with ear- lier versions this is not the default setting); note, that the text of the reference is packed into a horizontal box (\hbox) due to the need of measuring its size
• black,gray,colordetermine the colors anchors and references are printed in (default isblack);
the colors can be changed by \definecolor{refcolor}{rgb}{r,g,b}for references, \definecolor{undefrefcolor}{rgb}{r,g,b} for unresolved references, and\definecolor{anchorcolor}{rgb}{r,g,b}for anchors where
r, g, b stand for the red, green, and blue, respectively, values (between 0.0 and 1.0) of the color (cf.graphicspackage)
• pagenumber,pagetopdetermine whether a page number refers to the page number of the respectively page or to the top of the page
• indexcmds has to be given explicitely whenever an index or glossary file has been created using this package if the file is not regenerated using the commands\makeindexand\makeglossary, respectively.
• backcitepages,backcitesectionsintroduce back references from the bib- liography to the pages and sections, respectively, they have been cited in
• amsart,amsbook,amsdtx,amsldoc,amsproc,article,book,cweb,letter, ltxdoc,ltxguide,ltnews,proc,report,slides determine the document class for which the modifications are loaded (default is the document class given via\documentclassif it can be derived)
• leqnoadds modifications for the document class optionleqno(will be used automagically for known document classes)
• amsmath, amstex, amsthm, doc, fancyheadings, ftnright, longtable, natbib, subeqnarray, theorem, upref add modifications for the corre- sponding package (will be used automagically)
• xr add modifications for the package xr and redefine it’s internal macro
\externaldocumentaddint a new parameter determining the URL–address of the document for the cross references used (will be used automagically)
• harvardadd modifications for the respectively packages that are part of the distribution but provided by other authors
• <other> add a modification file <other>.hyp that has to be provided by yourself
3 Macros Provided
The following macros are defined by the package and may be used:
• \hyperanchor#1#2lets#1being the hypertext anchor for#2(#1may neither be a natural number nor beginning withpage.orfn.)
• \blindhyperanchor#1lets#1being a hypertext anchor (#1may neither be a natural number nor beginning withpage.orfn.)
• \hyperreference#1#2lets#2being a hypertext reference to the anchor#1, (#1may not start with a [)
• \hyperURL#1#2#3#4lets#4being a hypertext reference to an external URL with type#1, domain#2, and document#3, i.e. to the URL#1://#2/#3
• \labeltext#1#2lets#1being the hypertext capable (LATEX 2ε) reference to the text#2and prints#2
• \noref[#1]#2lets #1being a hypertext reference to the anchor defined by the LATEX 2εreference#2without printing the reference (#1is not optional!)
• \ref[#1]#2is the same as LATEX 2ε’s original#1~\ref{#2}except that the hypertext reference is provided from the complete #1~\ref{#2}instead of
\ref{#2}only
• \pageref[#1]#2is the same as\refexcept that we get a reference to the page number
• \refcurrent#1 lets #1 being a hypertext reference to the last numerical anchor that has been generated
• \refnext#1lets#1being a hypertext reference to the next numerical anchor that will be generated
The following macros are redefined when using the corresponding packages:
• forxr:
– \externaldocument(#1)[#2]#3,\externaldocument[#1](#2)#3are equivalent to the original \externaldocument of the xr–package ex- cept for the additional parameter surrounded by () determining the URL–address of the external document (the URL–typefile:is added automagically) (default is#3.dvi)
The following macros are provided when using the option backcitepages or backcitesections(definitions show default value):
• \def\hyperbackcitepage{Cited on page~}is the text preceeding a back reference to a single page number.
• \def\hyperbackcitepages{Cited on pages~} is the text preceeding a back reference to multiple page numbers.
• \def\hyperbackcitesection{Cited in~}is the text preceeding a back ref- erence to a single section reference.
• \def\hyperbackcitesections{Cited in~} is the text preceeding a back reference to multiple section references.
• \def\hyperbackcitenormalseparator{, } is the text between two page numbers or section references (except for the last pair).
• \def\hyperbackcitefinalseparatorpair{ and~}is the text between the page numbers or section references if there are exactly two entries.
• \def\hyperbackcitefinalseparatorlist{, and~}is the text between the last pair page numbers or section references if there are more than two entries.
4 Viewing HyperL
ATEX 2 ε –documents
There are several methods that can be used to view the dvi–documents with html–
marks resulting from using this package.
• For UNIXTM–systems with the graphical user interfaceX there is a modifi- cation ofxdvicalledxhdviavailable at any CTAN-site.
• For systems running under NeXTSTEPTMthere exists a HyperTEX-capable modification ofTeXview, calledHyperTeXview.
• There exists a variant of dvips(called dvihps) translating hyperdvi–files to hyperps–files containing the html–marks when using the parameter -z.
(emtexprovides this feature withdvips).
The resulting files can be viewed using a HyperPS-capable Postscript-viewer, (e.g. a hacked version ofghostview(for UNIXTM) or the actualgsview(for WindowsTM))
• Another way is to use dvihps to get a HyperPS–file ready to be han- dled by the AcrobatTM–distiller available from Adobe or by ghostscript’s pdfwriter–output–device which both can translate hyperps–files to pdf–
files that can be viewed using an AcrobatTM–reader or any otherpdf–reader.
5 Bugs
Currently there are only a few known problems. Unfortunately they cannot be avoided. You have to care about this:
• If you write your bibliographies with the thebibliograpy-environment by hand (not using bibtex) you may get an error message due to a command not matching its definition. This can be avoided by providing an empty line or a\parcommand at the end of each bibliographic entry (with\bibitem) including the last entry before\end{thebibliography}.
• If you include an index or glossary file into the current document you may get a message from LATEX likeUndefined control sequence.. . .\hyperpage.
This is due to you not using\makeindexor\makeglossaryin the preamble.
In this case just add the package optionindexcmdswhen loading the hyper–
package.
• In indexing commands you can’t use ]without surrounding braces. If you do, TEX will parse the command in a wrong way. To get the sorting of the index right you therefore should use\index{A[zzzzB@A{]}B}instead of
\index{A]B}.
• Similarly, a protected|, i.e."|is not handled correctly. Use a similar method as above to circumnavigate this problem.
There is another problem in connection with (a html-capable)dvipsand paper formats different from letter. Apparently the positions for the html-specials are not computed correctly. The package provides a perl-script that allows to modify the positions of these specials. When using e.g. a4paper you have to call perl dvi2pdf.pl -z "-s0,50" -nopdf <normal parameters to dvips>to cre- ate an appropriate ps-file. Note, that the scriptdvi2pdf.plhas to be configured and has only been tested on a WindowsTMsystem.
Other problems are not known so far. But surely there are some (otherwise the history would not be already that long). Thus, if you detect one please report it with the package version and a small example to
Michael Mehlich
6 Related Work, Acknowledgement
Sebastian Rahtz has written another package for adding HyperText–capabilities to LATEX. His packagehyperrefhas been developed in parallel with this one and uses a slightly different realization for getting similar results. Some of the ideas found there have been added to this package, too. Thus, I have to give a special thank to him.
Thanks also to Ulrich Fuchs for further suggestions.
7 History
When By What V
1998/10/29 Michael Mehlich fixed macro name foramsthm 4.2d 1998/10/28 Michael Mehlich corrected problem with wrong refer-
ences produced
4.2c 1997/09/22 Michael Mehlich corrected problem with \uppercase
and \lowercase in internally used names
4.2b
1997/09/15 Michael Mehlich corrected problem with \noalign in eqnarrayenvironment
4.2a 1997/08/28 Michael Mehlich corrected definition of new hyper
anchor name to appear only locally within\labeltext
redefined\labelforamstex.sty added support for package subeqnarray
4.2
1997/08/24 Michael Mehlich reduced problems when adding or re- moving thehyper-package
patched around problem in interaction of optionfixhyperboxwithdvips problem with undefined hyper refer- ences when using cross references pro- vided by the packagexrresolved
4.1
1997/07/14 Michael Mehlich corrected bug when creating cross- references between documents (bug was introduced when introducing res- olution of nested html-marks)
4.0h
1997/05/28 Michael Mehlich ensured hyper references for footnotes being created even if footnote is moved to the next page (but not further) corrected marks introduced by the in- dex environment \theindex in the classesreportandbook
changed mechanism for change flags
4.0g
1997/05/07 Michael Mehlich redirected output for special hyper in- formations to main auxiliary file
4.0f 1997/04/25 Michael Mehlich changed catcodes for reading the pa-
rameters of\hyperURL
4.0e 1997/04/17 Michael Mehlich resolved some problem with thecweb-
package modifications
4.0d 1997/03/25 Michael Mehlich resolved problem with wrong foot-
note references when using package footnpag (this also corrects the for- mer wrong naming of anchors for foot- notes)
4.0c
1997/03/21 Michael Mehlich removed bug in interaction of package 4.0b
When By What V 1997/03/08 Michael Mehlich added color for external URL added
by\hyperURL
4.0a 1997/03/01 Michael Mehlich added check for anchor existing before
introducing reference to it
added check whether the anchors have changed beween two LATEX 2εruns added handling of nested html-marks by unnesting (shit, this conflicts with the option fixhyperbox)
added optionfixhyperbox
changed creation of anchor names for footnotes due to illegal names and duplicated names in the old version improved extension package backcites
added handling of sorted citations for packagenatbib
changed macros for packagenatbib added support for common package fancyheadings (this was needed for handling page references to page numbers when creating pages with empty headers and footers)
modified header and footer modifica- tion for inserting appropriate anchors and references
4.0
1997/02/03 Michael Mehlich allow \makeindex and
\makeglossary to appear after including the package
corrected mishandling ofpagetop changed colors for references and anchors
added documentation about how to change colors for colored references and anchors
3.0c
1997/01/12 Michael Mehlich corrected problem with loop occurring on even pages
3.0b 1996/11/01 Michael Mehlich corrected problem with empty head-
ings causing an overful hbox
bug of having two page anchors on empty pages in case of pagetop re- moved
adapted to current version of natbib 3.0a
When By What V 1996/10/26 Michael Mehlich added code for bibliographic refer-
ences with natbib
added possibility of let pagelinks go to the top of the page
3.0
1996/10/21 Michael Mehlich corrected problem with empty page style
2.8a 1996/01/07 Michael Mehlich adapted to current version of latex 2.8 1995/12/19 Michael Mehlich adapted to current version of the
cweb–package
2.7b 1995/10/22 Michael Mehlich made reference commands robust 2.7a 1995/09/24 Michael Mehlich added support for the Cweb docu-
ment class
2.7 1995/07/13 Michael Mehlich \hyper @next changed to
\fragilerefnext to avoid prob- lems when writing the command into the.toc–file
2.6a
1995/07/06 Michael Mehlich \hyperbackciteoccurred mistakenly in each file
bug fix in redefinition of theindex- environment in doc.hyp
handling of footnotes corrected modified\@xeqncrinstead of\@eqncr adapted redefinition of captions for longtable to current version of longtable
2.6
1995/07/04 Michael Mehlich correction of optional parameter of\\
in eqnarray–environment mistakenly ignored
2.5d
1995/06/14 Michael Mehlich corrected\hyper @oddfoot 2.5c 1995/05/29 Michael Mehlich added support for contribution
harvard.hyp, changed automatical uploading of packages to conditional uploading (tests if the package really exists)
2.5b
1995/05/23 Michael Mehlich changed wrong page numbers for cer- tain document classes
2.5a 1995/05/10 Michael Mehlich added support for backcites 2.5 1995/05/08 Michael Mehlich internal handling of references to
pages simplified bug inxr.hypfixed
anchor on empty pages added
2.4c
1995/05/07 Michael Mehlich let \item accept ] in optional argu- ment
2.4b
When By What V 1995/04/20 Michael Mehlich added new option indexcmds 2.4a 1995/04/20 Michael Mehlich added support for amstex 2.4 1995/04/18 Michael Mehlich corrected bug in index (reported by
Ulrich Fuchs)
2.3a 1995/02/12 Michael Mehlich support for packagexradded
handling of options improved
2.3 1995/02/11 Michael Mehlich definition of\labelcorrected (bug in-
troduced at 1995/01/31)
2.2b 1995/02/02 Michael Mehlich macros foramsthm changed according
to new definition in amslatex
2.2a 1995/02/01 Michael Mehlich support for packageamslatexadded
support for packagelongtableadded 2.2 1995/01/31 Michael Mehlich support for packagetheoremadded
catcodes of|,@, and! for parsing the parameters of\indexand\glossary changed
\@makecaptionmodified
hypertext references ineqnarraycor- rected
redefinition of\labelchanged
2.1
1995/01/30 Michael Mehlich handling of series of page numbers for index/glossary added
\protected @writestopped from in- serting an extra space
2.0b
1995/01/29 Michael Mehlich references from headers to sections for bibliography, index, glossary, and ta- ble of contents added
2.0a
1995/01/26 Michael Mehlich options to be handled are determined automagically now
protected the anchor and reference adding macros instead of "
some internal algorithms changed some macro–names changed
2.0
1995/01/25 Michael Mehlich handling of index and glossary added 1.3 1995/01/24 Michael Mehlich handling of options changed
color support for anchors and refer- ences added
1.2
1995/01/24 Michael Mehlich \noref added
bug in writing wrong page numbers to auxiliary files removed
1.1
1995/01/20 Michael Mehlich protected"for compatibility with the packagegerman.sty
1.0g 1995/01/12 Michael Mehlich first official version 1.0
8 The Realization
8.1 The Package Header
We need a version of LATEX2e dated with June 1, 1995 or newer. Thus, we just demand it.
1h∗hyperi
2\NeedsTeXFormat{LaTeX2e}[1995/12/01]
Now we have to introduce ourself.
3\ProvidesPackage{hyper}[\filedate\space HyperLaTeX2e extension]
8.2 Special Characters
First of all let us reserve some characters which are important and are not pre- served by every other package.
4\bgroup
5 \catcode‘\!00\relax
6 \catcode‘\"12\relax
7 !catcode‘!\12!relax
8 !gdef!hyper@quote{"}
9 !gdef!hyper@backslash{\}
10 !global!edef!hyper@hash{!string#}
11 !global!edef!hyper@tilde{!string~}
12!egroup
For compatibility with other packages this may need to be extended. But for now we suppose this being sufficient.
8.3 The Basic Anchor/Reference-Entries
Let us set the output channel for special hyper informations first.
13\AtBeginDocument{\let\hyper@auxout\@auxout}
We have to define some macros that allow us to insert the hypertext marks for anchors and references into the resulting dvi-file. This can be done by using the
\special–macro.
But before introducing them, we need some auxiliaries that allow us to write the hyper anchors to the auxiliary file and reread them at program start. This way we can check, whether we use a reference to an existing anchor; thus we can avoid introducing invalid references. This mechanism can additionally be used to check whether the hyper anchors may have changed between two LATEX 2εruns.
This is also a good place to recheck whether there have been some undefined or multiply defined hyper anchors or forwarded references used in hyper references.
14\newcount\hyper@changed
15\global\hyper@changed=0
16\newcount\hyper@cnt%careful, this is used as a temporary counter in various places
17\def\hyper@change#1{%set change value (powers of 2 only), in use: 1,2,4,8
18 \hyper@cnt\hyper@changed\relax%
19 \divide\hyper@cnt#1\relax%
20 \ifodd\hyper@cnt\else%
21 \global\advance\hyper@changed#1\relax%
22 \fi%
23}
24\def\newhyper#1#2{%
25 \bgroup%
26 \def\uppercase{<UPPERCASE>}%
27 \def\lowercase{<LOWERCASE>}%
28 \expandafter\ifx\csname hyper@#1\endcsname\relax\else%
29 \hyper@change2\relax%
30 \PackageWarningNoLine{hyper}%
31 {Hyper anchor #1 multiply defined}%
32 \fi%
33 \expandafter\global\expandafter\def\csname hyper@#1\endcsname{#2}%
34 \egroup%
35}
36\def\newhyper@check#1#2{%
37 \def\reserved@a{#2}%
38 \bgroup%
39 \def\uppercase{<UPPERCASE>}%
40 \def\lowercase{<LOWERCASE>}%
41 \expandafter\ifx\csname hyper@#1\endcsname\reserved@a\else%
42 \expandafter\ifx\csname hyper@new@#1\endcsname\reserved@a\else%
43 \global\hyper@change4\relax%
44 \fi%
45 \fi%
46 \egroup%
47}
48\let\hyper@enddocument\enddocument
49\def\hyper@check@end{%
50 \ifodd\hyper@changed%1
51 \PackageWarningNoLine{hyper}{There were undefined hyper references}%
52 \fi%
53 \divide\hyper@changed2\relax%
54 \ifodd\hyper@changed%2
55 \PackageWarningNoLine{hyper}%
56 {There were multiply defined hyper anchors}%
57 \fi%
58 \divide\hyper@changed2\relax%
59 \ifodd\hyper@changed%4
60 \PackageWarningNoLine{hyper}%
61 {Hyper anchor(s) may have changed.\MessageBreak
62 Rerun to get hyper references right}%
63 \fi%
64 \divide\hyper@changed2\relax%
65 \ifodd\hyper@changed%8
66 \PackageWarningNoLine{hyper}%
67 {Footnote hyper reference(s) may have been forwarded\MessageBreak
68 to next page.\MessageBreak
69 Check result to ensure this being correct.\MessageBreak
70 If not rerun to get footnote hyper references right}%
71 \fi%
72}
73\def\enddocument{%
74 \let\hyper@@end\@@end%
75 \def\@@end{\hyper@check@end\hyper@@end}%
76 \let\newhyper\newhyper@check%
77 \hyper@enddocument%
78}
79\def\hyper@to@aux#1{%
80 \bgroup%
81 \def\uppercase{<UPPERCASE>}%
82 \def\lowercase{<LOWERCASE>}%
83 \expandafter\ifx\csname hyper@#1\endcsname\relax%
84 \expandafter\ifx\csname hyper@new@#1\endcsname\relax%
85 \expandafter\global%
86 \expandafter\expandafter\expandafter\def\csname hyper@new@#1\endcsname%
87 {{\@currentlabel}{\thepage}}%
88 \fi%
89 \fi%
90 \@bsphack%
91 \protected@write%
92 \hyper@auxout%
93 {}%
94 {\string\newhyper%
95 {#1}%
96 {{\@currentlabel}{\thepage}}%
97 }%
98 \@esphack%
99 \egroup%
100}
The macros\hyperreference \hyperpagereferenceand insert a html-reference to an internal label except when the first parameter begins with [. Then the parameter must have the form[#1][#2]where#1is an external URL and#2an anchor within this URL. This is used when generating cross references between documents.
The whole stuff is complicated by two problems: We have to avoid nesting of the html-markups in the dvi-file and we have to telldvipsabout the right dimension of the box by modifying the positions of the specials from whichdvipsgets the bounding box for a hyper reference (The latter one is optionally done when passing the corresponding parameter to the package).
101\newbox\hyper@box@text
102\newbox\hyper@box@ref
103\newdimen\hyper@fixdim
104\newif\if@hyper@is@active
105\@hyper@is@activefalse
106\def\hyper@html{html:}
107\bgroup
108 \catcode‘\<12\catcode‘\>12\relax%
109 \catcode‘\:12\catcode‘\=12\catcode‘\/12\relax%
110 \gdef\hyper{%
111 \def\hyper@unnested@special##1##2##3{%
112 \special{\hyper@html##1}##3\special{\hyper@html##2}%
113 }%
114 \def\hyper@unnested@special@anchor@nofix##1##2##3{%
115 \special{\hyper@html##1}\hyper@anchor@color{##3}\special{\hyper@html##2}%
116 }%
117 \def\hyper@unnested@special@reference@nofix##1##2##3{%
118 \special{\hyper@html##1}\hyper@ref@color{##3}\special{\hyper@html##2}%
119 }%
120 \def\hyper@unnested@special##1##2{%
121 \hyper@fixdim\ht\hyper@box@text%
122 \advance\hyper@fixdim\dp\hyper@box@text%
123 \advance\hyper@fixdim-8pt%
124 \setbox\hyper@box@ref=\hbox{%
125 \parindent0pt\leftskip0pt\rightskip0pt%
126 \leftmargin0pt\rightmargin\wd\hyper@box@text\advance\rightmargin0.5pt%
127 \linewidth\rightmargin\textwidth\rightmargin%
128 \noindent\vbox{%
129 \hrule height \hyper@fixdim width 0pt%
130 \special{\hyper@html##1}\hbox to\linewidth{\hfill}%
131 \hrule height -\hyper@fixdim width 0pt%
132 \hbox to\linewidth{\hfill\special{\hyper@html##2}}%
133 \hrule height 0pt width 0pt%
134 }%
135 }%
136 \ht\hyper@box@ref0pt%
137 \dp\hyper@box@ref0pt%
138 \wd\hyper@box@ref0pt%
139 \hyper@fixdim\ht\hyper@box@text%
140 \advance\hyper@fixdim-8pt%
141 \hbox{\raise\hyper@fixdim\copy\hyper@box@ref\copy\hyper@box@text}%
142 \setbox\hyper@box@ref=\hbox{}%
143 }%
144 \def\hyper@unnested@special@anchor@fix##1##2##3{%
145 \setbox\hyper@box@text=\hbox{\hyper@anchor@color{##3}}%
146 \hyper@unnested@special{##1}{##2}%
147 \setbox\hyper@box@text=\hbox{}%
148 }%
149 \def\hyper@unnested@special@reference@fix##1##2##3{%
150 \setbox\hyper@box@text=\hbox{\hyper@ref@color{##3}}%
151 \hyper@unnested@special{##1}{##2}%
152 \setbox\hyper@box@text=\hbox{}%
153 }
154 \let\hyper@unnested@special@reference\hyper@unnested@special@reference@nofix%
155 \let\hyper@unnested@special@anchor\hyper@unnested@special@anchor@nofix%
156 \def\hyper@nested@special##1##2##3##4{%
157 \ifx\hyper@unnested@special@reference\hyper@unnested@special@reference@nofix%
158 \if@hyper@is@active%
159 \expandafter\expandafter\expandafter%
160 \special\expandafter\@firstoftwo\hyper@special@last%
161 {\def\hyper@special@last{{{\hyper@html##4}}{{\hyper@html##2}}}%
162 ##1{##2}{##4}{##3}%
163 }%
164 \expandafter\expandafter\expandafter%
165 \special\expandafter\@secondoftwo\hyper@special@last%
166 \else%
167 \def\hyper@special@last{{{\hyper@html##4}}{{\hyper@html##2}}}%
168 \@hyper@is@activetrue\relax%
169 ##1{##2}{##4}{##3}%
170 \@hyper@is@activefalse\relax%
171 \fi%
172 \else%
173 \if@hyper@is@active%
174 ##1{##2}{##4}{##3}%
175 \else%
176 \@hyper@is@activetrue\relax%
177 ##1{##2}{##4}{##3}%
178 \@hyper@is@activefalse\relax%
179 \fi%
180 \fi%
181 }%
182 \def\hyper@special@anchor{\hyper@nested@special\hyper@unnested@special@anchor}
183 \def\hyper@special@reference{\hyper@nested@special\hyper@unnested@special@reference}
184 \def\f@hyper@ref@ext[##1][##2][##3]\end@hyper@ref##4{%
185 \ifvmode\leavevmode\fi%
186 \hyper@special@reference%
187 {<a href=\hyper@quote##1##2\hyper@hash##3\hyper@quote>}%
188 {##4}%
189 {</a>}%
190 }%
191 \def\hyper@check@fn##1.##2.##3.##4\hyper@check@fn{%
192 \def\hyper@tmpa{fn}%mark for link to footnote
193 \def\hyper@tmpb{##1}%
194 \ifx\hyper@tmpa\hyper@tmpb{%
195 \ifx?##3\relax%
196 \global\let\hyper@forwarded@fn\@empty%
197 \else%
198 \hyper@cnt##3\relax% fetch page
199 \advance\hyper@cnt1\relax% advance page by one
200 \global\edef\hyper@forwarded@fn{fn.##2.\the\hyper@cnt}%create new link
201 \fi%
202 }%
203 \else%
204 \global\let\hyper@forwarded@fn\@empty%
205 \fi%
206 }%
207 \let\hyper@thepage\thepage%
208 \def\f@hyper@ref@int##1\end@hyper@ref##2{%
209 \ifvmode\leavevmode\fi%
210 \expandafter\ifx\csname hyper@##1\endcsname\relax%
211 \expandafter\ifx\csname hyper@new@##1\endcsname\relax%
212 \hyper@check@fn##1...\hyper@check@fn%
213 \ifx\hyper@forwarded@fn\@empty%
214 \PackageWarning{hyper}%
215 {Hyper reference ‘##1’ for ‘##2’ on page \hyper@thepage\space undefined}%
216 \hyper@change1\relax%
217 \hyper@undef@color{##2}%
218 \else%
219 \expandafter\ifx\csname hyper@\hyper@forwarded@fn\endcsname\relax%
220 \expandafter\ifx\csname hyper@new@\hyper@forwarded@fn\endcsname\relax%
221 \PackageWarning{hyper}%
222 {Hyper reference ‘##1’ for ‘##2’ %
223 on page \hyper@thepage\space undefined}%
224 \hyper@change1\relax%
225 \hyper@undef@color{##2}%
226 \else%
227 \hyper@change8\relax%
228 \PackageWarning{hyper}%
229 {Hyper reference ‘##1’ for ‘##2’ on page \hyper@thepage\space%
230 forwarded to ‘\hyper@forwarded@fn’}%
231 \hyper@special@reference%
232 {<a href=\hyper@quote\hyper@hash\hyper@forwarded@fn\hyper@quote>}%
233 {##2}%
234 {</a>}%
235 \fi%
236 \else%
237 \hyper@change8\relax%
238 \PackageWarning{hyper}%
239 {Hyper reference ‘##1’ for ‘##2’ on page \hyper@thepage\space%
240 forwarded to ‘\hyper@forwarded@fn’}%
241 \hyper@special@reference%
242 {<a href=\hyper@quote\hyper@hash\hyper@forwarded@fn\hyper@quote>}%
243 {##2}%
244 {</a>}%
245 \fi%
246 \fi%
247 \else%
248 \hyper@special@reference%
249 {<a href=\hyper@quote\hyper@hash##1\hyper@quote>}%
250 {##2}%
251 {</a>}%
252 \fi%
253 \else%
254 \hyper@special@reference%
255 {<a href=\hyper@quote\hyper@hash##1\hyper@quote>}%
256 {##2}%
257 {</a>}%
258 \fi%
259 }%
260 \def\f@hyper@ref{%
261 \@ifnextchar[{\f@hyper@ref@ext[]}{\f@hyper@ref@int}%
262 }%
263 \def\fragilehyperreference##1{%
264 \expandafter\expandafter\expandafter\f@hyper@ref##1\end@hyper@ref%
265 }%
266 \def\f@hyper@page@ref{%
267 \@ifnextchar[{\f@hyper@ref@page@ext[page.]}{\f@hyper@ref@int page.}%
268 }%
269 \def\fragilehyperpagereference##1{%
270 \expandafter\expandafter\expandafter%
271 \f@hyper@page@ref##1\end@hyper@ref%
272 }%
273 \def\fragilehyperanchor##1##2{%
274 \ifvmode\leavevmode\fi%
275 \hyper@special@anchor%
276 {<a name=\hyper@quote##1\hyper@quote>}%
277 {\hyper@to@aux{##1}%
278 ##2%
279 }%
280 {</a>}%
281 }%
282 \def\fragileblindhyperanchor##1{%
283 \hyper@special@anchor%
284 {<a name=\hyper@quote##1\hyper@quote>}%
285 {\hyper@to@aux{##1}}%
286 {</a>}%
287 }%
288 \def\fragilehyperURL##1##2##3##4{%
289 \ifvmode\leavevmode\fi%
290 \def\hyper@tmp{##4}%
291 \def\hyper@tmpa{##1}%
292 \def\hyper@tmpb{##2}%
293 \def\hyper@tmpc{##3}%
294 \ifx\hyper@tmp\@empty%
295 %
296 \else\ifx\hyper@tmpa\@empty%
297 \ifx\hyper@tmpb\@empty%
298 \ifx\hyper@tmpc\@empty%
299 {##4}%
300 \else%
301 \hyper@special@reference%
302 {<a href=\hyper@quote##3\hyper@quote>}%
303 {##4}%
304 {</a>}%
305 \fi%
306 \else\ifx\hyper@tmpc\@empty%
307 \hyper@special@reference%
308 {<a href=\hyper@quote//##2/\hyper@quote>}%
309 {##4}%
310 {</a>}%
311 \else%
312 \hyper@special@reference%
313 {<a href=\hyper@quote//##2/##3\hyper@quote>}%
314 {##4}%
315 {</a>}%
316 \fi\fi%
317 \else\ifx\hyper@tmpb\@empty%
318 \ifx\hyper@tmpc\@empty%
319 {##4}%
320 \else%
321 \hyper@special@reference%
322 {<a href=\hyper@quote##1:##3\hyper@quote>}%
323 {##4}%
324 {</a>}%
325 \fi%
326 \else\ifx\hyper@tmpc\@empty%
327 \hyper@special@reference%
328 {<a href=\hyper@quote##1://##2/\hyper@quote>}%
329 {##4}%
330 {</a>}%
331 \else%
332 \hyper@special@reference%
333 {<a href=\hyper@quote##1://##2/##3\hyper@quote>}%
334 {##4}%
335 {</a>}%
336 \fi\fi\fi\fi%
337 }%
338 }
339\egroup
340\hyper
Sometimes we need this package without being allowed to insert the hypertext marks into the dvi–file. Note, thate\hyper@fix is defined for the sole purpose of having the same TEX-output behaviour regardless whether we create or do not create hypertext markups.
341\def\nohyper{%
342 \def\hyper@fix##1{%
343 \ifx\hyper@unnested@special@reference\hyper@unnested@special@reference@nofix%
344 ##1%
345 \else%
346 \hbox{##1}%
347 \fi%
348 }
349 \def\fragilehyperreference##1##2{%
350 \ifvmode\leavevmode\fi\hyper@fix{\hyper@ref@color{##2}}%
351 }%
352 \def\fragilehyperpagereference##1##2{%
353 \ifvmode\leavevmode\fi\hyper@fix{\hyper@ref@color{##2}}%
354 }%
355 \def\fragilehyperanchor##1##2{%
356 \ifvmode\leavevmode\fi\hyper@anchor@color{##2}%
357 }%
358 \def\fragileblindhyperanchor##1{}%
359 \def\fragilehyperURL##1##2##3##4{%
360 \ifvmode\leavevmode\fi\hyper@fix{\hyper@ref@color{##4}}%
361 }%
362}
Now let’s protect the fragile commands.
363\def\hyperreference{\protect\fragilehyperreference}
364\def\hyperpagereference{\protect\fragilehyperpagereference}
365\def\hyperanchor{\protect\fragilehyperanchor}
366\def\blindhyperanchor{\protect\fragileblindhyperanchor}
367\def\fragileChyperURL{%
368 \bgroup%
369 \catcode‘\<12\catcode‘\>12\catcode‘\"12\relax%
370 \catcode‘\:12\catcode‘\=12\catcode‘\/12\relax%
371 \catcode‘\#12\catcode‘\~12\relax%\catcode‘\%12\relax%
372 \finish@hyperURL%
373}
374\def\finish@hyperURL#1#2#3#4{%
375 \fragilehyperURL{#1}{#2}{#3}{#4}%
376 \egroup%
377}
378\def\hyperURL{\protect\fragileChyperURL}
8.4 Colored Anchors/References
Above we have used three macros\hyper@ref@color,\hyper@undef@color, and
\hyper@anchor@colorwith which we can modify the text that is printed to the document. As their name indicates we want to use them to color the anchors resp.
references. Hence we should define some variants of these macros.
The first variant prints the text in different colors.
379\def\hyper@color{%
380 \definecolor{refcolor}{rgb}{0,0,1}%
381 \definecolor{undefrefcolor}{rgb}{1,0,0}%
382 \definecolor{anchorcolor}{rgb}{0,0.75,0.75}%
383 \def\hyper@ref@color##1{\textcolor{refcolor}{##1}}%
384 \def\hyper@undef@color##1{\textcolor{undefrefcolor}{##1}}%
385 \def\hyper@anchor@color##1{\textcolor{anchorcolor}{##1}}%
386}
If we do not have colors we may use gray text instead.
387\def\hyper@gray{%
388 \definecolor{refcolor}{gray}{0.75}%
389 \definecolor{undefrefcolor}{gray}{0.25}%
390 \definecolor{anchorcolor}{gray}{0.5}%
391 \def\hyper@ref@color##1{\textcolor{refcolor}{##1}}%
392 \def\hyper@undef@color##1{\textcolor{undefrefcolor}{##1}}%
393 \def\hyper@anchor@color##1{\textcolor{anchorcolor}{##1}}%
394}
In ready to print documents we should not use these options but print the text in ordinary black. This is also the default definition.
395\def\hyper@black{%
396 \def\hyper@ref@color##1{##1}%
397 \def\hyper@undef@color##1{##1}%
398 \def\hyper@anchor@color##1{##1}%
399}
400\hyper@black
8.5 Automatic Generation of Anchor Names
As we want to insert hypertext marks automagically we need a service that pro- vides new names for anchors. The simplest solution is to let the name be a natural number.
Thus we need an initialization for providing them.
401\newcount\hypercount
402\hypercount=0\relax
403\def\@currenthyper{}
Now we can compute the next anchor from the last one generated.
404\def\hyper@setcurrent{%
405 \global\advance\hypercount1\relax%
406 \edef\@currenthyper{\the\hypercount}%
407}%
408\def\hyper@settype#1{%
409\edef\@currenthypertype{#1}%
410}%
The automatic generation of anchor names leads to a little problem. We have to ensure that\@currenthyperis expanded at an appropriate time. Thus we define a macro that allow us to get an expanded hypertext reference that follows a not yet expanded token list.
411\def\hyper@ref@toggle#1#2#3{#3[\hyperreference{#1}{#2}]}
412\def\ref@by@expanded@hyper#1\end@hyper{{#1}}
413\def\callwithexpandedhyperref#1#2{%
414 \expandafter\expandafter\expandafter\hyper@ref@toggle%
415 \expandafter\ref@by@expanded@hyper\@currenthyper\end@hyper%
416 {#2}{#1}%
417}
8.6 HyperText Cross–Referencing for L
ATEX 2 ε
For a replacement of LATEX 2ε’s cross–referencing features we need to redefine the commands\labeland\ref.
Let us first define a label command for writing the current hypertext reference to the.aux–file. It must print four components of a label: the hypertext–type, the hypertext–anchor, the LATEX 2ε–anchor, and the LATEX 2ε–page. This is due to the fact that we need to know not only the stuff we reference to but also the internal name of the anchor.
418\def\hyperlabel#1{\@bsphack
419 \protected@write\hyper@auxout{}%
420 {\string\newlabel{#1}%
421 {{\@currenthypertype}{\@currenthyper}{\@currentlabel}{\thepage}}}%
422 \@esphack}
Now we need some auxiliary macros to be able to select each of the three parts of the second argument of\newlabelthat has been written to the.aux–file. Note, that the third component may contain informations about the URL of an external document (for cross referencing between documents) that has to be stripped of a page number before printing it.
423\def\hyper@secondoffour#1#2#3#4{#2}
424\def\hyper@thirdoffour#1#2#3#4{#3}
425\def\hyper@forthoffour#1#2#3#4{#4}
426\def\hyper@snd@forthoffour[#1][#2]\end@hyper{#2}
427\def\hyper@this@forthoffour#1\end@hyper{#1}
428\def\hyper@test@forthoffour{%
429 \@ifnextchar[{\hyper@snd@forthoffour}{\hyper@this@forthoffour}%
430}
431\def\hyper@page@forthoffour#1#2#3#4{%
432 \expandafter\hyper@test@forthoffour#4\end@hyper%
433}
When setting a reference to an anchor we also have to add the corresponding hypertext link into the dvi-file.
434\let\hyper@thepage\thepage
435\def\hyper@setref#1#2#3#4{%
436 \ifx#1\relax%
437 \protect\G@refundefinedtrue%
438 #4\nfss@text{\reset@font\bfseries ??}%
439 \@latex@warning{Reference ‘#3’ on page \hyper@thepage \space undefined}%
440 \else%
441 \edef\hyper@tmp{\expandafter\hyper@secondoffour#1}%
442 \ifx\hyper@tmp\@empty%
443 \ifx#2\hyper@secondoffour%
444 #4\null%
445 \else\ifx#2\hyper@thirdoffour%
446 #4\expandafter#2#1\null%
447 \else%
448 #4\expandafter#2#1\null%
449 \fi\fi%
450 \else%
451 \ifx#2\hyper@secondoffour%
452 \hyperreference{\expandafter\hyper@secondoffour#1}{#4}\null%
453 \else\ifx#2\hyper@thirdoffour%
454 \hyperreference%
455 {\expandafter\hyper@secondoffour#1}%
456 {#4\expandafter#2#1\null}\null%
457 \else%
458 \hyperpagereference%
459 {\expandafter\hyper@forthoffour#1}%
460 {#4\expandafter#2#1\null}\null%
461 \fi\fi%
462 \fi%
463 \fi%
464}
Proceeding from this we can define three macros\hypernoref,\hyperref, and
\hyperpagerefthat correspond to the same LATEX 2ε–macros where the hyper does not occur. But we want to do a little bit more. Thus an additional optional argument may be given to these macros to allow the user to reference from a whole text and not only from the number to the anchor.
465\def\@@hypernoref[#1]#2{%
466 \expandafter\hyper@setref\csname r@#2\endcsname%
467 \hyper@secondoffour{#2}{#1}%
468}
469\def\@hypernoref[#1]{\@@hypernoref[#1]}
470\def\hypernoref{\@ifnextchar[{\@hypernoref}{\@@hypernoref[]}}
471\def\@@hyperref[#1]#2{%
472 \expandafter\hyper@setref\csname r@#2\endcsname%
473 \hyper@thirdoffour{#2}{#1}%
474}
475\def\@hyperref[#1]{\@@hyperref[#1~]}
476\def\hyperref{\@ifnextchar[{\@hyperref}{\@@hyperref[]}}
477\def\@@hyperpageref[#1]#2{%
478 \expandafter\hyper@setref\csname r@#2\endcsname%
479 \hyper@page@forthoffour{#2}{#1}%
480}
481\def\@hyperpageref[#1]{\@@hyperpageref[#1~]}
482\def\hyperpageref{\@ifnextchar[{\@hyperpageref}{\@@hyperpageref[]}}
Now let’s patch LATEX 2ε’s ref/label-system:
483\let\label\hyperlabel
484\def\noref{\protect\hypernoref}
485\def\ref{\protect\hyperref}
486\def\pageref{\protect\hyperpageref}
Up to now we only can reference to anchors but haven’t yet defined some. This will be done in many of the following subsections.
8.7 Other Cross–Referencing Features
Though LATEX 2ε has a very good reference mechanism this is not enough for hypertext documents. The user should be able to add an anchor to a text of his own choice.
487\def\labeltext#1#2{%
488 \bgroup%
489 \hyper@setcurrent%
490 \hyper@settype{text}%
491 \def\@currentlabel{#2}%
492 \label{#1}%
493 \hyperanchor{\@currenthyper}{#2}%
494 \egroup%
495}
But that is not enough. Some of the macros of this package define anchors which cannot be caught by a\label command. But then it is the current or the next anchor generated. The following macros will allow us to reference to them:
496\def\refcurrent#1{\hyperreference{\@currenthyper}{#1}}
497\def\fragilerefnext#1#2{\bgroup%
498 \hypercount=#1\relax\advance\hypercount1\relax%
499 \hyperreference{\the\hypercount}{#2}%
500\egroup}
501\def\refnext#1{\protect\fragilerefnext{\the\hypercount}{#1}}
This is especially usefull for inserting links from the table of contents to an un- numbered section like e.g. the references of a document.
But wait, there is more. LATEX 2εnot only uses\refand\labelfor it’s referencing mechanism but also \refstepcounter to determine to what the next \label should reference. This has to be reflected for the hypertext stuff.
502\let\hyper@refstepcounter\refstepcounter
503\def\refstepcounter{\hyper@setcurrent\hyper@settype{counter}\hyper@refstepcounter}
As we will patch some latex internals below we also need a macro that allow us to forget the next\refstepcounter.
504\def\ignore@next@refstepcounter{%
505 \def\refstepcounter##1{%
506 \def\refstepcounter{\hyper@setcurrent\hyper@settype{counter}\hyper@refstepcounter}%
507 }%
508}
8.8 Handling Page Numbers
We want to refer from the pages in the table of contents to the corresponding page. Thus we have to recall the necessary information when printing the table.
509\let\hyper@contentsline\contentsline
510\def\contentsline#1#2#3{%
511 \hyper@contentsline{#1}{#2}{\hyperpagereference{#3}{#3}}%
512}
The same is valid for indices and glossaries. But they are more problematic. Hence we will handle them in a subsection of its own.
So far the result is a couple of references from page numbers to pages. But we haven’t defined the anchors they refer to.
To resolve this we have to modify headers and footers of a page. This can be done for an arbitrary page style when we change (misuse!) \@begindvi.
Let’s provide to different styles for this purpose, one allowing jumps to the page number, and one allowing jumps to the top of the page. In the latter case we let the page numbers in the headers and footers refer to the top of the page.
513\let\hyper@thepage\thepage
514\def\hyper@anchorpage{%
515 \fragilehyperanchor{page.\hyper@thepage}{\hyper@thepage}%
516}
517\def\hyper@referencepage{%
518 \fragilehyperreference{page.\hyper@thepage}{\hyper@thepage}%
519}
520\def\hyper@empty{\@empty}
521\def\hyper@evenhead{\@evenhead}
522\def\hyper@oddhead{\@oddhead}
523\def\hyper@evenfoot{\@evenfoot}
524\def\hyper@oddfoot{\@oddfoot}
525\def\hyper@modifyheadfoot@pagenumber{%
526 \let\hyper@thehead\@thehead%
527 \ifx\hyper@thehead\hyper@oddhead\let\hyper@thehead\@oddhead\fi%
528 \ifx\hyper@thehead\hyper@evenhead\let\hyper@thehead\@evenhead\fi%
529 \let\hyper@thefoot\@thefoot%
530 \ifx\hyper@thefoot\hyper@oddfoot\let\hyper@thefoot\@oddfoot\fi%
531 \ifx\hyper@thefoot\hyper@evenfoot\let\hyper@thefoot\@evenfoot\fi%
532 \def\@thehead{%
533 \ifnum\ifnum\ifx\hyper@thehead\@empty1\else0\fi%
534 \ifx\hyper@thehead\hyper@empty1\else0\fi%
535 >0 0\else1\fi%
536 \ifnum\ifx\hyper@thefoot\@empty1\else0\fi%
537 \ifx\hyper@thefoot\hyper@empty1\else0\fi%
538 >0 0\else1\fi%
539 >0\relax%
540 \else%
541 \blindhyperanchor{page.\thepage}%
542 \fi%
543 \let\hyper@thepage\thepage%
544 \let\thepage\hyper@anchorpage%
545 \ifx\hyper@thehead\@empty%
546 \hfil%
547 \else\ifx\hyper@thehead\hyper@empty%
548 \hfil%
549 \else%
550 \hyper@thehead%
551 \fi\fi%
552 }%
553 \def\@thefoot{%
554 \let\hyper@thepage\thepage%
555 \let\thepage\hyper@anchorpage%
556 \ifx\hyper@thefoot\@empty%
557 \hfil%
558 \else\ifx\hyper@thefoot\hyper@empty%
559 \hfil%
560 \else%
561 \hyper@thefoot%
562 \fi\fi%
563 }%
564}
565\def\hyper@modifyheadfoot@pagetop{%
566 \let\hyper@thehead\@thehead%
567 \ifx\hyper@thehead\hyper@oddhead\let\hyper@thehead\@oddhead\fi%
568 \ifx\hyper@thehead\hyper@evenhead\let\hyper@thehead\@evenhead\fi%
569 \let\hyper@thefoot\@thefoot%
570 \ifx\hyper@thefoot\hyper@oddfoot\let\hyper@thefoot\@oddfoot\fi%
571 \ifx\hyper@thefoot\hyper@evenfoot\let\hyper@thefoot\@evenfoot\fi%
572 \def\@thehead{%
573 \blindhyperanchor{page.\thepage}%
574 \let\hyper@thepage\thepage%
575 \let\thepage\hyper@referencepage%
576 \ifx\hyper@thehead\@empty%
577 \hfil%
578 \else\ifx\hyper@thehead\hyper@empty%
579 \hfil%
580 \else%
581 \hyper@thehead%
582 \fi\fi%
583 }%
584 \def\@thefoot{%
585 \let\hyper@thepage\thepage%
586 \let\thepage\hyper@referencepage%
587 \ifx\hyper@thefoot\@empty%
588 \hfil%
589 \else\ifx\hyper@thefoot\hyper@empty%
590 \hfil%
591 \else%
592 \hyper@thefoot%
593 \fi\fi%
594 }%
595}
596\let\hyper@begindvi\@begindvi
597\def\@begindvi{%
598 \hyper@begindvi%
599 \hyper@modifyheadfoot%
600 \global\let\@begindvi\hyper@modifyheadfoot%
601}
Hopefully we do not use a page number twice in headers or footers if we want to jump to the pagenumber.
We use pagenumbers as the default position for page anchors.
602\let\hyper@modifyheadfoot\hyper@modifyheadfoot@pagenumber
8.9 Table of Contents
In the subsection “Handling of Pages” we already have inserted references from the page number to the corresponding page. Now we want to add further references from the title of an entry in the table of contents to the corresponding text within the document.
To do that we have to modify the corresponding sectioning commands.
603\let\hyper@sect\@sect
604\def\@sect#1#2#3#4#5#6[#7]#8{%
605 \ifnum #2>\c@secnumdepth%
606 \hyper@setcurrent%
607 \else%
608 \refstepcounter{#1}%
609 \ignore@next@refstepcounter%
610 \fi%
611 \hyper@settype{#1}%
612 \global\let\@currenthyper\@currenthyper%
613 \global\let\@currenthypertype\@currenthypertype%
614 \callwithexpandedhyperref%
615 {\hyper@sect{#1}{#2}{#3}{#4}{#5}{#6}}%
616 {#7}%
617 {\hyperanchor{\@currenthyper}{#8}}%
618}
619\let\hyper@ssect\@ssect
620\def\@ssect#1#2#3#4#5{%
621 \hyper@setcurrent%
622 \hyper@settype{#1}%
623 \global\let\@currenthyper\@currenthyper%
624 \global\let\@currenthypertype\@currenthypertype%
625 \hyper@ssect{#1}{#2}{#3}{#4}{\hyperanchor{\@currenthyper}{#5}}%
626}
627h/hyperi
The classesbookandreportadditionally define a\chaptercommand. Unfortu- nately they do it in a different way. But the differences are fairly small. Thus we will use nearly the same definition.
628h∗book,reporti
629\let\hyper@chapter\@chapter
630\let\hyper@schapter\@schapter
631\def\@chapter[#1]#2{%
632 \ifnum\c@secnumdepth>\m@ne%
633h/book,reporti
634h∗booki
635 \if@mainmatter%
636h/booki
637h∗book,reporti
638 \refstepcounter{chapter}%
639 \ignore@next@refstepcounter%
640h/book,reporti
641h∗booki
642 \else%
643 \hyper@setcurrent%
644 \fi%
645h/booki
646h∗book,reporti
647 \else%
648 \hyper@setcurrent%
649 \fi%
650 \hyper@settype{chapter}%
651 \global\let\@currenthyper\@currenthyper%
652 \global\let\@currenthypertype\@currenthypertype%
653 \callwithexpandedhyperref%
654 {\hyper@chapter}%
655 {#1}%
656 {\hyperanchor{\@currenthyper}{#2}}%
657}
658\def\@schapter#1{%
659 \hyper@setcurrent%
660 \hyper@settype{chapter}%
661 \global\let\@currenthyper\@currenthyper%
662 \global\let\@currenthypertype\@currenthypertype%
663 \hyper@schapter{\hyperanchor{\@currenthyper}{#1}}%
664}
However, this is not sufficient. The classesbookandreportuse a different mech- anism for the index heading not using the macro\chapter*. So we have to fix this.
665\let\hyper@theindex\theindex
666\def\theindex{%
667 \bgroup%
668 \let\hyper@makeschapterhead\@makeschapterhead%
669 \def\@makeschapterhead##1{%
670 \hyper@setcurrent%
671 \hyper@settype{chapter}%
672 \global\let\@currenthyper\@currenthyper%
673 \global\let\@currenthypertype\@currenthypertype%
674 \hyper@makeschapterhead{\hyperanchor{\@currenthyper}{##1}}%
675 }
676 \hyper@theindex%
677 \egroup%
678 \let\item\@idxitem%
679}
680h/book,reporti
There is also a\part–macro defined in the classesarticle,book,ltnews,ltxdoc, ltxguide,proc, andreport. Unfortunately there are two different definitions we have to modify. But they differ only in a constant in a conditional expression.
Thus we can use a nearly common definition.
681h∗article,book,ltnews,ltxdoc,ltxguide,proc,reporti
682\let\hyper@part\@part
683\def\@part[#1]#2{%
684 \ifnum\c@secnumdepth>%
685h/article,book,ltnews,ltxdoc,ltxguide,proc,reporti
686h∗article,ltnews,ltxdoc,ltxguide,proci
687-1\relax%
688h/article,ltnews,ltxdoc,ltxguide,proci
689h∗book,reporti
690-2\relax%
691h/book,reporti
692h∗article,book,ltnews,ltxdoc,ltxguide,proc,reporti
693 \refstepcounter{part}%
694 \ignore@next@refstepcounter%
695 \else%
696 \hyper@setcurrent%
697 \fi%
698 \hyper@settype{part}%
699 \global\let\@currenthyper\@currenthyper%
700 \global\let\@currenthypertype\@currenthypertype%
701 \callwithexpandedhyperref%
702 {\hyper@part}%
703 {#1}%
704 {\hyperanchor{\@currenthyper}{#2}}%
705}
706\let\hyper@spart\@spart
707\def\@spart#1{%
708 \hyper@setcurrent%
709 \hyper@settype{part}%
710 \global\let\@currenthyper\@currenthyper%
711 \global\let\@currenthypertype\@currenthypertype%
712 \hyper@spart{\hyperanchor{\@currenthyper}{#1}}%
713}
714h/article,book,ltnews,ltxdoc,ltxguide,proc,reporti
Now we do not only get references from the table of contents to the corresponding sections but also from the headers and footers to them. There is only one exception these references are not inserted: If we used the *–ed variants of the sectioning commands the marks are not inserted in the headers.
For bibliography, glossary, index, and table of contents this can be changed by modifying\@mkboth.
715h∗article,book,ltnews,ltxdoc,ltxguide,proc,reporti
716\def\hyper@mkboth@do[#1][#2]{%
717 \markboth{#1}{#2}%
718}
719\def\hyper@mkboth#1#2{%
720 \callwithexpandedhyperref%
721 {\callwithexpandedhyperref{\hyper@mkboth@do}{#1}}%
722 {#2}%
723}
As marks are only inserted when using the pagestyle “headings”, the corresponding
macro has to be modified to get the desired result.
724\let\hyper@ps@headings\ps@headings
725\def\ps@headings{%
726 \hyper@ps@headings%
727 \let\@mkboth\hyper@mkboth%
728}
729h/article,book,ltnews,ltxdoc,ltxguide,proc,reporti Last but not least set the new page style.
730h∗book,reporti
731\pagestyle{headings}
732h/book,reporti
Unfortunately, the packagedoc.stymodifies thetheindexenvironment in a way that the above changes do not work correctly with it. Hence, we have to modify this environment to resolve this.
733h∗doci
734\g@addto@macro\index@prologue{%
735 \def\markboth#1#2{%
736 \@mkboth{\refcurrent{#1}}{\refcurrent{#2}}%
737 }%
738}
739h/doci
8.10 Bibliography
We want to reference from citation points within the text, given by\cite, to the corresponding entry in the bibliography. To realize this we only have to modify the\bibitem–macro.
740h∗hyperi
741\def\@lbibitem[#1]#2{%
742 \hyper@setcurrent%
743 \hyper@settype{citation}%
744 \item[\@biblabel{\hyperanchor{\@currenthyper}{#1}}\hfill]%
745 \if@filesw%
746 {\let\protect\@unexpandable@protect%
747 \immediate%
748 \write\@auxout{%
749 \string\bibcite{#2}{\hyperreference{\@currenthyper}{#1}}%
750 }%
751 }%
752 \fi%
753 \ignorespaces%
754}
755\def\@bibitem{%
756 \stepcounter{\@listctr}%
757 \hyper@settype{citation}%
758 \@lbibitem[\the\value{\@listctr}]%
759}
8.11 Equations
The goal is to reference to the equation number in equations and arrays of equa- tions. This is really simple to do.
760\def\@eqnnum{%
761 \hyperanchor{\@currenthyper}{\normalfont\normalcolor(\theequation)}%
762}
763\let\hyper@eqnarray\eqnarray
764\def\eqnarray{%
765 \hyper@setcurrent%
766 \def\@currenthyper{\the\hypercount}%
767 \hyper@settype{equation}%
768 \hyper@eqnarray%
769}
770\let\hyper@xeqncr\@xeqncr
771\def\@xeqncr[#1]{%
772 \hyper@xeqncr[#1]%
773 \noalign{\hyper@setcurrent\hyper@settype{equation}}%
774}
775h/hyperi
There is a document class optionleqnothat has to be redefined for us.
776h∗leqnoi
777\def\@eqnnum{%
778 \hbox to .01\p@{}%
779 \rlap{\reset@font\rmfamily%
780 \hskip -\displaywidth%
781 \hyperanchor{\@currenthyper}{\reset@font\rmfamily (\theequation)}%
782 }%
783}
784h/leqnoi
8.12 Float Captions
What do you think we want to do here? Simply using \caption to define an anchor that may be used to refer to the current float.
785h∗hyperi
786\long\def\@caption#1[#2]#3{\par%
787 \addcontentsline%
788 {\csname ext@#1\endcsname}%
789 {#1}%
790 {\protect\numberline{\csname the#1\endcsname}%
791 {\ignorespaces \hyperreference{\@currenthyper}{#2}}%
792 }%
793 \begingroup%
794 \@parboxrestore%
795 \normalsize%
796 \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par%
797 \endgroup%
798}
799h/hyperi
Obviously we need to modify\@makecaptionto define the anchor. As this macro is defined only for the classesarticle,book, ltnews,ltxdoc, ltxguide, proc, andreportwe redefine it only for them.
800h∗article,book,ltnews,ltxdoc,ltxguide,proc,reporti
801\let\hyper@makecaption\@makecaption
802\long\def\@makecaption#1#2{%
803 \hyper@makecaption{\hyperanchor{\@currenthyper}{#1}}{#2}%
804}
805h/article,book,ltnews,ltxdoc,ltxguide,proc,reporti
8.13 Footnotes
Here we want to handle references from footnotemarks to footnotes at the bottom of the page.
At first modify the standard definition of \@makefnmark to refer to a footnote which is complicated by the fact that\thepagedoes not necessarily refer to the actual page when used. So we have to write the page to an auxiliary file and reread it afterwards. Let’s not forget to check for changes of these entries to warn the user about possible changes.
806h∗hyperi
807\newcount\hyper@fnmark@count
808\hyper@fnmark@count0
809\def\hyper@currentfnmark{%
810 \global\advance\hyper@fnmark@count1\relax%
811 \@bsphack%
812 \protected@write\hyper@auxout%
813 {}%
814 {\string\hyperfnpage{\the\hyper@fnmark@count}{\thepage}}%
815 \@esphack%
816 \hb@xt@\z@{%
817 \ifx\hyper@minipage@label\@empty%
818 \global\edef\hyper@current@fnmark%
819 {fn.\@arabic\c@footnote.%
820 \expandafter%
821 \ifx\csname hyper@fn@\the\hyper@fnmark@count\endcsname%
822 \relax%
823 ?%
824 \else%
825 \csname hyper@fn@\the\hyper@fnmark@count\endcsname%
826 \fi%
827 }%
828 \else\ifnum\hyper@minipage@label=0\relax%
829 \global\edef\hyper@current@fnmark%
830 {fn.\hyper@minipage@label.\@arabic\c@footnote.%
831 \expandafter%
832 \ifx\csname hyper@fn@\the\hyper@fnmark@count\endcsname%
833 \relax%