2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-25 22:38:04 +02:00

Karteikarten

This commit is contained in:
Martin Thoma 2014-02-06 16:01:29 +01:00
parent a3888a96a6
commit ff24e6c3a1
6 changed files with 71 additions and 51 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re, glob
@ -7,10 +7,17 @@ def get_definitions(filename):
with open(filename) as f:
content = f.read()
pattern = re.compile(r"\\begin{definition}.*?\\end{definition}", re.DOTALL)
m = re.findall(pattern, content)
return "\n\n".join('\\vspace*{{\\fill}}\n{0}\n\\vspace*{{\\fill}}\\clearpage'.format(definition) for definition in m)
#return "\n\n".join('\\begin{{flashcard}}{{a}}\n{0}\n\\end{{flashcard}}'.format(definition) for definition in m)
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:
@ -24,4 +31,4 @@ if __name__ == "__main__":
definitions = []
for texsource in sorted(glob.glob("../Kapitel*.tex")):
definitions.append(get_definitions(texsource))
write_definitions_to_template("\n\n\n".join(definitions))
write_definitions_to_template("\n\n\n".join(definitions), "flashcards-try.tex")