def remove_latex_commands(s):
 chars = []
 FOUND_SLASH = False
 for c in s:
  if (c == '{'):
   if FOUND_SLASH:
    FOUND_SLASH = False
  elif (c == '}'):
   pass
  elif (c == '\\'):
   FOUND_SLASH = True
  elif (not FOUND_SLASH):
   chars.append(c)
  elif c.isspace():
   FOUND_SLASH = False
 return ''.join(chars)

def remove_latex_commands ( s ) : chars = [ ] FOUND_SLASH = False for c in s : if ( c == '{' ) : if FOUND_SLASH : FOUND_SLASH = False elif ( c == '}' ) : pass elif ( c == '\\' ) : FOUND_SLASH = True elif ( not FOUND_SLASH ) : chars . append ( c ) elif c . isspace ( ) : FOUND_SLASH = False return '' . join ( chars )
simple function to remove any latex commands or brackets from the string .