Make \newenvironment perform the end substitution BEFORE testing if \end matches the corresponding \begin.  This allows \newcommand to use \begin and \end in the substititions.  Resolves issue #793.
Merge branch 'issue793' into develop.  Issue #793.