def pick_math_environment(code, numbered=False):
 chunks = code.split('\\begin{')
 toplevel_code = ''.join([chunk.split('\\end{')[(-1)] for chunk in chunks])
 if (toplevel_code.find('\\\\') >= 0):
  env = 'align'
 else:
  env = 'equation'
 if (not numbered):
  env += '*'
 return env

def pick_math_environment ( code , numbered = False ) : chunks = code . split ( '\\begin{' ) toplevel_code = '' . join ( [ chunk . split ( '\\end{' ) [ ( - 1 ) ] for chunk in chunks ] ) if ( toplevel_code . find ( '\\\\' ) >= 0 ) : env = 'align' else : env = 'equation' if ( not numbered ) : env += '*' return env
return the right math environment to display code .