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
|
% \iffalse
% makeindex -s gglo.ist -o endnotes-hy.gls endnotes-hy.glo
% makeindex -s gind.ist -o endnotes-hy.ind endnotes-hy.idx
%<*copyright>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% endnotes-hy.sty package, %%
%% Copyright (C) 2020 %%
%% dpstory@uakron.edu dpstory@acrotex.net %%
%% %%
%% This program can redistributed and/or modified under %%
%% the terms of the LaTeX Project Public License %%
%% Distributed from CTAN archives in directory %%
%% macros/latex/base/lppl.txt; either version 1.2 of the %%
%% License, or (at your option) any later version. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%</copyright>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{endnotes-hy}
%<package> [2020/04/08 v0.1 Enables hypertext links for endnotes]
%<*driver>
\documentclass{ltxdoc}
\usepackage[colorlinks,hyperindex=false,linktocpage,bookmarksnumbered]{hyperref}
\usepackage{calc}
\usepackage{endnotes-hy}
%\def\texorpdfstring#1#2{#1}
%\pdfstringdefDisableCommands{\let\\\textbackslash}
\OnlyDescription % comment out for implementation details
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\gdef\brpr#1{\texttt{\char123\relax#1\char125\relax}}
\let\darg\brpr
\let\env\texttt
\let\opt\texttt
\let\app\textsf
\let\pkg\textsf
\def\EXCL{!}
\def\visispace{\symbol{32}}
\def\ameta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}}
\def\meta#1{\textsl{\texttt{#1}}}
\def\SUB#1{\ensuremath{{}_{\mbox{\scriptsize\ttfamily#1}}}}
\def\CMD#1{\textbackslash#1}
\makeatletter
\renewcommand\theparagraph{\texorpdfstring{\protect\P\protect\ }{\textparagraph}}
\renewcommand\thesubparagraph{\texorpdfstring{\protect\P\protect\P\protect\ }{\textparagraph\textparagraph}}
\renewcommand{\section}
{\renewcommand{\@seccntformat}[1]{\thesection\quad}%
\@startsection {section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\Large\bfseries}}
\renewcommand{\paragraph}
{\renewcommand{\@seccntformat}[1]{\theparagraph\unskip\,}%
\@startsection{paragraph}{4}{0pt}{6pt}{-3pt}{\bfseries}}
\renewcommand{\subparagraph}
{\renewcommand{\@seccntformat}[1]{\thesubparagraph\unskip\,}%
\@startsection{subparagraph}{5}{\parindent}{6pt}{-3pt}{\bfseries}}
\makeatother
\newbox\enbox
\InputIfFileExists{aebdocfmt.def}{\PackageWarning{endnotes-hy}{Inputting aebdocfmt.def}}
{\def\IndexOpt{\DescribeMacro}\def\IndexKey{\DescribeMacro}\let\setupFullwidth\relax
\PackageInfo{endnotes-hy}{aebdocfmt.def cannot be found}}
\begin{document}
\addtolength{\marginparwidth}{3pt}
\GetFileInfo{endnotes-hy.sty}
\title{The \textsf{endnotes-hy} Package}
\author{D. P. Story\\
Email: \texttt{dpstory@uakron.edu}}
\date{processed \today}
\maketitle
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\bgroup
\value{secnumdepth}=3
\value{tocdepth}=3
\tableofcontents
\egroup
\DocInput{endnotes-hy.dtx}
\IfFileExists{\jobname.ind}{\newpage\setupFullwidth\par\PrintIndex}{\paragraph*{Index} The index goes here. Execute
\begin{quote}\texttt{makeindex -s gind.ist -o endnotes-hy.ind endnotes-hy.idx}\end{quote}
on the command line and recompile
\texttt{endnotes-hy.dtx}.}
\IfFileExists{\jobname.gls}{\PrintChanges}{\paragraph*{Change History} The list of changes goes here. Execute
\begin{quote}
\texttt{makeindex -s gglo.ist -o endnotes-hy.gls endnotes-hy.glo}
\end{quote}
on the command line and recompile \texttt{endnotes-hy.dtx}.}
\end{document}
%</driver>
% \fi
% \MakeShortVerb{|}
% \InputIfFileExists{aebdonotindex.def}{\PackageInfo{web}{Inputting aebdonotindex.def}}
% {\PackageInfo{web}{cannot find aebdonotindex.def}}
% \begin{macrocode}
%<*package>
% \end{macrocode}
% \section{Introduction}
% This package is an extension of \href{https://ctan.org/pkg/endnotes}{\pkg{endnotes}}.
% \changes{v0.1}{2020/04/08}{First published version of this package.}
%
% \paragraph*{Background:} A colleague---a dedicated user of the
% \href{https://ctan.org/pkg/endnotes}{\pkg{endnotes}} package---complained to me
% (for some reason) that links created by \pkg{hyperref} do not point to the
% endnotes at the end of the file; for example, if we say
%\begin{quote}\ttfamily
% \string\endnote\darg{\string\label\darg{\ameta{name}}\ameta{text}}
%\end{quote}
% then any link, such as
% \cs{hyperref[\ameta{name}]\darg{endnote\string~\string\ref*\darg{\ameta{name}}}} jumps
% to the most recent anchor (\texttt{Doc-Start}, for example); no hypertext
% anchor is created where the endnote is inserted into the document. This short
% package is an attempt to rectify this problem.
%
%\paragraph*{Syntax:}
% The \cs{endnote} command has been modified to conform to the following syntax:
%\begin{quote}
% \cs{endnote*[\ameta{num}]\darg{\ameta{text}}\string\label\darg{\ameta{name}}}
%\end{quote}
% Refer to the documentation of the \href{https://ctan.org/pkg/endnotes}{\pkg{endnotes}} package for a description of the \cs{endnote}
% command and its \ameta{num} and \ameta{text} arguments.
% If the \texttt*-option (new syntax) is used, the endnote mark is not placed, but the endnote
% is written to the \texttt{ENT} file.\endnote*{An endnote created with \texttt*-option}\label{en:en*}
% Such a ``secret'' endnote can be referred to using standard \pkg{hyperref} commands,
% see the \autoref{en:en*} on page~\pageref{en:en*} for more information. The placement of the \cs{label} has
% changed for this package as well. To define an endnote label, place \cs{label\darg{name}} following
% the \cs{endnote} command, a more traditional location. This was done to get access to the \ameta{name}, if it exist.
% This enables the package to place a hypertext link around the endnote mark.\endnote{This is normal endnote}\label{en:normal}
% The optional \ameta{num} can be used
% to write special endnotes.{\def\theendnote{N\arabic{endnote}}\endnote[1]{This is special endnote}\label{en:specen}}
% As a side benefit to this new syntax, you can place verbatim text into an
% endnote.\setbox\enbox\hbox{\verb!%^$^&$%^&!}\edef\VertTxti{\unhbox\enbox}\endnote{Some verbatim text \VertTxti}\label{en:verb}
% If there is no \cs{label} following \cs{endnote}, no hypertext link is created.\endnote{No hypertext link created}
%
% \paragraph*{Note:} This package will work correctly without the \pkg{hyperref} package (of course, no links).
% The advantage of using \pkg{endnotes-hy} without \pkg{hyperref} is to use the extended syntax:
% \cs{endnote*[\ameta{num}]\darg{\ameta{text}}\string\label\darg{\ameta{name}}}
%
% \section{Required packages}
%
% \begin{macrocode}
\RequirePackage{endnotes}
% \end{macrocode}
% Require \pkg{etoolbox} because we redefine several commands using \cs{patchcmd}; this is not
% really necessary, we could have redefined the whole command instead.
% \begin{macrocode}
\RequirePackage{etoolbox}
% \end{macrocode}
% \section{Package code}
% We allow the author not to use \pkg{hyperref}; this enables the use of the extended
% syntax of the \cs{endnote} command.
% \begin{macrocode}
\newcommand\hyperref@nohy[2][]{#2}
\AtBeginDocument{\@ifundefined{hyperref}{\let\hyperref@en\hyperref@nohy
\let\phantomendnote\relax}
{\let\hyperref@en\hyperref}}
% \end{macrocode}
% \begin{macro}{\phantomendnote}
% The key is to create an hyperref anchor to reference; this definition is based on
% \cs{phantomsection} of \pkg{hyperref}. This is used internally.
% \begin{macrocode}
\def\phantomendnote{%
\Hy@MakeCurrentHrefAuto{endnote}%
\Hy@raisedlink
{\hyper@anchorstart{endnote.\@theenmark}\hyper@anchorend}}
\def\endnoteautorefname{endnote}
% \end{macrocode}
% \end{macro}
% Redefinition of \DescribeMacro{\theendnotes}\cs{theendnotes}
% \begin{macrocode}
\patchcmd{\theendnotes}{\enoteformat}
{\phantomendnote\def\@currentHref{endnote.\@theenmark}%
\enoteformat}{}{}
% \end{macrocode}
% Redefine \DescribeMacro\endnote\cs{endnote} to take an optional \texttt{*}, if this option is used, the mark does not appear
% in the text. This enables us to easily define an endnote and refer to it even with multiple paragraphs.
% I didn't like the syntax of inserting the \cs{label} within the argument of \cs{endnote}, this seems to have
% problems. The new syntax is as follows:\begin{quote}
% Syntax: \cs{endnote*[\ameta{num}]\darg{\ameta{text}}\string\label\darg{\ameta{name}}}\end{quote}
% This new syntax could be a problem if an author has already used \pkg{endnotes} and then converts
% to \pkg{endnotes-hy}. In \pkg{endnotes} the \texttt*-option is note defined and the \cs{label}
% command is typically placed within the argument of the \darg{\ameta{text}}. Labels would have to be moved
% to a position following \darg{\ameta{text}}.
%
% To obtain this syntax, we need several stages of parsing. The major problem is to get the
% label name in time to build a hyperref link around \cs{@endnotemark}.
% \begin{macrocode}
\newtoks\@entoks
\def\endnote{\let\@encurrlabelname\@empty
\@ifstar{\let\@noMrk1\endnote@i}{\let\@noMrk0\endnote@i}}
\def\endnote@i{\@ifnextchar[%]
{\@xendnote}
{\stepcounter{endnote}%
\protected@xdef\@theenmark{\theendnote}%
% \end{macrocode}
% We placed the \darg{text} argument into a token register, this removes
% that argument from the input stream, and allows us to see of the next token
% is \cs{label}, if so, we get the label name argument.
% \begin{macrocode}
\afterassignment\endnote@ii\@entoks}}
% \end{macrocode}
% If the next token is \cs{label}, get the label name with \cs{endnote@iii},
% otherwise, move on to \cs{endnote@iv}, the final step.
% \begin{macrocode}
\def\endnote@ii{\@ifnextchar\label{\endnote@iii}{\endnote@iv}}
\def\endnote@iii\label#1{\def\@encurrlabelname{#1}\endnote@iv}
% \end{macrocode}
% If the flag \cs{@noMrk} is 0 (mark is typeset), and if there
% is a label name, we make an hypertext link.
% \begin{macrocode}
\def\endnote@iv{%
\if\@noMrk0\relax
\ifx\@encurrlabelname\@empty
\@endnotemark
\else
\hyperref@en[\@encurrlabelname]{\@endnotemark}%
\fi
\fi
% \end{macrocode}
% Finish by expanding \cs{@endnotetext} with its argument
% that was saved in the \cs{@entoks} register.
% \begin{macrocode}
\expandafter\@endnotetext\expandafter{\the\@entoks}}
% \end{macrocode}
% We patch into \DescribeMacro\@endnotetext\cs{@endnotetext} just after \verb~\def\next{#1}~.
% If there was a \cs{label}, we insert it back into the argument
% of \cs{endnote}.
% \begin{macrocode}
\patchcmd{\@endnotetext}
{\def\next{#1}}
{\ifx\@encurrlabelname\@empty
\def\next{#1}\else
\edef\x{\noexpand\label{\@encurrlabelname}}%
\expandafter\def\expandafter\next\expandafter{\x#1}\fi}{}{}
% \end{macrocode}
% If \cs{endnote} has an optional argument, the flow passes to
% \DescribeMacro\xendnote\cs{xendnote}. We replace
% \verb~\@endnotemark\@endnotetext~ by redirecting flow to
% to \cs{endnote@ii}, after saving the argument in \cs{@entoks}.
% \begin{macrocode}
\patchcmd{\@xendnote}
{\@endnotemark\@endnotetext}
{\afterassignment\endnote@ii\@entoks}
{}{}
% \end{macrocode}
% \begin{macrocode}
%</package>
% \end{macrocode}
%\theendnotes
%\Finale
|