Many people have asked questions about how to locate float references such that the float will appear near the first reference (note that a similar - but less common - problem exists for footnotes, as described in "Footnote being pushed to after a float page."). I'm hoping for an automated tool to identify potential problem floats and footnotes.

In a small document, it's relatively easy to identify and fix any problematic references, but in a large document (e.g. a dissertation or a book), the proofreading effort is considerable, and the problems may change considerably after minor editing. At the extreme, adding a sentence or a paragraph early in a chapter may affect float placement throughout that chapter - and I don't want to repeat the laborious proofing process after each compilation.

I'm imagining a PDF tool that would output a list of potentially problematic placements, for manual review. E.g. "Table 2.3 located 3 pages after the first reference", "Footnote 3 in chapter 4 located 2 pages after reference".

Such a tool could presumably use the PDF hyperlinks produced by the hyperref package to trace references within the document. Alternatively (and more simply), is there a pdflatex option to output a warning when placing a float or footnote more than x pages from the first reference?

Update: I've built myself a simple tool using the iText library, but it's pretty rudimentary, and I'd still be interested in a more sophisticated proofing tool.

1 Answer 1


This warns if the page of the first ref is no equal to the page with the thing being referenced

It makes

first ref {f2} on page 2 -> page 3
first ref {f5} on page 2 -> page 8

You could modify it in various ways eg change the equality test here


to something testing distance eg


to only warn if it's more than 5 pages ahead.

If you use non integer page numbers (eg roman numerals) it would need a bit of extra code to make those \ifnum safe, and if you use hyperref there are four rather than 2 fields in the internal ref structure so

 \@secondoftwo\csname r@#1\endcsname\@empty\@empty

would probably need to be

 \@secondoffour\csname r@#1\endcsname\@empty\@empty\@empty\@empty
\def\a{One two three four five six. }
\def\b{Red yellow. \a Green blue black white \a\a}
\def\c{Something \stepcounter{enumi} \roman{enumi} \a\b\a\b\par}

\centering FFF\\FFF \caption{fff\label{#2}}

\expandafter\ifx\csname first@#1\endcsname\relax
\global\expandafter\let\csname first@#1\endcsname\@empty
  \@secondoftwo\csname r@#1\endcsname\@empty\@empty}%

\typeout{first ref {#1}  on page #3 -> page #2}%


aaa\ref{f1}  and \ref{f2} and \ref{f5}

bbb \ref{f5} again
\f{H}{f4}% end of document


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .