Created
February 12, 2014 19:40
-
-
Save joninvski/8963016 to your computer and use it in GitHub Desktop.
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
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