Graph of dependencies from a Latex file This question has been "manually migrated" to TeX-SX: https://tex.stackexchange.com/q/40200/86

Apologies if the question is not very appropiate for Mathoverflow. It seems to me more appropiate here than in the other 'exchange' sites.
Is there an IT tool to create a graph of dependencies from a Latex file? The sense is the following:
It just occurred to me that if everyone creates propositions with proofs (usually) afterwards and these proofs use \eqref, \ref \cite to call to other results it should be feasible to create a graph of dependencies of results, given a paper written in Latex.
I think such a thing would be useful for any mathematician (check dependencies, recursive arguments, that there are lemmas which have a need, possibility of suggesting equivalences, writing well-ordered documents...) so I would be surprised if this does not exist yet, but I couldn't find it anywhere.
 A: As a rule, you cannot depend upon math papers making every dependency explicit, meaning you cannot extract nearly so much information from this directed graph as you imagine.  In addition, there isn't any reason this graph should be acyclic since forward references frequently get used in outlines and motivational text.
That said, there are use cases like identifying all the backwards references.  For example, you could find all backwards \ref commands using this perl script I call earlyref.pl :
#!/usr/bin/perl -n
BEGIN {  %labels = ();  }
while (/\\(label|ref)\{([A-Za-z0-9_]+)\}/g) {
    if ($1 eq "label") {  $labels{$2} = 1;  next;  }
        next if ($labels{$2});
        print "Early \\ref{$2} on line $. in $ARGV"
}
close if eof(ARGV);

You'll find this handles multiple filename arguments correctly because the last line resets the line number $.` when appropriate. 
There is considerably more you can do using scripting languages with built in regular expressions.  I've written a chcite script which changes all your \cite commands for switching between different co-authors .bib files, for example.
A: Well, it's probably time to learn regular expressions

(http://xkcd.com/208/)
More seriously, I don't know if a graphical tools already exists, but writing a small say Python script which parse every \ref, \eqref and \cite in each proof environment using regular expressions is rather easy. Maybe the only ambiguous things is to associate each proof environment with the corresponding theorem/lemma. Then it would again be easy to generate Graphviz code from that, and Graphviz will automatically produce a nice oriented graph showing all the dependencies. 
