Skip to content

Instantly share code, notes, and snippets.

@renefritze
Created January 18, 2012 08:45
Show Gist options
  • Save renefritze/1632034 to your computer and use it in GitHub Desktop.
Save renefritze/1632034 to your computer and use it in GitHub Desktop.
tex label list
#!/usr/bin/env python
import fnmatch
import os
import sys
from collections import defaultdict
try:
src_dir = sys.argv[1]
except IndexError:
src_dir = "."
label_dict = defaultdict(list)
for root, dirnames, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, '*.aux'):
with open(os.path.join(root, filename)) as aux:
for line in aux:
if line.startswith('\\newlabel{'):
ref = line[10:line.find('}')]
if not '@' in ref:
sec = ref.split('::')[0]
label_dict[sec] = sorted(label_dict[sec] + [ref] )
with open('out.tex','wb') as out:
for sec,labels in label_dict.items():
out.write('\\begin{itemize}\n')
for label in labels:
out.write('\\item \\cref{%s} -- \\verb|%s|\n'%(label,label))
out.write('\\end{itemize}\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment