import sys from TexSoup import * soup = TexSoup(sys.stdin.read()) spójniki = [ "oraz", "albo", "bądź", "czy", "lub", "ani", "ni", "ale", "jednak", "lecz", "zaś", "czyli", "i", "więc", "zatem", "choć", "czy", "że" ] def remove_orphans(text): out = "" for i, line in enumerate(text.split("\n")): if i: out += "\n" lines = line.split(" ") for j, word in enumerate(lines): if j == len(lines) - 1: out += word elif word.strip() != "" and word != "&" \ and not word.startswith("\\") \ and len(word.strip()) <= 2 or word in spójniki: out += word + "~" else: out += word + " " return out def mutate_r(root): if type(root.expr) == data.TexEnv: if root.expr.name == "equation": return try: for node in root.all: if not isinstance(node, str): mutate_r(node) continue else: node.text = remove_orphans(node.text) except: pass mutate_r(soup) print(soup)