def env_partition(st, env):
    """Similar to str.partition, but rather than using a given separator,
    it partition the string across some LaTeX environment.
    
    >>> tex = r'''some text
    ... \\begin{foo}
    ...   foo env
    ... \\end{foo}
    ... ham!'''
    >>> pre, env, post = env_partition(tex, 'foo')
    >>> print(env)
    \\begin{foo}
      foo env
    \\end{foo}
    >>> pre + post
    'some text\\n\\nham!'
    """
    pre, begin, post = st.partition('\\begin{%s}' % env)
    envdata, end, post = post.partition('\\end{%s}' % env)
    return pre, begin + envdata + end, post
