parameters: (text)
return_statement: return regex.sub(lambda match: conv[match.group()], text)
docstring: Escape LaTeX commands.
  
      Inputs:
          text: a plain text message
docstring_summary: Escape LaTeX commands.
docstring_tokens: Escape LaTeX commands .
function: def escape(text):
      """
      Escape LaTeX commands.
  
      Inputs:
          text: a plain text message
      """
      conv = {
          '&': '\\&',
          '%': '\\%',
          '$': '\\$',
          '#': '\\#',
          '_': '\\_',
          '{': '\\{',
          '}': '\\}',
          '^': '{\\textasciicircum}',
          '~': '{\\textasciitilde}',
          '\\': '{\\textbackslash}',
          '<': '{\\textless}',
          '>': '{\\textgreater}',
      }
  
      regex_list = []
      for key in sorted(conv.keys(), key=lambda item: - len(item)):
          regex_list.append(re.escape(str(key)))
      regex = re.compile('|'.join(regex_list))
      return regex.sub(lambda match: conv[match.group()], text)
function_tokens: def escape ( text ) : conv = { '&' : '\\&' , '%' : '\\%' , '$' : '\\$' , '#' : '\\#' , '_' : '\\_' , '{' : '\\{' , '}' : '\\}' , '^' : '{\\textasciicircum}' , '~' : '{\\textasciitilde}' , '\\' : '{\\textbackslash}' , '<' : '{\\textless}' , '>' : '{\\textgreater}' , } regex_list = [ ] for key in sorted ( conv . keys ( ) , key = lambda item : - len ( item ) ) : regex_list . append ( re . escape ( str ( key ) ) ) regex = re . compile ( '|' . join ( regex_list ) ) return regex . sub ( lambda match : conv [ match . group ( ) ] , text )