2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-25 14:28:05 +02:00
LaTeX-examples/documents/GeoTopo/definitions/generateDefinitions.py

35 lines
1.5 KiB
Python
Raw Normal View History

2014-02-06 16:01:29 +01:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2014-02-06 08:53:29 +01:00
import re, glob
def get_definitions(filename):
with open(filename) as f:
content = f.read()
2014-02-06 16:01:29 +01:00
pattern = re.compile(r"\\begin{definition}.*?\\end{definition}", re.DOTALL | re.UNICODE)
index_pattern = re.compile(r"\\xindex{(?:.*?@)?(.*?)(?:\|.*?)?}", re.UNICODE)
definitions = re.findall(pattern, content)
def_dict_list = []
for definition in definitions:
names = re.findall(index_pattern, definition)
names = map(lambda s: s.replace("!", ", "), names)
name = "\\\\".join(names)
def_dict_list.append({"name":name, "definition":definition})
#return "\n\n".join('\\vspace*{{\\fill}}\n{0}\n\\vspace*{{\\fill}}\\clearpage'.format(definition["definition"]) for definition in def_dict_list)
return "\n\n".join('\\begin{{flashcard}}{{ {1} }}\n{{ {0} }}\n\\end{{flashcard}}'.format(definition["definition"], definition["name"]) for definition in def_dict_list)
def write_definitions_to_template(definitions, template="mathe-vorlage.tex", target="definitionen.tex"):
with open(template) as f:
content = f.read()
content = content.replace('%CONTENT%', definitions)
with open(target, 'w') as f:
f.write(content)
if __name__ == "__main__":
definitions = []
for texsource in sorted(glob.glob("../Kapitel*.tex")):
definitions.append(get_definitions(texsource))
2014-02-06 16:01:29 +01:00
write_definitions_to_template("\n\n\n".join(definitions), "flashcards-try.tex")