Created
January 18, 2012 08:45
-
-
Save renefritze/1632034 to your computer and use it in GitHub Desktop.
tex label list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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