def read_tex(src):
c = next(src)<EOL>if c.startswith('<STR_LIT:%>'):<EOL><INDENT>return c<EOL><DEDENT>elif c.startswith('<STR_LIT:$>'):<EOL><INDENT>name = '<STR_LIT>' if c.startswith('<STR_LIT>') else '<STR_LIT:$>'<EOL>expr = TexEnv(name, [], nobegin=True)<EOL>return read_math_env(src, expr)<EOL><DEDENT>elif c.startswith('<STR_LIT>') or c.startswith("<STR_LIT>"):<EOL><INDENT>if c.startswith('<STR_LIT>'):<EOL><INDENT>name = '<STR_LIT>'<EOL>begin = '<STR_LIT>'<EOL>end = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>name = "<STR_LIT>"<EOL>begin = "<STR_LIT>"<EOL>end = "<STR_LIT>"<EOL><DEDENT>expr = TexEnv(name, [], nobegin=True, begin=begin, end=end)<EOL>return read_math_env(src, expr)<EOL><DEDENT>elif c.startswith('<STR_LIT:\\>'):<EOL><INDENT>command = TokenWithPosition(c[<NUM_LIT:1>:], src.position)<EOL>if command == '<STR_LIT>':<EOL><INDENT>contents, arg = read_item(src)<EOL>mode, expr = '<STR_LIT>', TexCmd(command, contents, arg)<EOL><DEDENT>elif command == '<STR_LIT>':<EOL><INDENT>mode, expr, _ = '<STR_LIT>', TexEnv(src.peek(<NUM_LIT:1>)), src.forward(<NUM_LIT:3>)<EOL><DEDENT>else:<EOL><INDENT>mode, expr = '<STR_LIT>', TexCmd(command)<EOL><DEDENT>expr.args = read_args(src, expr.args)<EOL>if mode == '<STR_LIT>':<EOL><INDENT>read_env(src, expr)<EOL><DEDENT>return expr<EOL><DEDENT>if c in ARG_START_TOKENS:<EOL><INDENT>return read_arg(src, c)<EOL><DEDENT>return c<EOL>
r"""Read next expression from buffer

    :param Buffer src: a buffer of tokens