Graph of dependencies from a Latex file - MathOverflow [closed] most recent 30 from http://mathoverflow.net 2013-05-22T01:46:31Z http://mathoverflow.net/feeds/question/84977 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://mathoverflow.net/questions/84977/graph-of-dependencies-from-a-latex-file Graph of dependencies from a Latex file Jesus Martinez Garcia 2012-01-05T17:12:44Z 2012-01-06T08:19:16Z <p>This question has been "manually migrated" to TeX-SX: <a href="http://tex.stackexchange.com/q/40200/86" rel="nofollow">http://tex.stackexchange.com/q/40200/86</a></p> <hr> <p>Apologies if the question is not very appropiate for Mathoverflow. It seems to me more appropiate here than in the other 'exchange' sites.</p> <p><strong>Is there an IT tool to create a graph of dependencies from a Latex file?</strong> The sense is the following:</p> <p>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.</p> <p>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.</p> http://mathoverflow.net/questions/84977/graph-of-dependencies-from-a-latex-file/84985#84985 Answer by Adrien for Graph of dependencies from a Latex file Adrien 2012-01-05T18:30:22Z 2012-01-05T21:48:29Z <p>Well, it's probably time to learn <a href="http://en.wikipedia.org/wiki/Regular_expression" rel="nofollow">regular expressions</a></p> <p><img src="http://imgs.xkcd.com/comics/regular_expressions.png" alt="alt text"> (<a href="http://xkcd.com/208/" rel="nofollow">http://xkcd.com/208/</a>)</p> <p>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 <a href="http://en.wikipedia.org/wiki/Graphviz" rel="nofollow">Graphviz</a> code from that, and Graphviz will automatically produce a nice oriented graph showing all the dependencies. </p> http://mathoverflow.net/questions/84977/graph-of-dependencies-from-a-latex-file/85014#85014 Answer by Jeff Burdges for Graph of dependencies from a Latex file Jeff Burdges 2012-01-06T00:28:56Z 2012-01-06T00:28:56Z <p>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.</p> <p>That said, there are use cases like identifying all the backwards references. For example, you could find all backwards <code>\ref</code> commands using this perl script I call <code>earlyref.pl</code> :</p> <pre><code>#!/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); </code></pre> <p>You'll find this handles multiple filename arguments correctly because the last line resets the line number <code>$.</code> when appropriate. </p> <p>There is considerably more you can do using scripting languages with built in regular expressions. I've written a <a href="https://github.com/burdges/chcite" rel="nofollow">chcite</a> script which changes all your \cite commands for switching between different co-authors .bib files, for example.</p>