summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/oberdiek/hypdoc.dtx
blob: 1c058c30a292f53585737c6b94a7d3d6449564e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
% \iffalse meta-comment
%
% Copyright (C) 2002, 2006 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 hypdoc.dtx
% and the derived files
%    hypdoc.sty, hypdoc.pdf, hypdoc.ins, hypdoc.drv.
%
% Distribution:
%    CTAN:macros/latex/contrib/oberdiek/hypdoc.dtx
%    CTAN:macros/latex/contrib/oberdiek/hypdoc.pdf
%
% Unpacking:
%    (a) If hypdoc.ins is present:
%           tex hypdoc.ins
%    (b) Without hypdoc.ins:
%           tex hypdoc.dtx
%    (c) If you insist on using LaTeX
%           latex \let\install=y\input{hypdoc.dtx}
%        (quote the arguments according to the demands of your shell)
%
% Documentation:
%    (a) If hypdoc.drv is present:
%           latex hypdoc.drv
%    (b) Without hypdoc.drv:
%           latex hypdoc.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 hypdoc.dtx
%       makeindex -s gind.ist hypdoc.idx
%       pdflatex hypdoc.dtx
%       makeindex -s gind.ist hypdoc.idx
%       pdflatex hypdoc.dtx
%
% Installation:
%    TDS:tex/latex/oberdiek/hypdoc.sty
%    TDS:doc/latex/oberdiek/hypdoc.pdf
%    TDS:source/latex/oberdiek/hypdoc.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: hypdoc 2006/06/02 v1.4 Hyper extensions for doc.sty (HO)}
\Msg{************************************************************************}

\keepsilent
\askforoverwritefalse

\preamble

This is a generated file.

Copyright (C) 2002, 2006 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 hypdoc.dtx
and the derived files
   hypdoc.sty, hypdoc.pdf, hypdoc.ins, hypdoc.drv.

\endpreamble

\generate{%
  \file{hypdoc.ins}{\from{hypdoc.dtx}{install}}%
  \file{hypdoc.drv}{\from{hypdoc.dtx}{driver}}%
  \usedir{tex/latex/oberdiek}%
  \file{hypdoc.sty}{\from{hypdoc.dtx}{package}}%
}

\obeyspaces
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* file into a directory searched by TeX:}
\Msg{*}
\Msg{*     hypdoc.sty}
\Msg{*}
\Msg{* To produce the documentation run the file `hypdoc.drv'}
\Msg{* through LaTeX.}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}

\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{hypdoc.drv}%
  [2006/06/02 v1.4 Hyper extensions for doc.sty (HO)]
\documentclass{ltxdoc}
\usepackage{holtxdoc}
\begin{document}
  \DocInput{hypdoc.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{682}
%
% \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{hypdoc.drv}
%
% \title{The \xpackage{hypdoc} package}
% \date{2006/06/02 v1.4}
% \author{Heiko Oberdiek\\\xemail{oberdiek@uni-freiburg.de}}
%
% \maketitle
%
% \begin{abstract}
% This package adds hyper features to the package
% \xpackage{doc} that is used in the documentation
% system of \LaTeXe. Bookmarks are added and references
% are linked as far as possible.
% \end{abstract}
%
% \tableofcontents
%
% \section{Features}
%
% The package adds the following features:
% \begin{description}
% \item[Bookmarks:]
%   For supporting bookmarks package \verb|hyperref| is loaded.
%   Some \TeX\ code inside section titles can cause problems
%   during bookmark processing; these can be warnings, ugly
%   bookmark titles or even errors. With the help of
%   \verb|\pdfstringdefDisableCommands| or \verb|\texorpdfstring|
%   you can manage these things, see \verb|hyperref|'s package
%   documentation.
% \item[Additional bookmarks:]
%   Unnumbered bookmark entries are generated for:
%   \begin{itemize}
%   \item Table of contents
%   \item List of figures
%   \item List of tables
%   \item Index
%   \item Glossary
%   \end{itemize}
%   Option \texttt{numbered} controls, whether these section or
%   chapters should be numbered. The exception is the table
%   of contents if this it would be the first numbered
%   section. Then just a bookmark is added.
% \item[Metadata:]
%   The loaded package \verb|hyperref|, enforced by
%   option \verb|pdfusetitle|, tries to detect \verb|\title|
%   and \verb|\author| and sets the corresponding PDF
%   information fields. In case of problems see the previous
%   item about bookmarks.
%   These enries can be overwritten or new ones added by
%   \verb|\hypersetup| after the packages is loaded, see
%   documentation of package \verb|hyperref|.
% \item[References, links:] Because of package \verb|\hyperref|
%   |\ref| become links, also \verb|\url|, footnote referencing
%   are supported.
% \item[Index:]
%   The main part of this package deals with index links in order
%   to support the kind of index that package \verb|doc| provides.
% \item[Thumbnails:]
%   Package \verb|thumbpdf| is loaded for the case that the
%   PDF file also should contain thumbnails, see the documentation
%   of this package. But thumbnail embedding is not really
%   necessary, because nowadays AcrobatReader is able to
%   generate and view thumbnails on the fly.
% \end{description}
%
% \section{Usage}
%
% The purpose of this packages is to add PDF features to
% the documentation of LaTeX packages. Thus just load
% the package in the driver file that generates the
% documentation:
% \begin{quote}
%   \verb|\usepackage{hypdoc}|
% \end{quote}
% Package \verb|doc| is loaded by \verb|hypdoc|, thus you
% also can replace a \verb|\usepackage{doc}| with this line.
% At any case, the package must be loaded before macros of
% package \verb|doc| such as \verb|\CodelineIndex| or
% \verb|\PageIndex| are used.
%
% If the class \verb|ltxdoc| is used, you can also use
% the configuration file for this class to add
% package \verb|hypdoc|. Add the following line
% to the file \verb|ltxdoc.cfg| (or create a new one):
% \begin{quote}
%\begin{verbatim}
%\AtEndOfClass{\RequirePackage{hypdoc}}
%\end{verbatim}
% \end{quote}
%
% \subsection{Options}
%
% There is one option \texttt{numbered}. It controls,
% whether the starred versions of section or chapter
% inside \cs{tableofcontents}, \cs{listoffigures}, \dots
% should be replaced by the non-star versions.
%
% \subsection{Simple example}
% Example of a simple driver file \verb|foobar.drv|
% of a package \verb|foobar|. Often the driver file
% is packed in the file \verb|foobar.dtx| and can
% be extracted by docstrip or if an instruction file
% for docstrip is provided by:
% \begin{quote}
% \verb|tex foobar.ins|
% \end{quote}
% Note that although docstrip doesn't rely on \LaTeX,
% sometimes you need to run the \verb|.ins| file through
% \LaTeX. Oddly enough, often the only \LaTeX\ feature
% in use is \verb|\NeedsTeXFormat{LaTeX2e}| in the first line.
% \begin{quote}
%\begin{verbatim}
%\documentclass{ltxdoc}
%\usepackage{hypdoc}
%\RecordChanges
%\EnableCrossrefs
%\CodelineIndex
%\begin{document}
%\title{Title for package \texttt{foobar}}
%\author{Author of package \texttt{foobar}}
%\date{...}
%\maketitle
%\tableofcontents
%\DocInput{foobar.dtx}
%\PrintChanges
%\PrintIndex
%\end{document}
%\end{verbatim}
% \end{quote}
%
% Then compile it, for example with pdf\LaTeX.
% \begin{quote}
%\begin{verbatim}
%pdflatex foobar.drv
%makeindex -s gind.ist foobar.idx
%makeindex -s gglo.ist -o foobar.gls foobar.glo
%pdflatex foobar.drv
%\end{verbatim}
% \end{quote}
% You will need several cycles until the cross references
% and similar things are correct.
%
% \subsection{Example \texttt{source2e.tex}}
%
% The source code of the base of \LaTeX\ is available as
% a bunch of \verb|.dtx| files. \LaTeX\ provides the file
% \verb|source2e.tex| to merge them all together.
%
% Now you can either load package \verb|hypdoc| in a private copy
% of this file (please, respect the LPPL) or use the configuration
% file \verb|ltxdoc.cfg|. Example that also sets A4 paper size:
% \begin{quote}
%\begin{verbatim}
%\PassOptionsToClass{a4paper}{article}
%\AtEndOfClass{\RequirePackage{hypdoc}}
%\end{verbatim}
% \end{quote}
%
% Then \verb|source2e.tex| can be compiled by pdf\TeX, for example:
% \begin{quote}
%\begin{verbatim}
%pdflatex source2e
%makeindex -s gind.ist source2e.idx
%makeindex -s gglo.ist -o source2e.glo source2e.gls
%pdflatex source2e
%makeindex -s gind.ist source2e.idx
%makeindex -s gglo.ist -o source2e.glo source2e.gls
%pdflatex source2e
%\end{verbatim}
% \end{quote}
%
% \StopEventually{
% }
%
% \section{Implementation}
%
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{hypdoc}%
  [2006/06/02 v1.4 Hyper extensions for doc.sty (HO)]
%    \end{macrocode}
%    The package identification is done at the top of the |.dtx| file
%    in order to use only one identification string.
%
%    For unique command names this package uses |HD@| as prefix
%
%    \begin{macrocode}
%
\newif\ifHD@numbered
\DeclareOption{numbered}{\HD@numberedtrue}
\ProcessOptions*\relax

\RequirePackage{doc}

\ifx\numexpr\@undefined
  \RequirePackage{calc}
\fi
\RequirePackage[%
  hyperindex=false,%
  pdfusetitle,%
  colorlinks,%
  pdfpagelabels,%
]{hyperref}[2002/05/09]%
\hypersetup{%
  plainpages=false,%
  bookmarksopen,%
  bookmarksnumbered,%
  bookmarksopenlevel=0,%
  pdfstartview={FitBH \hypercalcbp{%
    \paperheight-\topmargin-1in-\headheight-\headsep
  }},%
}
\RequirePackage{thumbpdf}

\newcounter{HD@unique}
\renewcommand{\theHD@unique}{%
  \number\value{HD@unique}%
}

\g@addto@macro\Hy@UseMaketitleInfos{%
  \@ifundefined{fileinfo}{}{%
    \ifx\@pdfsubject\@empty
      \hypersetup{pdfsubject={\fileinfo}}%
    \fi
  }%
}

\pdfstringdefDisableCommands{%
  \let\thanks\@gobble
  \let\footnote\@gobble
  \def\cs#1{\textbackslash #1}%
  \let\normalfont\@empty
  \let\scshape\@empty
  \def\and{and }%
}

%%% Bookmarks

\def\HD@sectionpatch{%
  \ifHD@numbered
    \HD@@sectionpatch{section}%
    \HD@@sectionpatch{chapter}%
  \else
    \let\Hy@writebookmark\HD@disable@writebookmark
  \fi
}
\def\HD@@sectionpatch#1{%
  \expandafter\let\csname HDorg@@#1\expandafter\endcsname
    \csname #1\endcsname
  \@namedef{#1}{%
    \@ifstar{\@nameuse{HDorg@@#1}}{\@nameuse{HDorg@@#1}}%
  }%
}
\def\HD@disable@writebookmark#1#2#3#4#5{}

% A wild guessing of the toclevel. There is the hope, that
% the macro \verb|#1| starts with a sectioning command.
\def\HD@guesstoclevel#1{%
  \expandafter\HD@@guesstoclevel#1\section\HD@end
}
\def\HD@@guesstoclevel#1#2\HD@end{%
  \@ifundefined{toclevel@\expandafter\@gobble\string#1\@empty}{%
    1%
  }{%
    \@nameuse{toclevel@\expandafter\@gobble\string#1\@empty}%
  }%
}

\let\HDorg@tableofcontents\tableofcontents
\def\tableofcontents{%
  % As first section the table of contents shouldn't
  % go into the toc itself. Also a number looks too funny then.
  % Just a bookmark is enough in this case.
  \begingroup
    \@ifundefined{c@section}{%
      \def\c@section{0}%
    }{}%
  \expandafter\endgroup
  \ifcase\c@section
    \stepcounter{HD@unique}%
    \pdfbookmark[\HD@guesstoclevel{\HDorg@tableofcontents}]
        {\contentsname}{toc\theHD@unique}%
    \HDorg@tableofcontents
  \else
    \ifHD@numbered
    \else
      \stepcounter{HD@unique}%
      \pdfbookmark[\HD@guesstoclevel{\HDorg@tableofcontents}]
          {\contentsname}{toc\theHD@unique}%
    \fi
    \begingroup
      \HD@sectionpatch
      \HDorg@tableofcontents
    \endgroup
  \fi
}

\let\HDorg@listoffigures\listoffigures
\def\listoffigures{%
  \ifHD@numbered
  \else
    \stepcounter{HD@unique}%
    \pdfbookmark[\HD@guesstoclevel{\HDorg@listoffigures}]
        {\contentsname}{toc\theHd@unique}%
  \fi
  \begingroup
    \HD@sectionpatch
    \HDorg@listoffigures
  \endgroup
}

\let\HDorg@listoftables\listoftables
\def\listoftables{%
  \ifHD@numbered
  \else
    \stepcounter{HD@unique}%
    \pdfbookmark[\HD@guesstoclevel{\HDorg@listoftables}]
        {\contentsname}{toc\theHD@unique}%
  \fi
  \begingroup
    \HD@sectionpatch
    \HDorg@listoftables
  \endgroup
}

\let\HDorg@thebibliography\thebibliography
\def\thebibliography{%
  \ifHD@numbered
  \else
    \stepcounter{HD@unique}%
    \pdfbookmark[\HD@guesstoclevel{\HDorg@thebibliography}]
      {\@ifundefined{chapter}{\refname}{\bibname}}{bib\theHD@unique}%
  \fi
  \HD@sectionpatch
  \HDorg@thebibliography
}

\let\HDorg@theindex\theindex
\def\theindex{%
  \let\HDorg@index@prologue\index@prologue
  \let\HDorg@writebookmark\Hy@writebookmark
  \HD@sectionpatch
  \g@addto@macro\IndexParms{%
    \ifHD@numbered
    \else
      \let\Hy@writebookmark\HDorg@writebookmark
    \fi
    \let\bfseries\HD@bfseries
  }%
  \edef\HD@toclevel@index{\HD@guesstoclevel{\index@prologue}}%
  \begingroup
    \count@=\HD@toclevel@index\relax
    \advance\count@ by 1 %
    \xdef\HD@toclevel@subindex{\the\count@}%
  \endgroup
  \def\index@prologue{%
    \ifHD@numbered
    \else
      \begingroup
        \stepcounter{HD@unique}%
        \let\Hy@writebookmark\HDorg@writebookmark
        \pdfbookmark[\HD@toclevel@index]%
            {\indexname}{index\theHD@unique}%
      \endgroup
    \fi
    \HDorg@index@prologue
  }%
  \HDorg@theindex
}
\let\HDorg@bfseries\bfseries
\def\HD@bfseries{\futurelet\HD@hfil\HD@@bfseries}%
\def\HD@@bfseries{%
  \HDorg@bfseries
  \ifx\HD@hfil\hfil
    \expandafter\HD@@@bfseries
  \fi
}%
\def\HD@@@bfseries\hfil#1\hfil{%
  \ifx\\#1\\%
  \else
    \raisebox{\baselineskip}[0pt]{%
      \kern-\HD@margin\relax
      \pdfbookmark[\HD@toclevel@subindex]{#1}{HD.#1}%
      \kern\HD@margin\relax
    }%
  \fi
  \hfil#1\hfil
}%
\def\HD@margin{1mm}

\let\HDorg@theglossary\theglossary
\def\theglossary{%
  \let\HDorg@glossary@prologue\glossary@prologue
  \let\HDorg@writebookmark\Hy@writebookmark
  \HD@sectionpatch
  \def\glossary@prologue{%
    \ifHD@numbered
    \else
      \begingroup
        \let\Hy@writebookmark\HDorg@writebookmark
        \stepcounter{HD@unique}%
        \pdfbookmark[\HD@guesstoclevel{\HDorg@glossary@prologue}]
            {\glossaryname}{glossary\theHD@unique}%
      \endgroup
    \fi
    \HDorg@glossary@prologue
  }%
  \HDorg@theglossary
}
\providecommand*{\glossaryname}{Change History}

%%% Index stuff

\newcounter{HD@hypercount}
\newlength{\HD@helplength}
\newif\ifHD@savedest
\HD@savedesttrue
\AtBeginDocument{%
  \HD@savedest@init
}
\begingroup
  \catcode`\^^M=\active
\@firstofone{\endgroup
  \def\HD@savedest@init{%
    \ifHD@savedest
      \let\HDorg@tilde~%
      \let~\HD@savedest@entry
      \edef\HDorg@catcodeM{\the\catcode`\^^M}%
      \catcode`\^^M=\active
      \def^^M{}%
      \InputIfFileExists{\jobname.hd}{}{}%
      \let~\HDorg@tilde
      \catcode`\^^M=\HDorg@catcodeM\relax
      \newwrite\HD@savedest@out
      \immediate\openout\HD@savedest@out=\jobname.hd\relax
      \AtEndDocument{\immediate\closeout\HD@savedest@out}%
    \else
      \let\HD@savedest@add\@gobble
    \fi
  }%
  \def\HD@savedest@entry#1^^M{%
    \@namedef{HD.#1}{}%
  }%
}
\def\HD@savedest@add#1{%
  \immediate\write\HD@savedest@out{\string~#1}%
}

\newif\ifHD@targetraise
\HD@targetraisetrue

\def\HD@target{%
  \ifHD@targetraise
    \ifhmode
      \settoheight{\HD@helplength}{[H]}%
      \addtolength{\HD@helplength}{0.4ex}%
      \raisebox{\HD@helplength}{%
        \HD@maketarget
      }%
    \else
      \HD@maketarget
    \fi
  \else
    \HD@maketarget
  \fi
}
\def\HD@maketarget{%
  \stepcounter{HD@hypercount}%
  \def\HD@next{%
    \llap{\hypertarget{HD.\the\c@HD@hypercount}{}\,}%
  }%
  \ifHD@savedest
    \expandafter\ifx\csname HD.\the\c@HD@hypercount\endcsname\@empty
    \else
      \let\HD@next\relax
    \fi
  \fi
  \HD@next
}

\g@addto@macro\CodelineIndex{%
  \let\special@index\HD@codeline@wrindex
}
\g@addto@macro\PageIndex{%
  \let\special@index\HD@page@wrindex
}

\def\HD@codeline@wrindex#1{%
  \begingroup
    \let\HDorg@encapchar\encapchar
    \def\encapchar##1\encapchar##2\@nil{%
      \HDorg@encapchar
      hdclindex{\the\c@HD@hypercount}{##1}%
    }%
    \codeline@wrindex{%
      #1\encapchar\encapchar\@nil
    }%
  \endgroup
}
\def\HD@page@wrindex#1{%
  \begingroup
    \let\HDorg@encapchar\encapchar
    \def\encapchar##1\encapchar##2\@nil{%
      \HDorg@encapchar
      hdpindex{##1}%
    }%
    \HDorg@index{#1\encapchar\encapchar\@nil}%
  \endgroup
}

\def\hdclindex#1#2#3{%
  \csname\ifx\\#2\\relax\else#2\fi\endcsname{%
    \hyperlink{HD.#1}{#3}%
    \HD@savedest@add{#1}%
  }%
}
\def\hdpindex#1#2{%
  \csname\ifx\\#1\\relax\else#1\fi\endcsname{%
    \hyperpage{#2}%
  }%
}

\let\HDorg@PrintDescribeMacro\PrintDescribeMacro
\renewcommand\PrintDescribeMacro[1]{%
  \begingroup
    \let\HDorg@MacroFont\MacroFont
    \def\MacroFont{%
      \HD@target
      \HDorg@MacroFont
    }%
    \HDorg@PrintDescribeMacro{#1}%
  \endgroup
}

\let\HDorg@PrintMacroName\PrintMacroName
\renewcommand\PrintMacroName[1]{%
  \begingroup
    \let\HDorg@MacroFont\MacroFont
    \def\MacroFont{%
      \HD@target
      \HDorg@MacroFont
    }%
    \HDorg@PrintMacroName{#1}%
  \endgroup
}

\let\HDorg@theCodelineNo\theCodelineNo
\renewcommand*\theCodelineNo{%
  \settowidth{\HD@helplength}{\HDorg@theCodelineNo\ }%
  \ifdim\HD@helplength<\MacroIndent
    \addtolength{\HD@helplength}{-\MacroIndent}%
    \llap{%
      \begingroup\HD@target\endgroup
      \hspace*{-\HD@helplength}%
    }%
  \else
    \HD@target
  \fi
  \HDorg@theCodelineNo
}

\AtBeginDocument{%
  \let\HDorg@index\index
}

\let\HDorg@SpecialUsageIndex\SpecialUsageIndex
\renewcommand*\SpecialUsageIndex[1]{%
  \@bsphack
  \begingroup
    \HD@target
    \let\index\HDorg@index
    \let\HDorg@encapchar\encapchar
    \edef\encapchar usage{%
       \HDorg@encapchar hdclindex{\the\c@HD@hypercount}{usage}%
    }%
    \HDorg@SpecialUsageIndex{#1}%
  \endgroup
  \@esphack
}

\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname autoindex\endcsname\relax
\else
  \let\HDorg@autoindex\autoindex
  \renewcommand*\autoindex[1]{%
    \@bsphack
    \begingroup
      \HD@target
      \let\index\HDorg@index
      \let\HDorg@encapchar\encapchar
      \edef\encapchar usage{%
         \HDorg@encapchar hdclindex{\the\c@HD@hypercount}{usage}%
      }%
      \HDorg@autoindex{#1}%
    \endgroup
    \@esphack
  }
\fi

\let\HDorg@SpecialEnvIndex\SpecialEnvIndex
\renewcommand*\SpecialEnvIndex[1]{%
  \@bsphack
  \begingroup
    \HD@target
    \let\HDorg@encapchar\encapchar
    \edef\encapchar usage{%
      \HDorg@encapchar hdclindex{\the\c@HD@hypercount}{usage}%
    }%
    \HDorg@SpecialEnvIndex{#1}%
  \endgroup
  \@esphack
}

\let\HDorg@SortIndex\SortIndex
\renewcommand*{\SortIndex}[2]{%
  \@bsphack
  \begingroup
    \let\index\HD@page@wrindex
    \HDorg@SortIndex{#1}{#2}%
  \endgroup
  \@esphack
}


%%% glossary stuff

\let\HDorg@wrglossary\@wrglossary
\def\@wrglossary#1{%
  \let\HDorg@encapchar\encapchar
  \def\encapchar##1\encapchar##2\@nil{%
    \HDorg@encapchar
    hdpindex{##1}%
  }%
  \HDorg@wrglossary{#1\encapchar\encapchar\@nil}%
}

%%% \MacroIndent automatically calculated

\AtEndDocument{%
  \if@filesw
    \immediate\write\@auxout{%
      \noexpand\HD@SetMacroIndent{\number\value{CodelineNo}}%
    }%
  \fi
}
\def\HD@SetMacroIndent#1{%
  \begingroup
    \value{CodelineNo}=#1\relax
    \settowidth{\MacroIndent}{\HDorg@theCodelineNo\ }%
    \global\MacroIndent\MacroIndent
  \endgroup
}
%    \end{macrocode}
%
%    \begin{macrocode}
%</package>
%    \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/hypdoc.dtx}] The source file.
% \item[\CTAN{macros/latex/contrib/oberdiek/hypdoc.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 hypdoc.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@{}}
%   hypdoc.sty & tex/latex/oberdiek/hypdoc.sty\\
%   hypdoc.pdf & doc/latex/oberdiek/hypdoc.pdf\\
%   hypdoc.dtx & source/latex/oberdiek/hypdoc.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 hypdoc.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 intension:
% \begin{quote}
%   \verb|latex \install=y\input{hypdoc.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 hypdoc.dtx
%makeindex -s gind.ist hypdoc.idx
%pdflatex hypdoc.dtx
%makeindex -s gind.ist hypdoc.idx
%pdflatex hypdoc.dtx
%\end{verbatim}
% \end{quote}
%
% \begin{History}
%   \begin{Version}{2002/05/10 v1.0}
%   \item
%     First standalone version.
%   \end{Version}
%   \begin{Version}{2006/02/20 v1.1}
%   \item
%     Option \xoption{numbered} added.
%   \item
%     \cs{HD@savedest@init} fixed (empty \xext{.hd} file triggered
%     first page with fl ligature).
%   \item
%     Bookmarks for \cs{listoffigures} and \cs{listoftables}.
%   \item
%     Documentation: features and usage added.
%   \item
%     LPPL 1.3.
%   \end{Version}
%   \begin{Version}{2006/04/27 v1.2}
%   \item
%     \cs{HD@target} fixed (\xfile{multicol.dtx}).
%   \end{Version}
%   \begin{Version}{2006/06/01 v1.3}
%   \item
%     Support for package \xpackage{amsdtx}'s \cs{autoindex} added.
%   \end{Version}
%   \begin{Version}{2006/06/02 v1.4}
%   \item
%     Bookmark fixed if there are several table of contents,
%     bibliographies, glossaries, \dots
%   \end{Version}
% \end{History}
%
% \PrintIndex
%
% \Finale
\endinput