#!/usr/bin/env python3 import re import sys from pathlib import Path if len(sys.argv) != 3: print("Usage: preprocess_tex_for_word.py input.tex output.tex", file=sys.stderr) sys.exit(1) src = Path(sys.argv[1]).read_text(encoding="utf-8") text = src # Rename \includegraphics{file.ext} -> \includegraphics{file.png} text = re.sub( r'(\\includegraphics(?:\[[^\]]*\])?\{[^{}]+?)\.[^./{}\\]+(\})', r'\1.png\2', text ) # Replace siunitx S[...] columns with plain right-aligned columns text = re.sub(r'S\[[^\]]*\]', 'r', text) # Replace bare S columns with r as well text = re.sub(r'(?