Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question led to a new package:
parnotes

How can I get footnote or endnote text to appear right after the paragraph in which it was mentioned?

Update:

As my question lacks sufficient detail, I'll try to clarify.

  • The goal is to place the notes closer to the reader and to have a document which flows from start to finish, rather than one that is interrupted continuously by footnotes.
  • By "footnote" or "endnote", I mean anything with a cross-reference mark (e.g. "1") pointing to another place on the page (the end of the paragraph).

Update:

The provided answer greatly solves the initial problem quite well. It is, however, incompatible with a number of other options provided by addition packages, such as footmisc and its included options such as para and stable. The bounty will go to an extended solution which:

  • Provides the ability to define the mark and text in different locations so that footnote marks can be placed within section titles (see footnotemark and footnotetext and stable options in footmisc for an example). E.g.:

    \begin{footnotepar}
    \section{This is a section title\footnotemark}
        \footnotetext{This is the text for a footnote which has a mark in the section title.}
        This is text in the paragraph.
    \end{footnotepar}
    
  • Treats the footnote text as if it is no different from text within a standard paragraph and allows the text to behave in a similar manner (e.g. flowing into a paragraph, breaking at the end of the page). E.g.:

1 This is the text of the first footnote. 2 This is the text of

the second footnote. 3 This is the text of the third footnote.

4 This is the text of the fourth footnote. 5 This is the text of


the fifth footnote which partially appears on the top of the

second page. 6 This is the text of the sixth footnote.

  • Leaves points for uniformly controlling the size, font, and position of the footnote mark (the one appearing near the footnote), the footnote text itself, and the space after each footnote (e.g. placing \newline to go to a new line, or \hspace to add some space).
  • Leaves points for uniformly enclosing an environment around each group of footnotes, for e.g., to enable the groups of footnote texts to be enclosed with \begin{multicols}{2} and \end{multicols} (or other environments).
share|improve this question
    
So, by "endnote" you refer to a footnote, but it should be placed immediately after the mentioned paragraph? If so, what should the formatting be? With/without a rule? Should it be flush left or right? \footnotesize or otherwise? –  Werner Nov 14 '11 at 5:56
    
i don't see any way of doing this in a "stable" way. what might be done is: extend endnotes to provide an environment, at the end of which something like \par\thenotes would be printed. would need work on \thenotes not to produce a section title at the start of this stuff. how would you expect these notes to look? would you hope to have a separate document-wide set of endnotes (it would make life more difficult: the paragraph-style notes would have to be stored locally, whereas ordinary endnotes go to a file and are read in at the end), –  wasteofspace Nov 14 '11 at 7:20
    
Have you considered using margin-notes instead? Try footmisc's side option. –  rdhs Dec 4 '11 at 18:37
    
i thought endnotes had capabilities for this (i've only recently looked at it). what am i missing? –  wasteofspace Dec 11 '11 at 11:01

4 Answers 4

up vote 15 down vote accepted

You may put each paragraph into a minipage, because minipages have their own footnotes:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}

\newenvironment{mpar}{\par\noindent\minipage{\linewidth}%
  \setlength{\parindent}{1em}%
}{\endminipage\par\medskip}

\begin{document}
\section{Test}
\blindtext
\begin{mpar}First example.\footnote{A note at the foot of the minipage}
\blindtext\end{mpar}
\begin{mpar}Second example.\footnote{A note at the foot of the minipage}
\blindtext\end{mpar}
\blindtext
\end{document}

Or you may define an environment, that does only copy the footnote feature of minipage:

\documentclass{article}
\usepackage{lipsum}

\makeatletter
\newenvironment{footnotepar}{%
  \par
  \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
  \let\@footnotetext\@mpfootnotetext
}{%
  \ifvoid\@mpfootins\else
    \vskip\skip\@mpfootins
    \normalcolor
    \footnoterule
    \unvbox\@mpfootins
  \fi
  \par\smallskip
}
\makeatother

\begin{document}
\lipsum[1-3]
\begin{footnotepar}Lipsum test:\footnote{lipsum is a
    package}\lipsum[2]\end{footnotepar}
\begin{footnotepar}Another\footnote{Not really another one}
  test:\footnote{This is a lipsum test}\lipsum[3]\end{footnotepar}
\lipsum[4]
\end{document}
share|improve this answer
1  
One caveat here would be that a minipage does not allow page breaks within. –  Werner Nov 14 '11 at 7:04
    
@Werner: That's absolutely correct and should be considered. On the other hand it prevents footnote sign at the text of one page and footnote after the end of the paragraph at another page. Without more information from Village it's difficult to suggest a really good answer. –  Schweinebacke Nov 14 '11 at 14:52
    
@Werner and @Schweinebacke: perhaps there is some exception to this and some way to allow a minipage to be broken at the edge of a page? –  Village Nov 15 '11 at 13:17
1  
@Village: If added a second example with a new enviroment, that is not minipage but copies the minipage footnote feature. Nevertheless: It would be nice, if you'd edit your question to tell a little bit about what you are doing and what you are expecting. –  Schweinebacke Nov 15 '11 at 13:59
    
Your second answer is very good. I've added a bounty to the question with some added details. –  Village Dec 4 '11 at 8:02

This is a stripped-down version of the code in the parnotes package.

NOTE to anyone wanting to "do x after every paragraph": The proper way to make long-term changes to \par is through \@setpar, or by modifying \@par along with \par. Many LaTeX environments reset \par to \@par at end; see source2e chapter ltpar.dtx.

Here's a hack using \g@addto@macro to collect notes and place them in the main text flow later. Use \parnote{TEXT} to place a mark, then call \parnotes to put the notes in manually, anywhere you'd like. For a custom mark, use \parnote[MARK]{TEXT}.

There's also an autopn environment which sets parnotes automatically at the end of every paragraph by redefining \par and \@par. If you enter another environment while in autopn and you still want notes, you'll need to nest autopn within it. (Credit to Ahmed Musa)

\documentclass{article}
\usepackage{multicol}

\makeatletter
% Format for parnotes - \PN@notes@shape is blank (\relax) by default
\providecommand{\parnotefmt}[1]{\footnotesize%
                \PN@notes@shape\PN@narrower@optional\noindent #1}
% Format for parnote marks
\providecommand{\parnotemark}[1]{\textsuperscript{#1}}
% Minimum vertical space before and after parnotes
\providecommand{\parnotevskip}{\medskipamount}
% Full command used between parnotes
\providecommand{\parnoteintercmd}{\hspace{1em plus 0.3em minus 0.2em}}

\global\def\PN@text{}
\global\newcount\c@parnotemark
\def\@PN@autopn{autopn}
\newif\ifPN@inparnotes
\def\PN@disable@indent{\@afterindentfalse\@afterheading}
\let\PN@reset@optional\relax
\let\PN@mark@set\@arabic
\let\PN@narrower@optional\relax
\let\PN@notes@shape\relax

\newcommand\parnote{%
    \ifx\protect\@typeset@protect
        \@ifnextchar [
            {\expandafter\PN@parnote@twoargs}%
            {\expandafter\PN@parnote@onearg}%
    \else
        \expandafter\PN@gobble@opt
    \fi
}
\DeclareRobustCommand\PN@gobble@opt{%
    \@ifnextchar [
        \PN@gobble@opt@@
        \@gobble
}
\def\PN@parnote@twoargs[#1]#2{\PN@parnote@real{#1}{#2}}
\def\PN@parnote@onearg#1{%
    \global\advance\c@parnotemark\@ne
    \begingroup\edef\@x{\endgroup\noexpand\PN@parnote@real%
                        {\PN@mark@set{\c@parnotemark}}}\@x{#1}%
}
\def\PN@gobble@opt@@[#1]#2{}

\long\def\PN@parnote@real#1#2{%
    \leavevmode
    \ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi
    \parnotemark{#1}%
    \ifhmode\spacefactor\@x@sf\fi\relax
    \unless\ifx\PN@text\@empty\g@addto@macro\PN@text{\parnoteintercmd}\fi
    \g@addto@macro\PN@text{\parnotemark{#1}\nolinebreak\thinspace#2}%
}

\newcommand\parnotes{%
    \unless\ifx\PN@text\@empty
        \expandafter\PN@parnotes@real
    \fi
}

\def\PN@parnotes@real{%
    \PN@inparnotestrue
    \unless\ifvmode\par\fi
    \nopagebreak\addvspace{\parnotevskip}%
    {\parnotefmt{\PN@text}\par}%
    \global\def\PN@text{}%
    \addvspace{\parnotevskip}%
    \PN@disable@indent
    \PN@reset@optional
    \PN@inparnotesfalse
}

\newenvironment{autopn}{%
    \let\PN@par\par
    \def\par{\PN@parnotes@auto\PN@par}%
    \def\@par{\PN@parnotes@auto\@@par}%
}
{\PN@parnotes@auto}

\def\PN@parnotes@auto{%
    \ifx\@currenvir\@PN@autopn
        \unless\ifPN@inparnotes
            \unless\ifx\PN@text\@empty
                \expandafter\PN@parnotes@real
            \fi
        \fi
    \fi
}
\makeatother

\begin{document}
\tableofcontents
\vspace{0.3in}
\begin{autopn}
\noindent%
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\parnote{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\parnote{Porta} et elementum diam sagittis.

\section{On parnotes\parnote{Section note.}}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\parnote{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\parnote{Porta} et elementum diam sagittis.

Ut vel ante eros, in lobortis risus.

Lorem ipsum dolor.

\vspace{0.1in}
\noindent Notes inside \texttt{multicols}:
\begin{multicols}{2}
\begin{autopn} % CHANGED: YOU MUST NEST autopn WITHIN ENVIRONMENTS
\noindent Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Integer aliquet quam\parnote{Vitae mauris tempus!} consequat.

New paragraph vitae magna
pulvinar pretium.\parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\parnote{Porta} et elementum diam sagittis.
\end{autopn}
\end{multicols}
\end{autopn}

\noindent Notes outside \texttt{multicols}:
\begin{multicols}{2}
\noindent Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Integer aliquet quam\parnote{Vitae mauris tempus!} consequat.

New paragraph vitae magna
pulvinar pretium.\parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\parnote{Porta} et elementum diam sagittis.
\end{multicols}
\parnotes

\vspace{0.1in}
\noindent Notes break pages:\\[0.08in]
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\parnote{Vitae mauris tempus consequat. In nec neque vitae magna
pulvinar pretium. Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae. In aliquet tortor sed tellus
Porta et elementum diam sagittis. Lorem ipsum dolor sit amet,
pulvinar pretium. Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae. In aliquet tortor sed tellus
Porta et elementum diam sagittis. Lorem ipsum dolor sit amet,
consectetur adipiscing elit.} In nec neque vitae magna pulvinar
pretium.
\parnotes
\end{document}

enter image description here

share|improve this answer
1  
Incredible! Please, go ahead and post a parnotes package to CTAN. –  Keks Dose Dec 9 '11 at 10:29
2  
+1 for a new package ;-) -- See: meta.tex.stackexchange.com/questions/1721/… –  Marco Daniel Dec 9 '11 at 11:04
\begin{filecontents*}{parnotes.sty}
\ProvidesPackage{parnotes}[2011/12/10 v0.0.1 Paragraph notes (Ahmed Musa)]
\NeedsTeXFormat{LaTeX2e}[2011/06/27]
\RequirePackage{combokeys}
\let\parnotesnosep\medbreak
\declarecombokeys[keyprefix=KVA,keyfamily=parnotes,macroprefix=pnt@]{%
  cmd/notecolor/black;
  cmd/noteformat/\@firstofone;
  cmd/notefont/\footnotesize;
  cmd/markformat/\@firstofone;
  cmd/vskip/\medskipamount;
  cmd/interskip/.5em;
}
\protected\def\declareparnotesformat#1{%
  \setkeys[KVA]{parnotes}{#1}%
}
\newcommand*\pnt@hook{}
\newcount\pnt@cnta
\@ifdefinable\parnote\relax
\protected\def\parnote#1{%
  \dkyifx\protect\@typeset@protect{%
    \global\advance\pnt@cnta\@ne
    \xdef\pnt@hook{%
      \dkyexpandonce\pnt@hook
      \begingroup
      \noindent
      \dkyexpandonce\pnt@notefont
      \noexpand\color{\pnt@notecolor}%
      \dkyexpandonce\pnt@markformat{%
        \noexpand\textsuperscript{\number\pnt@cnta}%
      }%
      \dkyexpandonce\pnt@noteformat{\unexpanded{~#1}}%
      \noexpand\hspace{\pnt@interskip}%
      \endgroup
    }%
    \ifvmode\else\unskip\fi
    \pnt@markformat{\textsuperscript{\number\pnt@cnta}}%
  }{}%
}
\protected\def\pnt@print{%
  \pnt@hook
  \global\pnt@cnta\z@
  \gdef\pnt@hook{}%
  \@saved@par
  \vspace{\pnt@vskip}%
  \@afterindentfalse\@afterheading
}
\newenvironment{parnotes}{%
  \let\@saved@par\par
  \def\par{%
    \@saved@par
    \dkyifx\pnt@hook\@empty{}{%
      \vspace{\pnt@vskip}%
      \parskip\z@
      \pnt@print
    }%
  }%
}{%
  \dkyifx\pnt@hook\@empty{}{%
    \@saved@par
    \vspace{\pnt@vskip}%
    \parskip\z@
    \pnt@print
  }%
  \let\par\@saved@par
  \let\@saved@par\@undefined
  \par
}

\endinput
\end{filecontents*} 

\documentclass{article}
\usepackage{multicol}
\usepackage{parnotes}
\usepackage[table,dvipsnames,hyperref]{xcolor}
\declareparnotesformat{%
  noteformat=\textsf,markformat=\textsf,notecolor=ForestGreen,
  notefont=\footnotesize,vskip=\medskipamount,
  interskip=.5em
}

\begin{document}

\begin{parnotes}

\section{Let us start with a multicolumn}

\begin{multicols}{2}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam \parnote{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium. \parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus

\parnote{Porta} et elementum diam sagittis.

\end{multicols}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\parnote{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\parnote{Porta} et elementum diam sagittis.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\parnote{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\parnote{Porta} et elementum diam sagittis.

\section{On parnotes\parnote{Section note.}}

\parnotesnosep
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\parnote{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\parnote{Porta} et elementum diam sagittis.

Ut vel ante eros, in lobortis risus. Nullam pretium, ipsum sit amet
pharetra faucibus, felis diam aliquet sem, bibendum eleifend turpis metus
in ligula.

\vspace{2ex}
\noindent
Notes outside \texttt{multicols}:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\parnote{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\parnote{Porta} et elementum diam sagittis.

\parnotesnosep

\noindent Notes inside \texttt{multicols}:

\begin{multicols}{2}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\parnote{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\parnote{Porta} et elementum diam sagittis.

\end{multicols}

\noindent Notes break pages:\\

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\parnote{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus

\parnote{Porta} et elementum diam sagittis.
\end{parnotes}
\end{document}

enter image description here

share|improve this answer

To avoid repetitive typing of \parnotes, something like the following is possible, but I haven't time now to look at the behavior of multicols in this case.

\def\beginparnotes{%
  \let\@saved@par\par
  \def\par{%
    \@saved@par
    \vspace{\parnotevskip}%
    \parskip\z@
    \ifx\PN@text\@empty\else
      \expandafter\parnotes
    \fi
  }%
}
\def\endparnotes{%
  \ifx\PN@text\@empty\else
    \@saved@par
    \vspace{\parnotevskip}%
    \parskip\z@
    \expandafter\parnotes
  \fi
  \let\par\@saved@par
}
\def\parnotes{%
    \parnotefmt{\PN@text}%
    \global\def\PN@text{}%
    \global\c@PN@t=\c@PN@n
    \vspace{\parnotevskip}%
    \@afterindentfalse\@afterheading
}

Also, note the \unskip in the following:

\long\def\PN@parnote@real#1{%
    \global\advance\c@PN@t\@ne
    \g@addto@macro\PN@text{%
        \global\advance\c@PN@n\@ne
        \parnotemarkfmt{PN@n}~#1\hspace{\parnoteinterspace}%
    }%
    \unskip\parnotemarkfmt{PN@t}%
}
\begin{document}

\beginparnotes

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam \parnote{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium. \parnote{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus

\parnote{Porta} et elementum diam sagittis.
\endparnotes
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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