"""Tables numbered in the order they appear (section 7's corpora tables come before 7.1's controls): 10 -> 8, 10b -> 8b, 11 -> 9, 8 -> 10, 9 -> 11, in one pass; and the last two pronouns for Chandrupatla's method in Appendix A.6. python -u apply_table_order.py """ import re PATH = "article/sim_numerics.md" MAP = {"10": "8", "10b": "8b", "11": "9", "8": "10", "9": "11"} src = open(PATH, encoding="utf8").read() src = re.sub(r"Table (10b|10|11|8|9)(?![0-9a-z])", lambda m: "Table " + MAP[m.group(1)], src) for old, new in (("and 100% of his steps.", "and 100% of its steps."), ("His band inside our step confirms", "Its band inside our step confirms")): assert src.count(old) == 1, old src = src.replace(old, new) open(PATH, "w", encoding="utf8").write(src) caps = re.findall(r"^\*\*Table ([0-9A-D]+[a-c]?)\.\*\*", src, re.M) print("captions in order:", caps)