generateDefinitions.py 866 B

123456789101112131415161718192021222324252627
  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 "\\vspace*{\\fill}"+("\n\\vspace*{\\fill}\\clearpage\\vspace*{\\fill}\n".join(m))
  10. def write_definitions_to_template(definitions, template="mathe-vorlage.tex", target="definitionen.tex"):
  11. with open(template) as f:
  12. content = f.read()
  13. content = content.replace('%CONTENT%', definitions)
  14. with open(target, 'w') as f:
  15. f.write(content)
  16. if __name__ == "__main__":
  17. definitions = []
  18. for texsource in sorted(glob.glob("../Kapitel*.tex")):
  19. definitions.append(get_definitions(texsource))
  20. write_definitions_to_template("\n\n\n".join(definitions))