def tex_escape(text):
conv = {<EOL>'<STR_LIT:&>': r'<STR_LIT>',<EOL>'<STR_LIT:%>': r'<STR_LIT>',<EOL>'<STR_LIT:$>': r'<STR_LIT>',<EOL>'<STR_LIT:#>': r'<STR_LIT>',<EOL>'<STR_LIT:_>': r'<STR_LIT>',<EOL>'<STR_LIT:{>': r'<STR_LIT>',<EOL>'<STR_LIT:}>': r'<STR_LIT>',<EOL>'<STR_LIT>': r'<STR_LIT>',<EOL>'<STR_LIT>': r'<STR_LIT>',<EOL>'<STR_LIT:\\>': r'<STR_LIT>',<EOL>'<STR_LIT:<>': r'<STR_LIT>',<EOL>'<STR_LIT:>>': r'<STR_LIT>',<EOL>}<EOL>regex = re.compile(<EOL>'<STR_LIT:|>'.join(<EOL>re.escape(six.text_type(key))<EOL>for key in sorted(conv.keys(), key=lambda item: -len(item))<EOL>)<EOL>)<EOL>return regex.sub(lambda match: conv[match.group()], text)<EOL>
Escape string for LaTeX usage
    :param text: a plain text message
    :return: the message escaped to appear correctly in LaTeX