import re


def latexify(txt):
    """
    Take some text and replace the logical vocabulary that ttg understands with LaTeX equivalents
    """
    # Use LaTeX symbols as in Forallx (roughly)
    substitutions = {
        "not": "\\lnot",
        "-": "\\lnot",
        "~": "\\lnot",
        "or": "\\lor",
        "nor": "\\downarrow",
        "xor": "\\veebar",
        "!=": "\\veebar",
        "and": "\\land",
        "nand": "\\uparrow",
        "implies": "\\rightarrow",
        "=>": "\\rightarrow",
        "=": "\\leftrightarrow",
    }

    regex = re.compile("(%s)" % "|".join(map(re.escape, substitutions.keys())))

    return regex.sub(lambda mo: substitutions[mo.string[mo.start() : mo.end()]], txt)