Created
December 15, 2016 19:52
-
-
Save bpj/e600553d1975882a423177b6b195f833 to your computer and use it in GitHub Desktop.
Load after endnotes, after hyperref to make endnote markers hyperlinks. I didn't write this. I just put it here to have a convenient place to grab it!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%% hyperendnotes.sty | |
\makeatletter | |
\newif\ifenotelinks | |
\newcounter{Hendnote} | |
% Redefining portions of endnotes-package: | |
\let\savedhref\href | |
\let\savedurl\url | |
\def\endnotemark{% | |
\@ifnextchar[\@xendnotemark{% | |
\stepcounter{endnote}% | |
\protected@xdef\@theenmark{\theendnote}% | |
\protected@xdef\@theenvalue{\number\c@endnote}% | |
\@endnotemark | |
}% | |
}% | |
\def\@xendnotemark[#1]{% | |
\begingroup\c@endnote#1\relax | |
\unrestored@protected@xdef\@theenmark{\theendnote}% | |
\unrestored@protected@xdef\@theenvalue{\number\c@endnote}% | |
\endgroup | |
\@endnotemark | |
}% | |
\def\endnotetext{% | |
\@ifnextchar[\@xendnotenext{% | |
\protected@xdef\@theenmark{\theendnote}% | |
\protected@xdef\@theenvalue{\number\c@endnote}% | |
\@endnotetext | |
}% | |
}% | |
\def\@xendnotenext[#1]{% | |
\begingroup | |
\c@endnote=#1\relax | |
\unrestored@protected@xdef\@theenmark{\theendnote}% | |
\unrestored@protected@xdef\@theenvalue{\number\c@endnote}% | |
\endgroup | |
\@endnotetext | |
}% | |
\def\endnote{% | |
\@ifnextchar[\@xendnote{% | |
\stepcounter{endnote}% | |
\protected@xdef\@theenmark{\theendnote}% | |
\protected@xdef\@theenvalue{\number\c@endnote}% | |
\@endnotemark\@endnotetext | |
}% | |
}% | |
\def\@xendnote[#1]{% | |
\begingroup | |
\c@endnote=#1\relax | |
\unrestored@protected@xdef\@theenmark{\theendnote}% | |
\unrestored@protected@xdef\@theenvalue{\number\c@endnote}% | |
\show\@theenvalue | |
\endgroup | |
\@endnotemark\@endnotetext | |
}% | |
\def\@endnotemark{% | |
\leavevmode | |
\ifhmode | |
\edef\@x@sf{\the\spacefactor}\nobreak | |
\fi | |
\ifenotelinks | |
\expandafter\@firstofone | |
\else | |
\expandafter\@gobble | |
\fi | |
{% | |
\Hy@raisedlink{% | |
\hyper@@anchor{Hendnotepage.\@theenvalue}{\empty}% | |
}% | |
}% | |
\hyper@linkstart{link}{Hendnote.\@theenvalue}% | |
\makeenmark | |
\hyper@linkend | |
\ifhmode | |
\spacefactor\@x@sf | |
\fi | |
\relax | |
}% | |
\long\def\@endnotetext#1{% | |
\if@enotesopen | |
\else | |
\@openenotes | |
\fi | |
\immediate\write\@enotes{% | |
\@doanenote{\@theenmark}{\@theenvalue}% | |
}% | |
\begingroup | |
\def\next{#1}% | |
\newlinechar='40 | |
\immediate\write\@enotes{\meaning\next}% | |
\endgroup | |
\immediate\write\@enotes{% | |
\@endanenote | |
}% | |
}% | |
\def\theendnotes{% | |
\immediate\closeout\@enotes | |
\global\@enotesopenfalse | |
\begingroup | |
\makeatletter | |
\edef\@tempa{`\string>}% | |
\ifnum\catcode\@tempa=12 | |
\let\@ResetGT\relax | |
\else | |
\edef\@ResetGT{\noexpand\catcode\@tempa=\the\catcode\@tempa}% | |
\@makeother\>% | |
\fi | |
\def\@doanenote##1##2##3>{% | |
\def\@theenmark{##1}% | |
\def\@theenvalue{##2}% | |
\par | |
\smallskip %<-small vertical gap between endnotes | |
\begingroup | |
\def\href{\expandafter\savedhref}% | |
\def\url{\expandafter\savedurl}% | |
\@ResetGT | |
\edef\@currentlabel{\csname p@endnote\endcsname\@theenmark}% | |
\enoteformat | |
}% | |
\def\@endanenote{% | |
\par\endgroup | |
}% | |
% Redefine, how numbers are formatted in the endnotes-section: | |
\renewcommand*\@makeenmark{% | |
\hbox{\normalfont\@theenmark~}% | |
}% | |
% header of endnotes-section | |
\enoteheading | |
% font-size of endnotes | |
\enotesize | |
\input{\jobname.ent}% | |
\endgroup | |
}% | |
\def\enoteformat{% | |
\rightskip\z@ | |
%\leftskip1.8em | |
\noindent | |
\hangindent .0 | |
\parindent | |
\leavevmode\llap{% | |
\setcounter{Hendnote}{\@theenvalue}% | |
\addtocounter{Hendnote}{-1}% | |
\refstepcounter{Hendnote}% | |
\ifenotelinks | |
\expandafter\@secondoftwo | |
\else | |
\expandafter\@firstoftwo | |
\fi | |
{\@firstofone}% | |
{\hyperlink{Hendnotepage.\@theenvalue}}% | |
{\makeenmark}% | |
}% | |
}% | |
% stop redefining portions of endnotes-package: | |
\makeatother | |
% Toggle switch in order to turn on/off back-links in the | |
% endnote-section: | |
\enotelinkstrue | |
%\enotelinksfalse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment