I was developing my latex code for the writing project and then I realized that this work must have hyperlinks to endnotes, which are ordered by section. Here is my code in a simple form (below). It has one line muted \let\footnote=\endnote. In this case the footnotes are not endnotes, but they do have hyperlinks (see screenshot at the bottom). If unmuted, this code is losing the hyperlinks to the endnotes. My question is how to have both (1) hyperlinks to endnotes, and (2) endnotes being at the end of the file and ordered by sections? Thanks!
\documentclass[]{article} \usepackage[ backend=biber, style=authoryear-icomp, natbib=true, url=true, doi=true, eprint=false ]{biblatex} \addbibresource{ref.bib} \usepackage[]{hyperref} \hypersetup{colorlinks=false} \usepackage{lipsum} \usepackage{endnotes,chngcntr} %--- Endnotes \counterwithin*{endnote}{section} \let\latexsection\section \makeatletter %changes the catcode of @ to 11 \renewcommand\enoteheading{ \setcounter{secnumdepth}{-2} \latexsection*{\notesname\markboth{NOTES}{}} \mbox{}\par\vskip-\baselineskip \let\@afterindentfalse\@afterindenttrue } \def\enotedivision#1#2{\@ifnextchar\enotedivision{}{#1{#2}}} \makeatother \RenewDocumentCommand{\section}{som}{% \IfBooleanTF{#1} {\latexsection*{#3}% \setcounter{endnote}{0}% \addtoendnotes{% \noexpand\enotedivision{\noexpand\subsubsection*} {\unexpanded{#3}}}% } {\IfNoValueTF{#2} {\latexsection{#3}} {\latexsection[#2]{#3}}% \addtoendnotes{% \noexpand\enotedivision{\noexpand\subsubsection*} {\thesection. \unexpanded{#3}}}% }% } %\let\footnote=\endnote \begin{document} \section{Foo} \lipsum[1]~\citep{beck2000}.\footnote{\lipsum[1]} \section{Boo} \lipsum[1]~\citet{sen1979}.\footnote{\lipsum[1]} \theendnotes \printbibliography \end{document} 