import re


def cleanup_tex_line(text):
    """Format line of tex e.g. replace multiple spaces with one"""
    # replace multiple spaces with 1 space (simplifies matching)
    if text == r"\n":
        return ""
    text = re.sub(r" {2,}", " ", text)
    text = text.rstrip()
    return text