def sanitize(text):
    """Escapes characters that have a special meaning in latex."""
    text = text.replace('\\', '\\textbackslash{}')

    for c in '$%^{}#_&':
        text = text.replace(c, '\\' + c)

    # Allow some more line breaks to happen.
    text = text.replace('/', '\\slash{}')
    text = text.replace('=', '=\\allowbreak{}')
    text = text.replace('-', '-\\allowbreak{}')

    return text