2

This question already has an answer here:

I have a few sentences with a lot of footnotes. Currently my tex code looks like this:

This is One%
%
\footnote{
Footnote text 1
}%
%
, Two%
%
\footnote{
Footnote text 2
}%
%
~and Three%
%
\footnote{
Footnote text 2
}%
%
.

The code is obviously very hard to read and also error prone with regard to the commas, points and whitespaces following the footnote. I have added the comment lines for better readabilty, but it only helps a little bit. Is there a way to decouple the footnotes from the main text? I know that there are the commands \footnotemark and \footenotetext, but when I write

This is One\footnotemark, Two\footnotemark and Three\footnotemark.

\footnotetext{
Footnote text 1
}
\footnotetext{
Footnote text 2
}
\footnotetext{
Footnote text 3
}

all the footnote texts refer to the last footnotemark. I also know that I could use the number parameter (and thereby making the footnote indexes static), but then I would get a problem if I have to add footnoes before or between the existing footnotes. How can I achieve a code like in the second example, but at the same time keep the footnote indexes dynamic?

marked as duplicate by clemens, egreg, user13907, Svend Tveskæg, Thorsten Apr 2 '16 at 11:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @ChristianHupfer In the main text, the footnotemarks show the correct indexs (1, 2, 3). But the footnotetexts show only the number 3. Where would I have to increase the footnote counter? – Rolch2015 Apr 1 '16 at 22:51
  • Sorry, forget my comment, I was wrong. – user31729 Apr 1 '16 at 22:52
  • 1
    Ah, I got the error: \footnotetext needs the last footnote counter value, i.e. \footnotemark...\footnotetext{...} but this is the same hurlyburyly as \footnote{...}` then – user31729 Apr 1 '16 at 22:59
  • 1
    Have a look at the sepfootnotes package. – clemens Apr 2 '16 at 0:11
  • @clemens Thank you, I will have a look at it and try it out. – Rolch2015 Apr 2 '16 at 0:27
2

The \footnotetext macro is basically meant for referring to a \footnotemark, rather near to it, using the current value of the footnote counter, however, multiple \footnotemark will increase the footnote counter accordingly, i.e. in the example it has the value of 3.

Now, \footnotetext will use only 3 as counter value, not the previous one.

A workaround is to reset the footnote counter and automatically step the footnote counter each time \footnotetext is used, by using \xpretocmd (prepending the command with a \stepcounter)

\documentclass{article}

\usepackage{xpatch}

\xpretocmd{\footnotetext}{\stepcounter{footnote}}{}{}

\begin{document}



This is One\footnotemark, Two\footnotemark and Three\footnotemark.


\setcounter{footnote}{0}
\footnotetext{%
Footnote text 1
}
\footnotetext{
Footnote text 2
}
\footnotetext{
Footnote text 3
}


\end{document}

enter image description here

Update

Another approach, somewhat reinventing endnotes:

\documentclass{article}


\usepackage{xparse}

\ExplSyntaxOn

\seq_new:N \g_rolch_seq 

\NewDocumentCommand{\StoreNote}{+m}{%
  \seq_gput_right:Nx \g_rolch_seq {{#1}} % Storing all notes in a list
}

\NewDocumentCommand{\ShowNotes}{}{%
  \setcounter{footnote}{0}
  \seq_map_inline:Nn \g_rolch_seq {\stepcounter{footnote}\footnotetext{##1}}
}


\ExplSyntaxOff


\AtEndDocument{%
  \ShowNotes%
}


\usepackage{blindtext}

\begin{document}


This is One\footnotemark, Two\footnotemark and Three\footnotemark.

\StoreNote{A long note}
\StoreNote{Another Long note}
\StoreNote{The note for the footnote with number \number\value{footnote}}

\blindtext[5]

Another\footnotemark

\blindtext[6]

Another footnote anchor is here\footnotemark


\StoreNote{More long notes}
\StoreNote{More other long notes}
\StoreNote{And now for something completely different}





\end{document}
  • Thank you, this helps lot. However, there is an other problem. If have a large document, say 500 pages and 600+ footnotes, then this solution would also get messy, because I have to write all footnote texts at the end of the document. Therefore, I would like to write the footnote texts after each paragraph. E.g. I have a paragraph with 5 footnote and after the paragraph I write the 5 footnote texts. Then I have an other paragraph with 2 footnotes and write after this pargaraph the two footnote texts etc. Because of this I can not set the counter to 0 for each paragaph(current index is unknown) – Rolch2015 Apr 1 '16 at 23:24
  • 1
    @Rolch2015: Well, then use Steven's approach with the \Lfn macros. The resetting is only an issue if you have to reset the footnote number after each paragraph. But since all footnotes are at the end, I assume, they have one running number, from 1 to 600+? – user31729 Apr 1 '16 at 23:25
  • If I could use arithmetic operations (e.g. \setcounter{footnote}{footnote-4}) then I actually would prefer your solution. This would be possible, because I know how many footnotes I have in the pargraph. The tradeoff would be of course that I had to update the subtrahend each time I add a footnote in the pargraph. But I think it would be worth it, because I can decouple the footnotes from the text. Are such operations possible? – Rolch2015 Apr 1 '16 at 23:30
  • 1
    \setcounter{footnote}{\numexpr\value{footnote}-4} works ;-). I've got another idea – user31729 Apr 1 '16 at 23:31
  • 1
    @Rolch2015: Is my update more what you need? – user31729 Apr 1 '16 at 23:45
5

Here I develop what amounts to a labeling system for footnotes. Define them in the preamble with \labelfn{label}{footnote} and recall them in the text with \Lfn{label}.

\documentclass{article}
\newcommand\labelfn[2]{\expandafter\def\csname Footnote#1\endcsname{#2}}
\newcommand\Lfn[1]{\footnote{\csname Footnote#1\endcsname}}
\labelfn{intro}{This is my introductory footnote.}
\labelfn{trivia}{Here is a bit of trivia.}
\labelfn{reminder}{Now for a reminder.}
\begin{document}
\vspace*{6in}
Here is some blah-blah text.\Lfn{intro}  Now as I continue my
text, there is more\Lfn{trivia} to say on the subject.

I am now done.\Lfn{reminder}
\end{document}

enter image description here

  • Allocating registers for this ? ;-) What about \Lfn{My nice footnote} ?;-) – user31729 Apr 1 '16 at 23:16
  • 1
    @ChristianHupfer The OP wanted to avoid lengthy footnote text within the body of his/her text, as I understood it. Coming up with a solution like \Lfn{My nice footnote} would put the footnote text right back in amongst the body text, the whole pupose being to avoid this. – Steven B. Segletes Apr 1 '16 at 23:21
  • \Lfn{My nice footnote} isn't lengthy .... \Lfn{A ring to rule them all} is lengthy ;-) – user31729 Apr 1 '16 at 23:23
  • 2
    @Rolch2015 The problem with numbers is if you need to rearrange footnotes or add extras, it screws up the numbering scheme. Labels make more sense, as I see it. There is nothing stopping you from making the label a simple number. As my solution is structured, the \labelfn can occur in the text, but must be defined before the footnote can be used. In order to, for example, define footnotes at the end, one would need a system of writing them all out to the aux file, so that the 2nd compilation pass could read them in and use them. – Steven B. Segletes Apr 1 '16 at 23:57
  • 1
    @Rolch2015 For an example of how to write out macros to the aux file, which would allow you to define footnotes at the end, see the addendum to this answer: tex.stackexchange.com/questions/295482/…. Alternatively, consider placing the footnote material in a separate file, and importing it in the preamble with in \include or \input macro. – Steven B. Segletes Apr 2 '16 at 11:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.