generateDefinitions.py 1012 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import re, glob
  4. def get_definitions(filename):
  5. with open(filename) as f:
  6. content = f.read()
  7. pattern = re.compile(r"\\begin{definition}.*?\\end{definition}", re.DOTALL)
  8. m = re.findall(pattern, content)
  9. return "\n\n".join('\\vspace*{{\\fill}}\n{0}\n\\vspace*{{\\fill}}\\clearpage'.format(definition) for definition in m)
  10. #return "\n\n".join('\\begin{{flashcard}}{{a}}\n{0}\n\\end{{flashcard}}'.format(definition) for definition in m)
  11. def write_definitions_to_template(definitions, template="mathe-vorlage.tex", target="definitionen.tex"):
  12. with open(template) as f:
  13. content = f.read()
  14. content = content.replace('%CONTENT%', definitions)
  15. with open(target, 'w') as f:
  16. f.write(content)
  17. if __name__ == "__main__":
  18. definitions = []
  19. for texsource in sorted(glob.glob("../Kapitel*.tex")):
  20. definitions.append(get_definitions(texsource))
  21. write_definitions_to_template("\n\n\n".join(definitions))