texlive[70745] Master/texmf-dist: multifootnote (24mar24)

commits+karl at tug.org commits+karl at tug.org
Sun Mar 24 21:05:18 CET 2024


Revision: 70745
          https://tug.org/svn/texlive?view=revision&revision=70745
Author:   karl
Date:     2024-03-24 21:05:18 +0100 (Sun, 24 Mar 2024)
Log Message:
-----------
multifootnote (24mar24)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/multifootnote/README.md
    trunk/Master/texmf-dist/doc/latex/multifootnote/multifootnote-doc.pdf
    trunk/Master/texmf-dist/doc/latex/multifootnote/multifootnote-doc.tex
    trunk/Master/texmf-dist/tex/latex/multifootnote/multifootnote.sty

Modified: trunk/Master/texmf-dist/doc/latex/multifootnote/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/multifootnote/README.md	2024-03-24 20:05:09 UTC (rev 70744)
+++ trunk/Master/texmf-dist/doc/latex/multifootnote/README.md	2024-03-24 20:05:18 UTC (rev 70745)
@@ -1,11 +1,16 @@
-<!-- Copyright (C) 2022 by Jinwen XU -->
+<!-- Copyright (C) 2022-2024 by Jinwen XU -->
 
 # `multifootnote` - Multiple numbers for the same footnote
 
-The package `multifootnote` provides several commands for generating footnotes with multiple numbers (or marks, if you prefer).
+The package `multifootnote` provides several commands for generating footnotes which correspond to multiple footnote numbers (or marks, if you prefer).
 
+In some cases, you may wish for certain footnotes to correspond to several places in your text. The traditional solution usually involves writing the same footnote mark multiple times at the corresponding places. However, this approach makes it difficult to see at once how many times a footnote has been referred to. Therefore, the current package proposes another method: writing the footnote marks in linear order, and allowing a footnote text to match several of these marks.
+
 *For more information, please refer to its documentation.*
 
+> Package dependencies: [*`hyperref`*](https://ctan.org/pkg/hyperref), [`refcount`](https://ctan.org/pkg/refcount).
+
+
 # License
 
 This work is released under the LaTeX Project Public License, v1.3c or later.

Modified: trunk/Master/texmf-dist/doc/latex/multifootnote/multifootnote-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/multifootnote/multifootnote-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/multifootnote/multifootnote-doc.tex	2024-03-24 20:05:09 UTC (rev 70744)
+++ trunk/Master/texmf-dist/doc/latex/multifootnote/multifootnote-doc.tex	2024-03-24 20:05:18 UTC (rev 70745)
@@ -2,8 +2,10 @@
 
 \usepackage{ProjLib}
 
-\usepackage[left indent]{multifootnote}
+\setmonofont[Scale=.9]{Iosevka}
 
+\usepackage[left indent, backref]{multifootnote}
+
 %%================================
 %% For typesetting code
 %%================================
@@ -25,9 +27,9 @@
     breaklines = true,
     frame = lines,
     backgroundcolor = \color{code-background},
-    flexiblecolumns = true,
+    basewidth = .5em,
     escapeinside = {(*}{*)},
-    alsoletter = {_,:},
+    alsoletter = {_:},
     % numbers = left,
     % firstnumber = last,
     numberstyle = \scriptsize\ttfamily,
@@ -40,13 +42,20 @@
     texcsstyle =* \color{code-main},
     moretexcs =
       {
+        multifootnotemark,
         multifootnotetext,
-        multifootnotemark,
         multifootnotetag,
         multifootnotetagtext,
         multifootnote,
         footnotenumber,
         footnotetag,
+        multifootnotemarkmanual,
+        multifootnotetextmanual,
+        multifootnotetagmanual,
+        multifootnotetagtextmanual,
+        multifootnotemanual,
+        footnotenumbermanual,
+        footnotetagmanual,
       }
 }
 \lstset{% LaTeX3 commands
@@ -59,8 +68,8 @@
 \lstnewenvironment{code}{\setstretch{1.05}\LocallyStopLineNumbers}{\ResumeLineNumbers\vspace{-.3\baselineskip}\vspace{-.5\parskip}}
 \lstnewenvironment{code*}{\setstretch{1.05}\lstset{numbers=left}\LocallyStopLineNumbers}{\ResumeLineNumbers\vspace{-.3\baselineskip}\vspace{-.5\parskip}}
 
-\newcommand{\packageoption}[1]{\texttt{\textcolor{code-option}{#1}}}
-\newcommand{\commandoption}[1]{\texttt{\textcolor{code-keys}{#1}}}
+\newcommand{\packageoption}[1]{\textcolor{code-option}{\texttt{#1}}}
+\newcommand{\commandoption}[1]{\textcolor{code-keys}{\texttt{#1}}}
 
 %%================================
 %% tip
@@ -94,7 +103,7 @@
 
 \begin{document}
 
-\def\PackageVersion{2022/05/31}
+\def\PackageVersion{2024/03/24}
 
 \title{\multifootnotepackage{}\\\smallskip\itshape Multiple numbers for the same footnote}
 \author{Jinwen XU}
@@ -105,12 +114,16 @@
 
 \begin{abstract}
     \raggedleft
-    The package \multifootnotepackage{} provides two groups of commands for \\generating footnotes with multiple numbers (or marks, if you prefer).
+    The package \multifootnotepackage{} provides two groups of commands for generating\\footnotes which correspond to multiple numbers (or marks, if you prefer).
 \end{abstract}
 
 
-\vspace*{-.5\baselineskip}
+\addtocounter{section}{-1}
+\section{Introduction}
 
+In some cases, you may wish for certain footnotes to correspond to several places in your text. The traditional solution usually involves writing the same footnote mark multiple times at the corresponding places. However, this approach makes it difficult to see at once how many times a footnote has been referred to. Therefore, the current package proposes another method: writing the footnote marks in linear order, and allowing a footnote text to match several of these marks.
+
+
 \section{How to load it}
 
 You can simply load the current package with:
@@ -122,6 +135,10 @@
 \medskip
 It has the following options:
 \begin{itemize}[label=,leftmargin=1.25em,itemindent=-1.25em]
+    \item \packageoption{backref}
+        \begin{itemize}
+            \item Enable backward referencing from the footnotes.
+        \end{itemize}
     \item \packageoption{left align}
         \begin{itemize}
             \item Align the footnotes to the left.
@@ -132,8 +149,14 @@
             \item Similar to \packageoption{left align}, but with an indentation \meta{length}, default to be \texttt{1.5em}.
             \item Alternative names: \packageoption{left-indent} \,$|$\, \packageoption{leftindent}
         \end{itemize}
+    \item \packageoption{manual}
+        \begin{itemize}
+            \item Use the manual version of the commands. This means that you shall need to manually specify the place where the footnote text should print (by placing the \lstinline|\multifootnote| commands in the appropriate places). You should only use this option when the automatic result does not fit your need.
+            \item Alternative names: \packageoption{manual-mode} \,$|$\, \packageoption{manual mode} \,$|$\, \packageoption{manualmode}
+        \end{itemize}
 \end{itemize}
 
+\clearpage
 \section{How to use it}
 
 Here are two approaches for producing a footnote with multiple numbers, and in either of them, there are two commands involved.
@@ -180,13 +203,18 @@
     \lstinline|\multifootnote| appears in both approaches for producing footnote text: it shall be interpreted as \lstinline|\multifootnotetext| if the optional argument is a comma-separated list, and as \lstinline|\multifootnotetagtext| if not. See the examples below.
 \end{tip}
 
-\bigskip
+\begin{tip}[Attention]
+    Notice that in the first approach, \meta{label} appears as an optional argument of \lstinline|\footnotenumber[|\meta{label}\lstinline|]| (thus square brackets); while in the second approach, \meta{tag} is a mandatory argument of \lstinline|\footnotetag{|\meta{tag}\lstinline|}| (thus curly brackets).
+\end{tip}
+
+\vfill
 \begin{center}
     \itshape
     If you're feeling confused, don't worry. Let's now take a look at some examples.
 \end{center}
+\vfill
 
-
+\clearpage
 \section{Examples}
 
 Here are two examples of usage, with the package option \textquote{\packageoption{left indent}} enabled.
@@ -202,10 +230,13 @@
 
 Result:
 
-\fbox{Lorem ipsum\footnotenumber[fn1] dolor\footnotenumber[fn2] sit amet\footnotenumber[fn3], consectetur\footnotenumber[fn4] adipiscing elit\footnotenumber[fn5].}
+\vspace{.5\baselineskip}\hrule\vspace{-.25\baselineskip}
+Lorem ipsum\footnotenumber[fn1] dolor\footnotenumber[fn2] sit amet\footnotenumber[fn3], consectetur\footnotenumber[fn4] adipiscing elit\footnotenumber[fn5].
+\vspace{.25\baselineskip}\hrule
 \multifootnote[fn1,fn2,fn5]{This is a footnote for demonstration.}
 \multifootnote[fn1,fn3,fn4]{This is another footnote for demonstration.}
 
+\medskip
 \subsection{The second approach}
 
 \medskip
@@ -217,20 +248,48 @@
 
 Result:
 
-\fbox{Lorem ipsum\footnotetag{fntag1,fntag2} dolor\footnotetag{fntag1} sit amet\footnotetag{fntag2}, consectetur\footnotetag{fntag2} adipiscing elit\footnotetag{fntag1}.}
+\vspace{.5\baselineskip}\hrule\vspace{-.25\baselineskip}
+Lorem ipsum\footnotetag{fntag1,fntag2} dolor\footnotetag{fntag1} sit amet\footnotetag{fntag2}, consectetur\footnotetag{fntag2} adipiscing elit\footnotetag{fntag1}.
+\vspace{.25\baselineskip}\hrule
 \multifootnote[fntag1]{This is a footnote for demonstration.}
 \multifootnote[fntag2]{This is another footnote for demonstration.}
 
+\bigskip
 \begin{tip}
     The second approach is more recommended, as it involves fewer labels, and you shall not need to worry about the order of footnote marks in \lstinline|\multifootnote|.
 \end{tip}
 
+\begin{tip}
+    By default, it doesn't quite matter where you put \lstinline|\multifootnote|. However, if you have enabled the package option \packageoption{manual mode}, then the corresponding footnote text shall be added to the current page immediately at where you write \lstinline|\multifootnote|.
+\end{tip}
+
+\bigskip
 \begin{tip}[Attention]
-    Notice that in the first approach, \meta{label} appears as an optional argument of \lstinline|\footnotenumber[|\meta{label}\lstinline|]| (thus square brackets); while in the second approach, \meta{tag} is a mandatory argument of \lstinline|\footnotetag{|\meta{tag}\lstinline|}| (thus curly brackets).
+    You should choose an approach you like and stick to it in your document. It is not recommended to use them both within the same document!
 \end{tip}
 
 
-\bigskip
+\clearpage
+\section{Regarding the manual version}\label{sec:manual-mode}
+
+Though the manual mode is not very convenient to be used by default (via the package option \packageoption{manual}), it is still useful to be able to switch to this mode in some cases. For example, the automatic mode would not work within a box, as with the usual footnotes; also, the automatic mode would not work quite properly when the footnote text is too long to fit into the current page. In such situations, you could switch to the manual mode temporarily, with which you could write the \lstinline|\multifootnote|, and thus typeset the footnote text outside the box.
+
+To do this, you just need to add the suffix \textquote{\lstinline|manual|} to the commands you are using, that is:
+\begin{itemize}
+    \item \lstinline|\multifootnotemarkmanual| and \lstinline|\multifootnotetextmanual|
+\end{itemize}
+for the first approach, and
+\begin{itemize}
+    \item \lstinline|\multifootnotetagmanual| and \lstinline|\multifootnotetagtextmanual|
+\end{itemize}
+for the second approach. Of course, we still have the alternative names to them:
+\begin{itemize}
+    \item \lstinline|\footnotenumbermanual| for \lstinline|\multifootnotemarkmanual|,
+    \item \lstinline|\footnotetagmanual| for \lstinline|\multifootnotetagmanual|, and
+    \item \lstinline|\multifootnotemanual| for \lstinline|\multifootnotetextmanual| or \lstinline|\multifootnotetagtextmanual|.
+\end{itemize}
+
+
 \section{Acknowledgement}
 
 This package arises from a question (\href{https://tex.stackexchange.com/q/645330}{\texttt{645330}}) on \texttt{TeX.StackExchange}. The author thanks user \href{https://tex.stackexchange.com/users/270985}{\textsf{@Bolzano}} for bringing up the question of producing such footnotes.
@@ -239,11 +298,14 @@
 
 The author also wishes to thank user \href{https://tex.stackexchange.com/users/213149}{\textsf{@antshar}} for proposing the second approach. The code is surprisingly simple but works just as fine as that of the first approach.
 
+During the creation and improvement of this package, the author benefited from numerous helps and inspirations from \texttt{TeX.StackExchange}, which is greatly appreciated.
+
 \section{Known issues}
 
 \begin{itemize}
     % \item When package \textsf{hyperref} is loaded, hyperlinks to those footnotes generated by the commands here cannot point to the correct place.
-    \item \multifootnotepackage{} is not compatible with the package \textsf{footnotebackref}.
+    \item \multifootnotepackage{} is not compatible with the package \textsf{footnotebackref}. However, this is not a serious problem: with the package option \packageoption{backref}, you should be able to get a similar result for which \textsf{footnotebackref} is supposed to achieve.
+    \item The automatic mode cannot deal with the situation where the footnote text is printed across pages. One should consider using the manual mode in this case, as mentioned in~\S\,\labelcref{sec:manual-mode}. However, it might be preferable to use endnote instead of footnote when there are too many footnotes or when the intended footnote text is too long.
 \end{itemize}
 
 \medskip

Modified: trunk/Master/texmf-dist/tex/latex/multifootnote/multifootnote.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/multifootnote/multifootnote.sty	2024-03-24 20:05:09 UTC (rev 70744)
+++ trunk/Master/texmf-dist/tex/latex/multifootnote/multifootnote.sty	2024-03-24 20:05:18 UTC (rev 70745)
@@ -1,5 +1,5 @@
 %%
-%% Copyright (C) 2022 by Jinwen XU
+%% Copyright (C) 2022-2024 by Jinwen XU
 %% ------------------------------------
 %%
 %% This file may be distributed and/or modified under the conditions of
@@ -9,11 +9,10 @@
 %%
 %%    http://www.latex-project.org/lppl.txt
 %%
-\NeedsTeXFormat{LaTeX2e}[2020-10-01]
-\RequirePackage{l3keys2e}
+\NeedsTeXFormat{LaTeX2e}[2022-06-01]
 \ProvidesExplPackage
   {multifootnote}
-  {2022/05/31} {}
+  {2024/03/24} {}
   {Multiple numbers for the same footnote}
 
 \msg_new:nnn { multifootnote }
@@ -37,6 +36,9 @@
 
 \keys_define:nn { multifootnote }
   {
+    , backref       .bool_set:N = \l__multifootnote_backref_bool
+    , backref       .initial:n  = { false }
+
     , left-align    .bool_set:N = \l__multifootnote_left_align_bool
     , left-align    .initial:n  = { false }
     , left~align    .bool_set:N = \l__multifootnote_left_align_bool
@@ -56,10 +58,24 @@
                                     \dim_set:Nn \l__multifootnote_left_indent_dim { #1 }
                                   }
     , left indent   .default:n  = { 1.5em }
+
+    , manual        .bool_set:N = \l__multifootnote_manual_mode_bool
+    , manual        .initial:n  = { false }
+    , manual-mode   .bool_set:N = \l__multifootnote_manual_mode_bool
+    , manual~mode   .bool_set:N = \l__multifootnote_manual_mode_bool
+    , manual mode   .bool_set:N = \l__multifootnote_manual_mode_bool
+
     , unknown       .code:n     = {}
   }
-\ProcessKeysOptions { multifootnote }
+\ProcessKeyOptions [ multifootnote ]
 
+\bool_if:NT \l__multifootnote_backref_bool
+  {
+    \RequirePackage { hyperref }
+  }
+
+\RequirePackage { refcount }
+
 \cs_new_protected:Nn \multifootnote_make_footnote_left_align:n
   {
     \renewcommand { \@makefntext } [1]
@@ -83,8 +99,26 @@
     \multifootnote_make_footnote_left_align:n { \l__multifootnote_left_indent_dim }
   }
 
+\cs_generate_variant:Nn \iow_now:Nn { ce }
+\cs_generate_variant:Nn \clist_put_right:Nn { ce }
+
+\tl_new:N \l__multifootnote_tmp_tl
+\seq_new:N \l__multifootnote_tmp_seq
+\clist_new:N \l__multifootnote_tmp_clist
+
+% get the total page number
+\hook_gput_code:nnn { enddocument } { multifootnote }
+  {
+    \label{multifootnote_last-page}
+  }
+\int_new:N \g_multifootnote_total_page_int
+\hook_gput_code:nnn { begindocument } { multifootnote }
+  {
+    \int_gset:Nn \g_multifootnote_total_page_int { \getpagerefnumber{multifootnote_last-page} }
+  }
+
 % First approach
-\NewDocumentCommand \multifootnotemark { O{} }
+\NewDocumentCommand \multifootnotemarkmanual { O{} }
   {
     \footnotemark
     \group_begin:
@@ -92,69 +126,265 @@
         {
           \addtocounter { footnote } { -1 }
           \refstepcounter { footnote }
+          \label { multifootnote-mark-#1 }
           \@ifpackageloaded { hyperref }
             {
               \cs_gset_eq:NN \@currentHref \Hy at footnote@currentHref
             } {}
-          \label { #1 }
+          \label { multifootnote-#1 }
         }
     \group_end:
   }
-\NewCommandCopy \footnotenumber \multifootnotemark
+\NewCommandCopy \footnotenumbermanual \multifootnotemarkmanual
 
-\NewDocumentCommand \multifootnotetext { O{} m }
+\NewDocumentCommand \multifootnotetextmanual { O{} m }
   {
     \group_begin:
-      \clist_clear:N \l_tmpa_clist
-      \clist_clear:N \l_tmpb_clist
-      \tl_if_blank:nF { #1 }
+      \tl_if_blank:nTF { #1 }
         {
+          \footnotetext { #2 }
+        }
+        {
+          \clist_clear:N \l_tmpa_clist
+          \clist_clear:N \l_tmpb_clist
           \clist_map_inline:nn { #1 }
             {
               \@ifpackageloaded { hyperref }
                 {
-                  \clist_put_right:Nn \l_tmpa_clist
-                    { \ref*{ ##1 } }
+                  \bool_if:NTF \l__multifootnote_backref_bool
+                    {
+                      \clist_put_right:Nn \l_tmpa_clist
+                        { \hyperref[multifootnote-mark-##1]{ \ref*{ multifootnote-##1 } } }
+                    }
+                    {
+                      \clist_put_right:Nn \l_tmpa_clist
+                        { \ref*{ multifootnote-##1 } }
+                    }
                   \clist_put_right:Nn \l_tmpb_clist
-                    { \Hy at raisedlink { \hypertarget { \getrefbykeydefault{##1}{anchor}{Doc-Start} } {} } }
+                    { \Hy at raisedlink { \hypertarget { \getrefbykeydefault{multifootnote-##1}{anchor}{Doc-Start} } {} } }
                 }
                 {
                   \clist_put_right:Nn \l_tmpa_clist
-                    { \ref { ##1 } }
+                    { \ref { multifootnote-##1 } }
                 }
             }
           \def \thefootnote { \clist_use:Nn \l_tmpa_clist { , \skip_horizontal:n { \l_multifootnote_space_after_comma_dim } } }
+          \@ifpackageloaded { hyperref }
+            {
+              \xdef \Hy at footnote@currentHref { x\Hy at footnote@currentHref }
+            } {}
+          \footnotetext { \clist_use:Nn \l_tmpb_clist {} \ignorespaces #2 }
         }
-      \@ifpackageloaded { hyperref }
+    \group_end:
+  }
+
+\seq_new:N \g__multifootnote_mark_internal_seq
+\cs_new:Nn \__multifootnote_process_per_page_mark:nnnN
+  % #1 = labels
+  % #2 = footnote text
+  % #3 = actual page number
+  % #4 = a macro to store the result
+  {
+    \tl_gclear:N #4
+    \clist_clear:N \l_tmpa_clist
+    \clist_map_inline:nn { #1 }
+      {
+        % only keep those labels that appear on the current page
+        \str_if_eq:eeT { #3 } { \getpagerefnumber{multifootnote-mark-##1} }
+          {
+            \clist_put_right:Nn \l_tmpa_clist { ##1 }
+          }
+      }
+    \clist_if_empty:NF \l_tmpa_clist
+      {
+        \tl_gput_right:No #4 { \exp_after:wN { \l_tmpa_clist } }
+        \tl_gput_right:Nn #4 { { #2 } }
+      }
+  }
+\hook_gput_code:nnn { begindocument } { multifootnote/mark }
+  {
+    \int_step_inline:nn { \int_eval:n { \g_multifootnote_total_page_int } }
+      {
+        % generate the per page mark-footnotetext sequences
+        % \tl_show:n { g__multifootnote_mark_internal_page_ #1 _seq }
+        \seq_new:c { g__multifootnote_mark_internal_page_ #1 _seq }
+        \seq_new:c { g__multifootnote_mark_internal_page_ #1 _recorded_seq }
+        % keep only those labels appeared on the current page
+        \seq_clear:N \l__multifootnote_tmp_seq
+        \seq_map_inline:cn { g__multifootnote_mark_internal_seq }
+          {
+            % \tl_show:n { TEST:~##1 }
+            \__multifootnote_process_per_page_mark:nnnN ##1 { #1 } \l__multifootnote_tmp_tl
+            \tl_if_empty:NF \l__multifootnote_tmp_tl
+              {
+                \seq_put_right:No \l__multifootnote_tmp_seq { \l__multifootnote_tmp_tl }
+              }
+          }
+        \seq_gset_eq:cN { g__multifootnote_mark_internal_page_ #1 _seq } \l__multifootnote_tmp_seq
+        % \seq_show:c { g__multifootnote_mark_internal_page_ #1 _seq }
+      }
+  }
+
+\NewDocumentCommand \multifootnotemark { O{} }
+  {
+    % print the footnote mark
+    \footnotemark
+    \group_begin:
+      \tl_if_blank:nF { #1 }
         {
-          \xdef \Hy at footnote@currentHref { x\Hy at footnote@currentHref }
-        } {}
-      \footnotetext { \clist_use:Nn \l_tmpb_clist {} \ignorespaces #2 }
+          \addtocounter { footnote } { -1 }
+          \refstepcounter { footnote }
+          \label { multifootnote-mark-#1 }
+          \@ifpackageloaded { hyperref }
+            {
+              \cs_gset_eq:NN \@currentHref \Hy at footnote@currentHref
+            } {}
+          \label { multifootnote-#1 }
+        }
     \group_end:
+    % print the corresponding footnote text
+    \tl_if_blank:nF { #1 }
+      {
+        \tl_set:Ne \l__multifootnote_tmp_tl { \getpagerefnumber{multifootnote-mark-#1} }
+        % \tl_show:N \l__multifootnote_tmp_tl
+        % \seq_show:c { g__multifootnote_mark_internal_page_ \l__multifootnote_tmp_tl _seq }
+        \seq_map_inline:cn { g__multifootnote_mark_internal_page_ \l__multifootnote_tmp_tl _seq }
+          {
+            % \tl_show:n { TEST:~ { #1 } ##1 }
+            \seq_if_in:cnF { g__multifootnote_mark_internal_page_ \l__multifootnote_tmp_tl _recorded_seq } { ##1 }
+              {
+                % \tl_show:n { TEST:~ { #1 } ##1 }
+                \__multifootnote_print_footnotetext:nnnnn { #1 } ##1
+                  {
+                    % record the current item
+                    \seq_gput_right:cn { g__multifootnote_mark_internal_page_ \l__multifootnote_tmp_tl _recorded_seq } { ##1 }
+                    % \seq_show:c { g__multifootnote_mark_internal_page_ \l__multifootnote_tmp_tl _recorded_seq }
+                  } {}
+                  {} {} % the two extra empty groups are added for safety
+              }
+          }
+      }
   }
+\cs_new:Nn \__multifootnote_print_footnotetext:nnnnn
+  % #1 = a given label
+  % #2 = labels
+  % #3 = footnote text
+  % #4 = code when the footnote text is indeed printed
+  % #5 = fallback code when the footnote text does not get printed
+  {
+    % \tl_show:n { TEST:~ { #1 } { #2 } { #3 } }
+    % \clist_if_in:nnTF { #2 } { #1 } { \tl_show:n { TEST:~ {#1}~is~in~{#2}. } } { \tl_show:n { TEST:~ {#1}~is~NOT~in~{#2}. } }
+    \clist_if_in:nnTF { #2 } { #1 }
+      {
+        \clist_clear:N \l_tmpa_clist
+        \clist_clear:N \l_tmpb_clist
+        % \clist_show:n { #2 }
+        \clist_map_inline:nn { #2 }
+          {
+            \@ifpackageloaded { hyperref }
+              {
+                \bool_if:NTF \l__multifootnote_backref_bool
+                  {
+                    \clist_put_right:Nn \l_tmpa_clist
+                      { \hyperref[multifootnote-mark-##1]{ \ref*{ multifootnote-##1 } } }
+                  }
+                  {
+                    \clist_put_right:Nn \l_tmpa_clist
+                      { \ref*{ multifootnote-##1 } }
+                  }
+                \clist_put_right:Nn \l_tmpb_clist
+                  { \Hy at raisedlink { \hypertarget { \getrefbykeydefault{multifootnote-##1}{anchor}{Doc-Start} } {} } }
+              }
+              {
+                \clist_put_right:Nn \l_tmpa_clist
+                  { \ref { multifootnote-##1 } }
+              }
+          }
+        % \clist_show:N \l_tmpa_clist
+        \group_begin:
+          \def \thefootnote { \clist_use:Nn \l_tmpa_clist { , \skip_horizontal:n { \l_multifootnote_space_after_comma_dim } } }
+          \@ifpackageloaded { hyperref }
+            {
+              \xdef \Hy at footnote@currentHref { x\Hy at footnote@currentHref }
+            } {}
+          \footnotetext { \clist_use:Nn \l_tmpb_clist {} \ignorespaces #3 }
+        \group_end:
+        #4
+      }
+      {
+        #5
+      }
+  }
+\NewCommandCopy \footnotenumber \multifootnotemark
 
+\NewDocumentCommand \multifootnotetext { O{} m }
+  {
+    \tl_if_blank:nTF { #1 }
+      {
+        \footnotetext { #2 }
+      }
+      {
+        \iow_now:cn { @auxout }
+          {
+            \@multifootnote at add@to at mark@text at list { #1 } { #2 }
+          }
+      }
+  }
+\NewDocumentCommand \@multifootnote at add@to at mark@text at list { m m }
+  {
+    \seq_gput_right:Nn \g__multifootnote_mark_internal_seq { { #1 } { #2 } }
+  }
+
 % Second approach
-\NewDocumentCommand \multifootnotetag { m }
+\int_new:N \g__multifootnote_tag_footnotemark_counter_int
+
+\NewDocumentCommand \multifootnotetagmanual { m }
   {
     \footnotemark
-    \group_begin:
-      \def \thefootnote {}
-      \footnotetext { \vspace { -\baselineskip } }
-    \group_end:
+    \@ifpackageloaded { hyperref }
+      {
+        \int_gdecr:N \g__multifootnote_tag_footnotemark_counter_int
+        \addtocounter { footnote } { -1 }
+        \refstepcounter { footnote }
+        \label { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } }
+        \cs_gset_eq:NN \@currentHref \Hy at footnote@currentHref
+        \label { multifootnote-tag-footnote- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } }
+        \clist_map_inline:nn { #1 }
+          {
+            % generate hypertargets for footnote marks so that they can jump correctly to the corresponding footnotes
+            \clist_if_exist:cF { multifootnote-tag-hypertarget- ##1 }
+              { \clist_new:c { multifootnote-tag-hypertarget- ##1 } }
+            \clist_put_right:ce { multifootnote-tag-hypertarget- ##1 }
+              { \exp_not:N \Hy at raisedlink { \exp_not:N \hypertarget { \exp_not:N \getrefbykeydefault{ multifootnote-tag-footnote- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int  } }{anchor}{Doc-Start} } {} } }
+          }
+      } {}
     \clist_map_inline:nn { #1 }
       {
-        \cs_if_exist:cTF { multifootnote-tag- ##1 }
+        % generate list of marks in the footnote
+        \bool_if:NTF \l__multifootnote_backref_bool
           {
-            \tl_gput_right:cx { multifootnote-tag- ##1 } { , \skip_horizontal:n { \l_multifootnote_space_after_comma_dim } \thefootnote }
+            \cs_if_exist:cTF { multifootnote-tag-list- ##1 }
+              {
+                \tl_gput_right:ce { multifootnote-tag-list- ##1 } { , \skip_horizontal:n { \l_multifootnote_space_after_comma_dim } \ref { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int  } } }
+              }
+              {
+                \cs_gset:cpx { multifootnote-tag-list- ##1 } { \ref { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int  } } }
+              }
           }
           {
-            \cs_gset:cpx { multifootnote-tag- ##1 } { \thefootnote }
+            \cs_if_exist:cTF { multifootnote-tag-list- ##1 }
+              {
+                \tl_gput_right:ce { multifootnote-tag-list- ##1 } { , \skip_horizontal:n { \l_multifootnote_space_after_comma_dim } \thefootnote }
+              }
+              {
+                \cs_gset:cpx { multifootnote-tag-list- ##1 } { \thefootnote }
+              }
           }
       }
   }
-\NewCommandCopy \footnotetag \multifootnotetag
+\NewCommandCopy \footnotetagmanual \multifootnotetagmanual
 
-\NewDocumentCommand \multifootnotetagtext { O{} m }
+\NewDocumentCommand \multifootnotetagtextmanual { O{} m }
   {
     \group_begin:
       \tl_if_blank:nTF { #1 }
@@ -162,13 +392,148 @@
           \def \thefootnote { }
         }
         {
-          \def \thefootnote { \use:c { multifootnote-tag- #1 } }
+          \def \thefootnote { \use:c { multifootnote-tag-list- #1 } }
         }
-      \footnotetext { #2 }
+      \@ifpackageloaded { hyperref }
+        {
+          \xdef \Hy at footnote@currentHref { x\Hy at footnote@currentHref }
+          \footnotetext { \clist_use:cn { multifootnote-tag-hypertarget- #1 } {} \ignorespaces #2 }
+        }
+        {
+          \footnotetext { #2 }
+        }
     \group_end:
   }
 
+\prop_new:N \g__multifootnote_tag_internal_prop
+\NewDocumentCommand \multifootnotetag { m }
+  {
+    \footnotemark
+    \int_gdecr:N \g__multifootnote_tag_footnotemark_counter_int
+    \addtocounter { footnote } { -1 }
+    \refstepcounter { footnote }
+    \label { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } }
+    % add the current label number to the clist of the given tag on the current page
+    \clist_map_inline:nn { #1 }
+      {
+        \iow_now:ce { @auxout }
+          {
+            \@multifootnote at add@to at tag@label at list
+              { ##1 }
+              { \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } }
+              { \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } }
+          }
+      }
+    \@ifpackageloaded { hyperref }
+      {
+        \cs_gset_eq:NN \@currentHref \Hy at footnote@currentHref
+        \label { multifootnote-tag-footnote- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } }
+      } {}
+    \clist_map_inline:nn { #1 }
+      {
+        \clist_if_exist:cF { g__multifootnote_tag_page_ \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } _recorded_clist }
+          {
+            \clist_new:c { g__multifootnote_tag_page_ \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } _recorded_clist }
+          }
+        \clist_if_in:cnF { g__multifootnote_tag_page_ \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } _recorded_clist } { ##1 }
+          {
+            \clist_gput_right:cn { g__multifootnote_tag_page_ \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } _recorded_clist } { ##1 }
+            \group_begin:
+              % \clist_show:c { g__multifootnote_tag_ ##1 _page_ \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } _clist }
+              \clist_if_exist:cT { g__multifootnote_tag_ ##1 _page_ \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } _clist }
+                { % skip the following code on the first run
+                  \clist_clear:N \l__multifootnote_tmp_clist
+                  \clist_map_inline:cn { g__multifootnote_tag_ ##1 _page_ \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } _clist }
+                    {
+                      % generate list of marks in the footnote
+                      \clist_put_right:Nn \l__multifootnote_tmp_clist
+                        {
+                          % \tl_show:n { ####1 }
+                          \bool_if:NTF \l__multifootnote_backref_bool
+                            {
+                              \ref { multifootnote-tag-mark- ####1 }
+                            }
+                            {
+                              \@ifpackageloaded { hyperref }
+                                {
+                                  \ref*{ multifootnote-tag-mark- ####1 }
+                                }
+                                {
+                                  \ref { multifootnote-tag-mark- ####1 }
+                                }
+                            }
+                        }
+                      \@ifpackageloaded { hyperref }
+                        {
+                          % generate hypertargets for footnote marks so that they can jump correctly to the corresponding footnotes
+                          \clist_if_exist:cF { multifootnote-tag-hypertarget- ##1 -page- \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } }
+                            { \clist_new:c { multifootnote-tag-hypertarget- ##1 -page- \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } } }
+                          \clist_put_right:ce { multifootnote-tag-hypertarget- ##1 -page- \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } }
+                            { \exp_not:N \Hy at raisedlink { \exp_not:N \hypertarget { \exp_not:N \getrefbykeydefault{ multifootnote-tag-footnote- ####1 }{anchor}{Doc-Start} } {} } }
+                        } {}
+                    }
+                  % \clist_show:N \l__multifootnote_tmp_clist
+                  \def \thefootnote { \clist_use:Nn \l__multifootnote_tmp_clist { , \skip_horizontal:n { \l_multifootnote_space_after_comma_dim } } }
+                  \@ifpackageloaded { hyperref }
+                    {
+                      \xdef \Hy at footnote@currentHref { x\Hy at footnote@currentHref }
+                      \footnotetext
+                        {
+                          \clist_use:cn { multifootnote-tag-hypertarget- ##1 -page- \getpagerefnumber { multifootnote-tag-mark- \int_eval:n { \g__multifootnote_tag_footnotemark_counter_int } } } {} \ignorespaces
+                          \prop_item:Nn \g__multifootnote_tag_internal_prop { ##1 }
+                        }
+                    }
+                    {
+                      \footnotetext { \prop_item:Nn \g__multifootnote_tag_internal_prop { ##1 } }
+                    }
+                }
+            \group_end:
+          }
+      }
+  }
+\NewCommandCopy \footnotetag \multifootnotetag
+\NewDocumentCommand \@multifootnote at add@to at tag@label at list { m m m }
+  % #1 = tag
+  % #2 = label number
+  % #3 = page number
+  {
+    \clist_if_exist:cF { g__multifootnote_tag_ #1 _page_ #3 _clist }
+      {
+        \clist_new:c { g__multifootnote_tag_ #1 _page_ #3 _clist }
+      }
+    \clist_gput_right:cn { g__multifootnote_tag_ #1 _page_ #3 _clist } { #2 }
+    % \clist_show:c { g__multifootnote_tag_ #1 _page_ #3 _clist }
+  }
+
+\NewDocumentCommand \multifootnotetagtext { O{} m }
+  {
+    \tl_if_blank:nTF { #1 }
+      {
+        \footnotetext { #2 }
+      }
+      {
+        \iow_now:cn { @auxout }
+          {
+            \@multifootnote at add@to at tag@text at list { #1 } { #2 }
+          }
+      }
+  }
+\NewDocumentCommand \@multifootnote at add@to at tag@text at list { m m }
+  {
+    \prop_gput:Nnn \g__multifootnote_tag_internal_prop { #1 } { #2 }
+  }
+
 % The combined interface for producing footnote text
+\NewDocumentCommand \multifootnotemanual { O{} m }
+  {
+    \str_if_in:nnTF { #1 } { , }
+      {
+        \multifootnotetextmanual [ #1 ] { #2 }
+      }
+      {
+        \multifootnotetagtextmanual [ #1 ] { #2 }
+      }
+  }
 \NewDocumentCommand \multifootnote { O{} m }
   {
     \str_if_in:nnTF { #1 } { , }
@@ -180,6 +545,17 @@
       }
   }
 
+\bool_if:NT \l__multifootnote_manual_mode_bool
+  {
+    \RenewCommandCopy \multifootnotemark    \multifootnotemarkmanual
+    \RenewCommandCopy \multifootnotetext    \multifootnotetextmanual
+    \RenewCommandCopy \multifootnotetag     \multifootnotetagmanual
+    \RenewCommandCopy \multifootnotetagtext \multifootnotetagtextmanual
+    \RenewCommandCopy \multifootnote        \multifootnotemanual
+    \RenewCommandCopy \footnotenumber       \footnotenumbermanual
+    \RenewCommandCopy \footnotetag          \footnotetagmanual
+  }
+
 \endinput
 %%
 %% End of file `multifootnote.sty'.



More information about the tex-live-commits mailing list.