Is there a way in LaTeX to separate the endnote text from the place where it should be placed/invoked? [duplicate]

I want to insert a few fairly large endnotes. The problem is that if I insert them with \endnote{text text} it makes it very difficult to follow the flow of the main text (as the endnote spans a few paragraphs).

Is there a package that would allow me to separate the place where the endnote is invoked from its contents? Something like say \lendnote{Label1} to invoke and \begin{lendnote}\label{Label1}<<here goes the endnote body>>\end{lendnote}

2 Answers

Here's a simple way to do this. You store each big endnote in a separate file named <label>.tex where <label> is how you will refer to it in the command that will insert it and in any \ref in the text. Then you create a command (I've called it \extendnote) which takes the label as an argument and then simply uses \input for the endnote text.

You can keep all of the external endnotes in the source file by adding them at the beginning using the {filecontents} environment. Of course if that becomes unmanageable, you can put all the {filecontents} environments in a separate file (e.g. bignotes.tex) and then \input that into your main source file.

\documentclass{article}
\usepackage{endnotes}
\usepackage{lipsum}
\begin{filecontents}[noheader,overwrite]{big.tex}
\lipsum[1-2]
\end{filecontents}
\begin{filecontents}[noheader,overwrite]{large.tex}
\lipsum[3-4]
\end{filecontents}
\newcommand{\extendnote}[1]{\endnote{\input{#1}\label{#1}}}
\begin{document}
Here is some text.\endnote{This is a small endnote\label{small}}
Here is some more text, with a big endnote.\extendnote{big} Here is some
more text.\endnote{A small endnote} and some more text.\extendnote{large}.
And here are some references to note \ref{large} and note \ref{small}.
\theendnotes
\end{document}


You can store the note text in a macro, defined sowhere earlier in the source code.

An example (partially borrowed from the Alan Munn's answer):

\documentclass{article}
\usepackage{endnotes}
\usepackage{lipsum}
\newcommand\noteone{\lipsum[1-2]}
\newcommand\notetwo{\lipsum[3-4]}
\begin{document}
Here is some text.\endnote{This is a small endnote} Here is some more text,
with a big endnote.\endnote{\noteone} Here is some more text.\endnote{A small
endnote} and some more text.\endnote{\notetwo}
\theendnotes
\end{document}

• Right. I put \def mechanically, it's shorter then \newcommand, so I rarely use the latter. – Sergei Golovan Oct 18 at 21:41
• Yes, me too sometimes, but for the site we should try to model best practice. :) (We can delete these comments). – Alan Munn Oct 18 at 21:57