Skip to content

Instantly share code, notes, and snippets.

@joninvski
Created February 12, 2014 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joninvski/8963016 to your computer and use it in GitHub Desktop.
Save joninvski/8963016 to your computer and use it in GitHub Desktop.
import re
main_tex = "report.tex"
current_level = 0
def extract(line):
found = re.search('{.+}', line)
if found:
return found.group(0)[1:-1]
return None
def write_mindmap(level, text):
global current_level
while level <= current_level:
for i in xrange(current_level): print "\t",
# print current_level,
current_level -= 1
print "</node>"
while level > current_level + 1:
for i in xrange(level): print "\t",
# print current_level,
print_mm_node("N/A")
current_level += 1
for i in xrange(level): print "\t",
# print current_level,
print_mm_node(text)
current_level = level
def write_output(level, text):
write_mindmap(level, text)
# for i in xrange(level): print "#",
# print text
def print_mm_node(text):
print '<node CREATED="1390492066844" ID="ID_419435128" MODIFIED="1390492068808" POSITION="right" TEXT="%s">' % (text,)
def open_mindmap():
print '<map version="0.9.0">'
print_mm_node("Thesis")
def close_mindmap():
global current_level
while current_level >= 0:
for i in xrange(current_level): print "\t",
print "</node>"
current_level -= 1
print '</map>'
def open_output():
open_mindmap()
def close_output():
close_mindmap()
def read_tex_file(f_path):
with open(f_path) as f:
for line in f:
if "\\input" in line:
read_tex_file(extract(line) + '.tex')
pass
elif "\\chapter" in line:
found = extract(line)
write_output(1, found)
elif "\\section" in line:
found = extract(line)
write_output(2, found)
elif "\\subsection" in line:
found = extract(line)
write_output(3, found)
elif "\\subsubsection" in line:
found = extract(line)
write_output(4, found)
elif "\\paragraph" in line:
found = extract(line)
write_output(5, found)
elif "\\subparagraph" in line:
found = extract(line)
write_output(6, found)
open_output()
read_tex_file(main_tex)
close_output()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment