Skip to content

Commit

Permalink
footnote reverse link (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldXiao authored Nov 11, 2023
1 parent 6f65b1f commit 7bcbc97
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/lib/init.btx
Original file line number Diff line number Diff line change
Expand Up @@ -1219,14 +1219,23 @@

\newcounter{actualfootnote}

\newcounter{footnoteorigin}

\newcounter{footnoteoriginref}

\def\@printfootnotes{}

\gdef\@footnoteorigincollection{}

\def\@footnotemark{%
\@inc{g.ctr-footnote}%
{%
\@settrue{text-sup}%
\@@set{ref-key}{footnote:{g.ctr-footnote}}%
\@ref{\thefootnote}%
\@setfalse{text-sup}%
\@footnoteorigin%
\@patch\@footnoteorigincollection{\@footnoteoriginref}%
}%
\@dec{g.ctr-footnote}%
}
Expand All @@ -1247,20 +1256,40 @@
\@defexpand\@patch\@printfootnotes{\theactualfootnote}%
\@patch\@printfootnotes{][}%
\@defexpand\@patch\@printfootnotes{\thefootnote}%
\@patch\@printfootnotes{]#1}%
\@patch\@printfootnotes{]}%
\@defexpand\@patch\@printfootnotes{\@footnoteorigincollection}%
\@patch\@printfootnotes{#1}%
}

\let\footnotemark\@footnotemark

\def\footnotetext#1{%
\@inc{g.ctr-footnote}%
\@footnotetext{#1}%
\gdef\@footnoteorigincollection{}%
}

\pdef\@footnoteorigin{%
\@inc{g.ctr-footnoteorigin}%
\@@def\@currentlabel{^}%
\@@set{ref-prefix}{o}%
\@@bmk%
\@@label{footnote-origin:{g.ctr-footnoteorigin}}%
}

\def\@footnoteoriginref{%
{
\@inc{g.ctr-footnoteoriginref}
\@@set{ref-key}{footnote-origin:{g.ctr-footnoteoriginref}}%
\@ref{\thefootnoteoriginref}%
}
}

\def\footnote#1{\footnotemark\footnotetext{#1}}

\def\printfootnotes{%
{%
\@@set{g.ctr-footnoteoriginref}{0}%
\@@set{g.list-classes}{footnotes}%
\begin{@list}%
\@printfootnotes%
Expand Down

0 comments on commit 7bcbc97

Please sign in to comment.