Footnotes – How to Manage Footnotes Effectively

footnotesmacros

Sometimes I find footnotes either annoying or distracting when trying to edit the body of a text: particularly one which is heavily annotated with footnotes. One solution I've come up with is to gather my footnotes together into files organized to mirror to the file/directory structure I'm using for the overall document.

Each footnote is given its own unique(ish) macro.
Here is an example of the sort of code I use to define a footnote macro:

\makeatletter
%% #1 = footnote identifier     
%% #2 = footnote content
\long\def\setfootnote#1#2{%%
  \expandafter\long\expandafter\def\csname ae@footnote@#1@ftnt@\endcsname{#2}}
\def\aefootnote#1{\footnote{\csname ae@footnote@#1@ftnt@\endcsname}}
\makeatother

This is a bit flattened from how I typically define my footnote commands, but my file/directory structure is beyond the scope of this question and would unduly complicate this example.

For the MWE I have three files:

footnote.tex

\setfootnote{first footnote}{This is just an example footnote.}
\setfootnote{another footnote}{sf;ksdf  sf;lskf s;df spewr po s;fksf; sdkf.}

main_matter.tex

\input{footnotes}

Here is an illustration of using my footnotes.\aefootnote{first footnote}
This is another footnoted sentence.\aefootnote{another footnote}

master_doc.tex

\documentclass{article}
\makeatletter
%% #1 = footnote identifier 
%% #2 = footnote content
\long\def\setfootnote#1#2{%%
  \expandafter\long\expandafter\def\csname ae@footnote@#1@ftnt@\endcsname{#2}}
\def\aefootnote#1{\footnote{\csname ae@footnote@#1@ftnt@\endcsname}}
\makeatother
\begin{document}

\input{main_matter}

\end{document}

This works pretty well for me. It cleans up the content of the master document. I can see where the footnotes are, but I don't have to be distracted by their content when writing and editing the main matter.

But memory-wise this is an extremely wasteful approach. If I have a long document, then I'm forcing LaTeX to know and remember my footnotes for the entire life of the document.

I could implement a garbage collection system. That is, I could track the macros for my footnotes by the file currently being compiled by storing their names in a macro such as \ae@garbage@collection. When I'm done compiling that file I could then do something along the following lines

\expandafter\let\csname ae@footnote@.....@ftnt@\endcsname\ae@undefined@macro

where ..... is the identifier for each footnote note macro I'm deleting. This could be automated through a macro \ae@delete@garbage.

In other words, I'm saying I know ways to get around cluttering up LaTeX's memory with things it only really needs once.

What I'm interested in knowing is whether someone has suggestions for a better approach. Is there a more efficient way of managing footnotes which nevertheless avoids cluttering up the source file(s) for the master document?

Best Answer

A easier option could be clipboard:

The file with the footnotes: (for example footnotes.tex)

\documentclass{article}
\usepackage{clipboard}
\newclipboard{myfootnotes}
\begin{document}
\Copy{lore}{\footnote{This is a footnote.}}
\Copy{ipsum}{\footnote{This is a more long footnote.}}
\Copy{dolor}{\footnote{\emph{Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit}.}}
\end{document}

The file with the main text: (for example main.tex)

\documentclass[a5paper,12pt]{article}
\usepackage[bmargin=14cm]{geometry}
\usepackage{clipboard}
\openclipboard{myfootnotes}
\begin{document}
This is the main text with a footnote,\Paste{lore}
another footnote \Paste{ipsum}  and one Cicero quote.
\Paste{dolor}
\end{document}

Notes:

The file names are irrelevant, but obviously both files must share the name of the clipboard.

Because content of footnote.tex is copied (to a temporal myfootnotes.cpy) and pasted into main.tex, you must compile first footnote.tex and after that, compile main.tex.

The original purpose of this package is to reuse the text of one stand alone document into anothers, but if the first file is only to maintain the clipboards, alternatively you can write directly myfootnotes.cpy, including only commands with this format:

\clipboard{name}{text}

But obviously, if you use \newclipboard{myfootnotes} in any .tex file, this .cpy file will be overwritten!

The result:

MWE

Related Question