Match multiple footnote marks with their disjoint text in LaTeX

I found an elegant solution to a problem I often have: I need to write some lengthy footnote in the middle of a paragraph, making the source LaTeX unreadable.

Luckily, LaTeX provides a pair of commands, `\footnotemark’ and ‘\footnotetext’, to disjoin the two parts of a ‘”footnote declaration”. The first produces a superscript, and the second links the last superscript with the text of the footnote. In this way you just drop a \footnotemark wherever you need to, and later specify the text of the footnote with \footnotetext.

So far, so good. The problem arises when you need to do this for multiple footnotes.

In fact, \footnotetext associates the text you pass to it to the last \footnotemark, hence if you had two footnote marks and then you provide two footnote texts, both will bind to the last mark and the first will remain orphan.

The solution is usually some awkward hotfix to the counters, but today I found a more elegant way. To be fair, we still have to manually intervene on the counters, but in a much safer way, as we’ll see. The trick is the following: label the footnotetexts with their own \label, and use \getrefnumber to bind it to the mark retroactively. To encapsulate the strategy, I wrote myself the following macros:

which can be used like this:

If you think the lengthy command names are as disrupting as the foonotes they replace, just rename them with your favorite abbreviation (like \dfm or whatever).

I said it is safer than other methods since the counters are manipulated just once, in a totally predictable way, and just when it’s needed (when we specify the footnote text). Moreover, as the binding mark-text is now explicit and named, it is very hard to mess with.

I’m probably more excited than I should be, but I hope it will help (and satisfy) someone else, too!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.