This is a follow-up to the question: How can I typeset a command and its literal equivalent in an environment?
It would obviously be useful to handle environments too. I imagine something like the following:
Syntax
\begin{environment}{env_name}{env_description}
\begin{env_name}
some example text
\end{env_name}
\end{environment}
Desired Output
The output would be something like this:

Pseudo Code
\documentclass{article}
\usepackage{fontspec}
\usepackage{menukeys}
\usepackage{xparse}
\usepackage{booktabs} % Adds support for \toprule, \midrule, \bottomrule
\usepackage{array} % https://tex.stackexchange.com/a/4816/13552
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
\setlength\parindent{0pt}
% Some flipped out function called "environment" goes here:
% \NewEnviron is what I would normally use to capture the body in \BODY
% \NewDocumentEnvironment is what egreg used for the command solution.
\begin{document}
\begin{environment}{mytab}{This environment is a wrapper for the standard latex table environment. This environment is a wrapper for the standard latex table environment. You can optionally adjust the alignment of columns by adding parameters. (e.g. \string$c\string^c\string^c)}
\begin{mytab}
\headrowstart
col1 & col2 & col3 \\
\headrowend
dat1 & dat2 & dat3 \\
dat4 & dat5 & dat6 \\
\end{mytab}
\end{environment}
\end{document}
Update 27-04-2015
I've added the following code to the preamble:
\ExplSyntaxOn
\NewDocumentEnvironment{environment}{vvv}
{
\tl_set:Nn \l_env_argument_i_tl { #1 }
\tl_set:Nn \l_env_argument_ii_tl { #2 }
\tl_set:Nn \l_env_argument_iii_tl { #3 }
\par\vspace{\baselineskip}
\noindent
\bgroup\ttfamily
\l_env_argument_i_tl\par
\ignorespaces
\egroup
\par\nopagebreak
\noindent
\l_env_argument_iii_tl \par\noindent % Description
\textbf{Example:~}\par
\texttt
{
\string\begin\string{\l_env_argument_i_tl\string}\l_env_argument_ii_tl\\
\string\end\string{\l_env_argument_i_tl\string}
}
\\*
}
{
\tl_set_rescan:NnV \l_env_argument_tl {} \l_env_argument_i_tl
\tl_if_blank:VF \l_env_argument_ii_tl
{
\tl_set_rescan:NnV \l_env_temp_tl {} \l_env_argument_ii_tl
\tl_put_right:Nx \l_env_argument_tl { { \exp_not:V \l_env_temp_tl } }
}\\*
}
\tl_new:N \l_env_argument_tl
\tl_new:N \l_env_argument_i_tl
\tl_new:N \l_env_argument_ii_tl
\tl_new:N \l_env_argument_iii_tl
\tl_new:N \l_env_temp_tl
\cs_generate_variant:Nn \tl_set_rescan:Nnn { NnV }
\ExplSyntaxOff
The output should be an example of literal code and an example as it would look when typeset.

Problem with automatically inserting code:
%\begin{environment}{<environment>}{<any parameters>}{<description>}
\begin{environment}{tabular}{{ccc}}{This is the standard latex environment for tabular data.}
% \begin{tabular}{ccc} <-- This gets automatically inserted
col1 & col2 & col3 \\
dat1 & dat2 & dat3 \\
% \end{tabular} <-- This gets automatically inserted
\end{environment}
Another option I was thinking about due to difficulties capturing the text inside the environment is to put the tabular data into arg3 and move the description into the body of the environment (just exchange them). If I do this, I still run into the problem that I need to add \begin{ + arg1 + } + arg2 + arg3 + \end{ + arg1 + }. I am not sure how to do this.



tcolorbox, it is not an option due to compatibility issues withhyperref. – Jonathan Komar Apr 27 '15 at 12:32example:\begin{example} \fbox{\begin{minipage}{4cm} \raggedright \tiny\lipsum[2] \end{minipage}} \end{example}– Paul Gessler Apr 27 '15 at 12:51tcolorboxandhyperref? – Apr 27 '15 at 16:21environpackage? (If I'm remembering it right.) – cfr Apr 28 '15 at 00:51tcolorboxroute. I would have to open a new question for that anyway, because it is beyond the scope of this question. Thanks for the environ package tip. @cfr I am aware of it for capturing the body as\BODY, but I then I can't usexparsefor the verbatim input and fancy-schmancy environments/commands. – Jonathan Komar Apr 28 '15 at 20:42xparse. Do you mean you couldn't useenvironwith expl3 syntax? – cfr Apr 28 '15 at 23:06xparse.\NewDocumentEnvironment{environment}{vvv}is possible due toxparse. – Jonathan Komar Apr 29 '15 at 06:08