Debian Codegraph @

texmf-dist/source/latex/endnotes-hy/endnotes-hy.dtx

raw
1 % \iffalse
2 % makeindex -s gglo.ist -o endnotes-hy.gls endnotes-hy.glo
3 % makeindex -s gind.ist -o endnotes-hy.ind endnotes-hy.idx
4 %<*copyright>
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 %% endnotes-hy.sty package, %%
7 %% Copyright (C) 2020 %%
8 %% [email protected] [email protected] %%
9 %% %%
10 %% This program can redistributed and/or modified under %%
11 %% the terms of the LaTeX Project Public License %%
12 %% Distributed from CTAN archives in directory %%
13 %% macros/latex/base/lppl.txt; either version 1.2 of the %%
14 %% License, or (at your option) any later version. %%
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16 %</copyright>
17 %<package>\NeedsTeXFormat{LaTeX2e}
18 %<package>\ProvidesPackage{endnotes-hy}
19 %<package> [2020/04/08 v0.1 Enables hypertext links for endnotes]
20 %<*driver>
21 \documentclass{ltxdoc}
22 \usepackage[colorlinks,hyperindex=false,linktocpage,bookmarksnumbered]{hyperref}
23 \usepackage{calc}
24 \usepackage{endnotes-hy}
25 %\def\texorpdfstring#1#2{#1}
26 %\pdfstringdefDisableCommands{\let\\\textbackslash}
27 \OnlyDescription % comment out for implementation details
28 \EnableCrossrefs
29 \CodelineIndex
30 \RecordChanges
31 \gdef\brpr#1{\texttt{\char123\relax#1\char125\relax}}
32 \let\darg\brpr
33 \let\env\texttt
34 \let\opt\texttt
35 \let\app\textsf
36 \let\pkg\textsf
37 \def\EXCL{!}
38 \def\visispace{\symbol{32}}
39 \def\ameta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}}
40 \def\meta#1{\textsl{\texttt{#1}}}
41 \def\SUB#1{\ensuremath{{}_{\mbox{\scriptsize\ttfamily#1}}}}
42 \def\CMD#1{\textbackslash#1}
43 \makeatletter
44 \renewcommand\theparagraph{\texorpdfstring{\protect\P\protect\ }{\textparagraph}}
45 \renewcommand\thesubparagraph{\texorpdfstring{\protect\P\protect\P\protect\ }{\textparagraph\textparagraph}}
46 \renewcommand{\section}
47 {\renewcommand{\@seccntformat}[1]{\thesection\quad}%
48 \@startsection {section}{1}{\z@}%
49 {-3.5ex \@plus -1ex \@minus -.2ex}%
50 {2.3ex \@plus.2ex}%
51 {\normalfont\Large\bfseries}}
52 \renewcommand{\paragraph}
53 {\renewcommand{\@seccntformat}[1]{\theparagraph\unskip\,}%
54 \@startsection{paragraph}{4}{0pt}{6pt}{-3pt}{\bfseries}}
55 \renewcommand{\subparagraph}
56 {\renewcommand{\@seccntformat}[1]{\thesubparagraph\unskip\,}%
57 \@startsection{subparagraph}{5}{\parindent}{6pt}{-3pt}{\bfseries}}
58 \makeatother
59 \newbox\enbox
60 \InputIfFileExists{aebdocfmt.def}{\PackageWarning{endnotes-hy}{Inputting aebdocfmt.def}}
61 {\def\IndexOpt{\DescribeMacro}\def\IndexKey{\DescribeMacro}\let\setupFullwidth\relax
62 \PackageInfo{endnotes-hy}{aebdocfmt.def cannot be found}}
63 \begin{document}
64 \addtolength{\marginparwidth}{3pt}
65 \GetFileInfo{endnotes-hy.sty}
66 \title{The \textsf{endnotes-hy} Package}
67 \author{D. P. Story\\
68 Email: \texttt{[email protected]}}
69 \date{processed \today}
70 \maketitle
71 \setcounter{secnumdepth}{5}
72 \setcounter{tocdepth}{5}
73 \bgroup
74 \value{secnumdepth}=3
75 \value{tocdepth}=3
76 \tableofcontents
77 \egroup
78 \DocInput{endnotes-hy.dtx}
79 \IfFileExists{\jobname.ind}{\newpage\setupFullwidth\par\PrintIndex}{\paragraph*{Index} The index goes here. Execute
80 \begin{quote}\texttt{makeindex -s gind.ist -o endnotes-hy.ind endnotes-hy.idx}\end{quote}
81 on the command line and recompile
82 \texttt{endnotes-hy.dtx}.}
83 \IfFileExists{\jobname.gls}{\PrintChanges}{\paragraph*{Change History} The list of changes goes here. Execute
84 \begin{quote}
85 \texttt{makeindex -s gglo.ist -o endnotes-hy.gls endnotes-hy.glo}
86 \end{quote}
87 on the command line and recompile \texttt{endnotes-hy.dtx}.}
88 \end{document}
89 %</driver>
90 % \fi
91 % \MakeShortVerb{|}
92 % \InputIfFileExists{aebdonotindex.def}{\PackageInfo{web}{Inputting aebdonotindex.def}}
93 % {\PackageInfo{web}{cannot find aebdonotindex.def}}
94 % \begin{macrocode}
95 %<*package>
96 % \end{macrocode}
97 % \section{Introduction}
98 % This package is an extension of \href{https://ctan.org/pkg/endnotes}{\pkg{endnotes}}.
99 % \changes{v0.1}{2020/04/08}{First published version of this package.}
100 %
101 % \paragraph*{Background:} A colleague---a dedicated user of the
102 % \href{https://ctan.org/pkg/endnotes}{\pkg{endnotes}} package---complained to me
103 % (for some reason) that links created by \pkg{hyperref} do not point to the
104 % endnotes at the end of the file; for example, if we say
105 %\begin{quote}\ttfamily
106 % \string\endnote\darg{\string\label\darg{\ameta{name}}\ameta{text}}
107 %\end{quote}
108 % then any link, such as
109 % \cs{hyperref[\ameta{name}]\darg{endnote\string~\string\ref*\darg{\ameta{name}}}} jumps
110 % to the most recent anchor (\texttt{Doc-Start}, for example); no hypertext
111 % anchor is created where the endnote is inserted into the document. This short
112 % package is an attempt to rectify this problem.
113 %
114 %\paragraph*{Syntax:}
115 % The \cs{endnote} command has been modified to conform to the following syntax:
116 %\begin{quote}
117 % \cs{endnote*[\ameta{num}]\darg{\ameta{text}}\string\label\darg{\ameta{name}}}
118 %\end{quote}
119 % Refer to the documentation of the \href{https://ctan.org/pkg/endnotes}{\pkg{endnotes}} package for a description of the \cs{endnote}
120 % command and its \ameta{num} and \ameta{text} arguments.
121 % If the \texttt*-option (new syntax) is used, the endnote mark is not placed, but the endnote
122 % is written to the \texttt{ENT} file.\endnote*{An endnote created with \texttt*-option}\label{en:en*}
123 % Such a ``secret'' endnote can be referred to using standard \pkg{hyperref} commands,
124 % see the \autoref{en:en*} on page~\pageref{en:en*} for more information. The placement of the \cs{label} has
125 % changed for this package as well. To define an endnote label, place \cs{label\darg{name}} following
126 % the \cs{endnote} command, a more traditional location. This was done to get access to the \ameta{name}, if it exist.
127 % This enables the package to place a hypertext link around the endnote mark.\endnote{This is normal endnote}\label{en:normal}
128 % The optional \ameta{num} can be used
129 % to write special endnotes.{\def\theendnote{N\arabic{endnote}}\endnote[1]{This is special endnote}\label{en:specen}}
130 % As a side benefit to this new syntax, you can place verbatim text into an
131 % endnote.\setbox\enbox\hbox{\verb!%^$^&$%^&!}\edef\VertTxti{\unhbox\enbox}\endnote{Some verbatim text \VertTxti}\label{en:verb}
132 % If there is no \cs{label} following \cs{endnote}, no hypertext link is created.\endnote{No hypertext link created}
133 %
134 % \paragraph*{Note:} This package will work correctly without the \pkg{hyperref} package (of course, no links).
135 % The advantage of using \pkg{endnotes-hy} without \pkg{hyperref} is to use the extended syntax:
136 % \cs{endnote*[\ameta{num}]\darg{\ameta{text}}\string\label\darg{\ameta{name}}}
137 %
138 % \section{Required packages}
139 %
140 % \begin{macrocode}
141 \RequirePackage{endnotes}
142 % \end{macrocode}
143 % Require \pkg{etoolbox} because we redefine several commands using \cs{patchcmd}; this is not
144 % really necessary, we could have redefined the whole command instead.
145 % \begin{macrocode}
146 \RequirePackage{etoolbox}
147 % \end{macrocode}
148 % \section{Package code}
149 % We allow the author not to use \pkg{hyperref}; this enables the use of the extended
150 % syntax of the \cs{endnote} command.
151 % \begin{macrocode}
152 \newcommand\hyperref@nohy[2][]{#2}
153 \AtBeginDocument{\@ifundefined{hyperref}{\let\hyperref@en\hyperref@nohy
154 \let\phantomendnote\relax}
155 {\let\hyperref@en\hyperref}}
156 % \end{macrocode}
157 % \begin{macro}{\phantomendnote}
158 % The key is to create an hyperref anchor to reference; this definition is based on
159 % \cs{phantomsection} of \pkg{hyperref}. This is used internally.
160 % \begin{macrocode}
161 \def\phantomendnote{%
162 \Hy@MakeCurrentHrefAuto{endnote}%
163 \Hy@raisedlink
164 {\hyper@anchorstart{endnote.\@theenmark}\hyper@anchorend}}
165 \def\endnoteautorefname{endnote}
166 % \end{macrocode}
167 % \end{macro}
168 % Redefinition of \DescribeMacro{\theendnotes}\cs{theendnotes}
169 % \begin{macrocode}
170 \patchcmd{\theendnotes}{\enoteformat}
171 {\phantomendnote\def\@currentHref{endnote.\@theenmark}%
172 \enoteformat}{}{}
173 % \end{macrocode}
174 % Redefine \DescribeMacro\endnote\cs{endnote} to take an optional \texttt{*}, if this option is used, the mark does not appear
175 % in the text. This enables us to easily define an endnote and refer to it even with multiple paragraphs.
176 % I didn't like the syntax of inserting the \cs{label} within the argument of \cs{endnote}, this seems to have
177 % problems. The new syntax is as follows:\begin{quote}
178 % Syntax: \cs{endnote*[\ameta{num}]\darg{\ameta{text}}\string\label\darg{\ameta{name}}}\end{quote}
179 % This new syntax could be a problem if an author has already used \pkg{endnotes} and then converts
180 % to \pkg{endnotes-hy}. In \pkg{endnotes} the \texttt*-option is note defined and the \cs{label}
181 % command is typically placed within the argument of the \darg{\ameta{text}}. Labels would have to be moved
182 % to a position following \darg{\ameta{text}}.
183 %
184 % To obtain this syntax, we need several stages of parsing. The major problem is to get the
185 % label name in time to build a hyperref link around \cs{@endnotemark}.
186 % \begin{macrocode}
187 \newtoks\@entoks
188 \def\endnote{\let\@encurrlabelname\@empty
189 \@ifstar{\let\@noMrk1\endnote@i}{\let\@noMrk0\endnote@i}}
190 \def\endnote@i{\@ifnextchar[%]
191 {\@xendnote}
192 {\stepcounter{endnote}%
193 \protected@xdef\@theenmark{\theendnote}%
194 % \end{macrocode}
195 % We placed the \darg{text} argument into a token register, this removes
196 % that argument from the input stream, and allows us to see of the next token
197 % is \cs{label}, if so, we get the label name argument.
198 % \begin{macrocode}
199 \afterassignment\endnote@ii\@entoks}}
200 % \end{macrocode}
201 % If the next token is \cs{label}, get the label name with \cs{endnote@iii},
202 % otherwise, move on to \cs{endnote@iv}, the final step.
203 % \begin{macrocode}
204 \def\endnote@ii{\@ifnextchar\label{\endnote@iii}{\endnote@iv}}
205 \def\endnote@iii\label#1{\def\@encurrlabelname{#1}\endnote@iv}
206 % \end{macrocode}
207 % If the flag \cs{@noMrk} is 0 (mark is typeset), and if there
208 % is a label name, we make an hypertext link.
209 % \begin{macrocode}
210 \def\endnote@iv{%
211 \if\@noMrk0\relax
212 \ifx\@encurrlabelname\@empty
213 \@endnotemark
214 \else
215 \hyperref@en[\@encurrlabelname]{\@endnotemark}%
216 \fi
217 \fi
218 % \end{macrocode}
219 % Finish by expanding \cs{@endnotetext} with its argument
220 % that was saved in the \cs{@entoks} register.
221 % \begin{macrocode}
222 \expandafter\@endnotetext\expandafter{\the\@entoks}}
223 % \end{macrocode}
224 % We patch into \DescribeMacro\@endnotetext\cs{@endnotetext} just after \verb~\def\next{#1}~.
225 % If there was a \cs{label}, we insert it back into the argument
226 % of \cs{endnote}.
227 % \begin{macrocode}
228 \patchcmd{\@endnotetext}
229 {\def\next{#1}}
230 {\ifx\@encurrlabelname\@empty
231 \def\next{#1}\else
232 \edef\x{\noexpand\label{\@encurrlabelname}}%
233 \expandafter\def\expandafter\next\expandafter{\x#1}\fi}{}{}
234 % \end{macrocode}
235 % If \cs{endnote} has an optional argument, the flow passes to
236 % \DescribeMacro\xendnote\cs{xendnote}. We replace
237 % \verb~\@endnotemark\@endnotetext~ by redirecting flow to
238 % to \cs{endnote@ii}, after saving the argument in \cs{@entoks}.
239 % \begin{macrocode}
240 \patchcmd{\@xendnote}
241 {\@endnotemark\@endnotetext}
242 {\afterassignment\endnote@ii\@entoks}
243 {}{}
244 % \end{macrocode}
245 % \begin{macrocode}
246 %</package>
247 % \end{macrocode}
248 %\theendnotes
249 %\Finale