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.

I'd like to have a footnote that refers to text later in the document, and say "... above ..." or "... below ..." depending on whether the text is on the same page (and thus above) the footnote, or on a later page (and thus below) the footnote. How do I do this? Is there a way to do this without manually writing to the aux file?

(Is it bad practice to refer to future text in a footnote?)


I have it (almost) working with the following code:

Right before the footnote:

\makeatletter
\newcommand{\IfDoAbove}{\ifdoabove\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
\immediate\write\@auxout{\noexpand\global\noexpand\newif\noexpand\ifsecondbulletabove}
\edef\relevantfootnotepage{\thepage}

In the footnote, \IfDoAbove{above}{below}

By the text that I care about

\ifnum\relevantfootnotepage=\thepage\relax
  \immediate\write\@auxout{\noexpand\global\noexpand\doabovetrue}%
\else
  \immediate\write\@auxout{\noexpand\global\noexpand\doabovefalse}%
\fi

But it fails if the text that I care about is in an \item which is the first thing on a new page; \thepage is the same as the old page, not the new page. Why is this?

share|improve this question
    
Hmm. I suppose this ought to at least be possible in principle, given the fact that the footnotes are supposed to be at the bottom of the page -- assuming, of course, that such footnotes don't ever end up spanning pages, which might be able to result in the puzzling situation that the word "above" or "below", in TeX's opinion, ought to be split between pages such that "below" would be appropriate on the first page and "above" would be appropriate on the second. –  SamB Nov 30 '10 at 3:03
1  
The actual placement of the footnote isn't important: what's important is the place in the main text that it refers to... So this misses the point. –  Seamus Dec 3 '10 at 15:55

2 Answers 2

up vote 3 down vote accepted

With the suggestion of Will Robertson, I've made the following code mostly work (it assumes the footnotetext is on the same page as the footnotemark):

\makeatletter
\long\def\@firstofthree#1#2#3{#1}
\long\def\@secondofthree#1#2#3{#2}
\long\def\@thirdofthree#1#2#3{#3}
\long\def\@gobbleto@end#1\@end{}
\long\def\@@firstofmany#1{#1\@gobbleto@end}
\long\def\@firstofmany#1{\@@firstofmany#1\@end}
\long\def\@@secondofmany#1#2{#2\@gobbleto@end}
\long\def\@secondofmany#1{\@@secondofmany#1\@end}
\newcounter{iflabelabove@counter}
\newcommand{\numeric@pageref}[1]{% since hyperref makes \pageref into a hyperlink, and \pageref, even without hyperref, gives me an extra {} at the end
  \expandafter\ifx\csname r@#1\endcsname\relax
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {-1}{\expandafter\@secondofmany\expandafter{\romannumeral-`\q\csname r@#1\endcsname}}%
}
\newcommand{\@branchonlabelpage}[1]{%
  \label{current page \arabic{iflabelabove@counter}}%
  \savebox{\@tempboxa}{\pageref{current page \arabic{iflabelabove@counter}}\pageref{#1}}%
  \ifnum\numeric@pageref{#1}<\numeric@pageref{current page \arabic{iflabelabove@counter}}\relax%
    \stepcounter{iflabelabove@counter}\expandafter\@firstofthree
  \else
    \ifnum\numeric@pageref{#1}=\numeric@pageref{current page \arabic{iflabelabove@counter}}\relax%
      \stepcounter{iflabelabove@counter}\expandafter\expandafter\expandafter\@secondofthree
    \else
      \stepcounter{iflabelabove@counter}\expandafter\expandafter\expandafter\@thirdofthree
    \fi
  \fi
}
\newcommand{\iflabelabovepage}[3]{\@branchonlabelpage{#1}{#2}{#3}{#3}}
\newcommand{\iflabelbelowpage}[3]{\@branchonlabelpage{#1}{#3}{#3}{#2}}
\makeatother
share|improve this answer

As far as I know, this is not possible, because TeX completely formats footnotes when you define them. They are stored in a "waiting list", as a sequence of completely formatted lines, and when TeX breaks a page, he tries to put some of those lines at the bottom of the current page. So at the moment you could possibly know on which page a footnote will be, it is too late to change it.

And since it is actually not even possible to reliably determine on which page a footnote is, multi-pass algorithms will not be of any help...

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.