3

I am in the position of needing footnotes for my document. I found that the syntax is:

Something pretty complicated\footnote{This complicated thing needs details.}

This will make my source hard to read so I have to ask you guys: is there any method to work like this?

Something pretty compLicated\footnote{ref:1}

\footnote{1}{This complicated thing needs details.}
0

If you are using plain TeX then you can try this:

\input opmac

\let\fnoteori=\fnote
\def\fnote#1{\fnoteori{%
   \expandafter\ifx\csname fn:#1\endcsname\relax Footnote not declared yet.%
   \else \csname fn:#1\endcsname\fi}}

\def\fnotedef#1#2{\toks0={#2}\openref\immediate\wref\sdef{{fn:#1}{\the\toks0}}}


Something pretty complicated\fnote{ref:1}

% at the end of the document (or somewhere else):
\fnotedef{ref:1}{This complicated thing needs details.}

\bye

If you are using different TeX macro (for example LaTeX) then you can find only the inspiration here. The \fnotedef macro saves the information to the working file (aux, ref etc.) in the format:

\sdef{fn:ref:1}{text}

When the document is processed again, then this file is read and \sdef macro defines \fn:ref:1 as text. So, the \fnote macro can execute the original \fnote where the \fn:ref:1 is expanded.

0

Something like this, that uses the .aux file for saving the footnotes. I don't think it's a real advancement in readability.

\documentclass{article}
\usepackage{atveryend}

\makeatletter
\newcommand{\victor@fnread}[2]{%
  \global\@namedef{victor@#1@footnote}{#2}%
  \g@addto@macro\victor@footnotes{#2}%
}
\def\victor@footnotes{}%
\let\FOOTNOTE\victor@fnread
\AtEndDocument{%
  \gdef\victor@footnotesend{}%
  \let\FOOTNOTE\victor@fncheck
}
\newcommand{\victor@fncheck}[2]{%
  \g@addto@macro\victor@footnotesend{#2}%
}
\AtVeryEndDocument{%
  \ifx\victor@footnotes\victor@footnotesend\else
    \@latex@warning@no@line{Footnotes have changed, rerun LaTeX}%
  \fi
}

\let\victor@footnote@ori\footnote
\renewcommand{\footnote}[1]{%
  \victor@footnote@ori{\@nameuse{victor@#1@footnote}}%
}

\newcommand{\savefootnote}[2]{%
  \protected@write\@auxout{}{%
    \string\FOOTNOTE{#1}{#2}%
  }%
}
\makeatother

\textheight=4cm % just for the example

\begin{document}

Something pretty complicated\footnote{ref:1}

\savefootnote{ref:1}{This complicated thing needs details.}

Whatever\footnote{ref:what} and another\footnote{ouch}

\savefootnote{ref:what}{OK}
\savefootnote{ouch}{Ouch}

\end{document}

enter image description here

A check for duplicate keys can be added. For the moment, just a warning the footnotes have changed is issued, if it's the case.

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