#!/usr/bin/env python3 """ Erzeugt tools/a5-reference.odt aus der Pandoc-Standardreferenz, angepasst an dein A5-Layout: - A5 (14,801 x 21,001 cm), Ränder oben 0,8 / unten 1,0 / links 1,0 / rechts 0,7 cm - Grundschrift Alegreya 10 pt, Überschriften Cinzel - keine Seitennummern (Footer entfernt) Aufruf: python3 make_reference_odt.py """ import io import os import re import subprocess import zipfile TOOLS = os.path.dirname(os.path.abspath(__file__)) OUT = os.path.join(TOOLS, "a5-reference.odt") # 1) Pandoc-Standardreferenz holen default = subprocess.check_output( ["pandoc", "--print-default-data-file", "reference.odt"] ) zin = zipfile.ZipFile(io.BytesIO(default)) names = zin.namelist() items = {n: zin.read(n) for n in names} styles = items["styles.xml"].decode("utf-8") # 2) Gezielte Ersetzungen REPL = [ # --- Seite A5 + Ränder --- ('fo:page-width="8.5in"', 'fo:page-width="14.801cm"'), ('fo:page-height="11in"', 'fo:page-height="21.001cm"'), ('fo:margin-top="1in"', 'fo:margin-top="0.8cm"'), ('fo:margin-bottom="1in"', 'fo:margin-bottom="1cm"'), ('fo:margin-left="1in"', 'fo:margin-left="1cm"'), ('fo:margin-right="1in"', 'fo:margin-right="0.7cm"'), # --- Schriften --- ("Times New Roman", "Alegreya"), ("Arial", "Cinzel"), ("Lucida Sans Unicode", "Cinzel"), ("Tahoma1", "Cinzel"), ("Tahoma", "Cinzel"), # --- Grundschrift 12 pt -> 10 pt --- ('fo:font-size="12pt"', 'fo:font-size="10pt"'), ('font-size-asian="12pt"', 'font-size-asian="10pt"'), ('font-size-complex="12pt"', 'font-size-complex="10pt"'), ] for a, b in REPL: styles = styles.replace(a, b) # 3) Footer (Seitennummer) aus dem Master-Page entfernen styles = re.sub(r".*?", "", styles, flags=re.S) items["styles.xml"] = styles.encode("utf-8") # 4) Neu packen: mimetype zuerst und unkomprimiert with zipfile.ZipFile(OUT, "w") as z: z.writestr("mimetype", items["mimetype"], compress_type=zipfile.ZIP_STORED) for n in names: if n == "mimetype": continue z.writestr(n, items[n], compress_type=zipfile.ZIP_DEFLATED) print("OK:", OUT)