def read(tex):
if isinstance(tex, str):<EOL><INDENT>tex = tex<EOL><DEDENT>else:<EOL><INDENT>tex = '<STR_LIT>'.join(itertools.chain(*tex))<EOL><DEDENT>buf, children = Buffer(tokenize(tex)), []<EOL>while buf.hasNext():<EOL><INDENT>content = read_tex(buf)<EOL>if content is not None:<EOL><INDENT>children.append(content)<EOL><DEDENT><DEDENT>return TexEnv('<STR_LIT>', children), tex<EOL>
Read and parse all LaTeX source

    :param Union[str,iterable] tex: LaTeX source
    :return TexEnv: the global environment