I've got a very large document (which I've broken into "chapters" and such) which I've recently moved a few things around in. Is there a nice way to get latex to output a list of forward references? (like, things in chapter 5 that reference a result in chapter 10)
Asked
Active
Viewed 4,229 times
2 Answers
16
Here's a way to write out all of your references, forward, backward, and undefined to \jobname.refs.
\newwrite\refs
\openout\refs=\jobname.refs
\makeatletter
\renewcommand\@setref[3]{%
\ifx#1\relax
\write\refs{'#3' \thepage\space undefined}%
\protect \G@refundefinedtrue
\nfss@text{\reset@font\bfseries ??}%
\@latex@warning{Reference `#3' on page \thepage\space
undefined}%
\else
\write\refs{'#3' \thepage\space
\expandafter\@secondoftwo#1}%
\expandafter#2#1\null
\fi
}
\makeatother
LaTeX doesn't keep track of chapter, so this writes out pages instead. The format is
'ref name' page refpage
You could easily change the \else case to do the \write\refs only if the second number was later than the first. Basically, change the \else clause to the following.
\begingroup
\count@\expandafter\@secondoftwo#1\relax
\ifnum\c@page<\count@
\write\refs{'#3' \thepage\space
\expandafter\@secondoftwo#1}%
\fi
\endgroup
\expandafter#2#1\null
TH.
- 62,639
7
TH. already gave a nice answer (I would even say that that is the way it ought to be done). But here a technologically cheap way since you've already broken it up in terms of chapters:
- Remove all
.auxfiles \includeonly{chapter1}and compile. See if there are broken references. Then\includeonly{chapter2}and compile. See if there are broken references.- Rinse and repeat.
Willie Wong
- 24,733
- 8
- 74
- 106
-
1I thought the point of
\includeonlywas that it worked correctly with references. – TH. Oct 17 '10 at 00:30 -
3@TH Yes, but only if the .aux files are present: you have to
\includeonly{chapterN}each chapter at least once in order to produce the chapterN.aux file, so Willie's recipe should indeed work. But your answer still is better in my opinion. – Lev Bishop Oct 17 '10 at 02:38 -
-
Of course, TH.'s answer is much better. In my answer above, I counted on
\includeonlyworking with references already present in .aux files to only show broken forward references and not working backward references. This is just the sort of cheap thing one can put together at one in the morning without thinking too hard. – Willie Wong Oct 17 '10 at 13:27
\makeatletter, could you please add\makeatotherat the end of your code? – Hendrik Vogt Oct 17 '10 at 07:53myfile.tex, then the output would be inmyfile.refs. If it doesn't work: please ask a new question and link to this one. – Willie Wong Aug 02 '22 at 15:35\usepackage{hyperref}, and\let\autoref\refand run the code above to generate the reference list. And then undo the source modification to build your real document. (The wayhyperrefis written, you will have to search throughhyperref.styand apply the same patch to every command that looks like\HyRef@<something>setref.) – Willie Wong Aug 02 '22 at 15:53