Implements graph-based tex master auto-find

As for the other branch, this time it should be ok.