# How to hide a verbatim-like environment in another environment?

I cannot find a good title to express my question. Therefore, please parse the following code first.

# Minimal Code

\documentclass[dvips,dvipsnames,cmyk,table]{book}
\usepackage[a5paper,margin=20mm]{geometry}
\usepackage{longtable,array,calc}

\usepackage{listings}
\lstset{basicstyle=\scriptsize,tabsize=3}

\usepackage{fancyvrb}
\fvset{tabsize=3}
\def\Capture{\VerbatimEnvironment\begin{VerbatimOut}{\jobname.tmp}}
\def\endCapture{\end{VerbatimOut}}

\usepackage{environ}

\NewEnviron{Row}
{%
\expandafter\gdef%
\expandafter\gtemp%
\expandafter%
{%
%\begin{Capture}
%\BODY
%\end{Capture}
\expandafter&%
\tabularnewline%
\hline%
}%
\aftergroup\gtemp%
}

\newcolumntype{A}
{
>{\begin{minipage}{0.5\linewidth-2\tabcolsep-1.5\arrayrulewidth}\vspace{\tabcolsep}}%
c%
<{\vspace{\tabcolsep}\end{minipage}}%
}

\newenvironment{ComparisonTable}%
{%
\begin{longtable}%
{%
|A<{\lstinputlisting{\jobname.tmp}}%
|A<{\input{\jobname.tmp}}%
|%
}%
\hline\ignorespaces%
}%
{\end{longtable}}

\begin{document}
\begin{ComparisonTable}
%
% Row 1
\begin{Capture}
$$y=ax^2+bx+c$$
\end{Capture}
\begin{Row}
\end{Row}
%
% Row 2
\begin{Capture}
\Huge\LaTeXe
\end{Capture}
\begin{Row}
\end{Row}
\end{ComparisonTable}
\end{document}


# Objective

I want \Row to hide \begin{Capture}...\end{Capture} such that I can change

\begin{Capture}
$$y=ax^2+bx+c$$
\end{Capture}
\begin{Row}
\end{Row}


to

\begin{Row}
$$y=ax^2+bx+c$$
\end{Row}


How to do this?

-
You can make your code a bit shorter by converting successive empty lines into a single empty line. (But yes, including single empty lines is sometimes good to make the code clearer.) – Hendrik Vogt Jan 14 '11 at 17:28
Still working on this problem? Seems that you're close to a good solution! – Hendrik Vogt Jan 14 '11 at 17:44
@Hendrik: I want to close and abandon that topic. – xport Jan 14 '11 at 17:53

The following works without \NewEnviron; the idea is to put \begin{Row}\end{Row} at the end of the Capture environment. Moreover, you don't need all the \expandafters, and it suffices to define \gtemp once.

\documentclass[dvips,dvipsnames,cmyk,table]{book}
\usepackage[a5paper,margin=20mm]{geometry}
\usepackage{longtable,array,calc}

\usepackage{listings}
\lstset{basicstyle=\scriptsize,tabsize=3}

\usepackage{fancyvrb}
\fvset{tabsize=3}
\newcommand\gtemp{&\tabularnewline\hline}
\newenvironment{Row}
{\VerbatimEnvironment\begin{VerbatimOut}{\jobname.tmp}}
{\end{VerbatimOut}\aftergroup\gtemp}

\newcolumntype{A}
{
>{\begin{minipage}{0.5\linewidth-2\tabcolsep-1.5\arrayrulewidth}\vspace{\tabcolsep}}%
c%
<{\vspace{\tabcolsep}\end{minipage}}%
}

\newenvironment{ComparisonTable}%
{%
\begin{longtable}%
{%
|A<{\lstinputlisting{\jobname.tmp}}%
|A<{\input{\jobname.tmp}}%
|%
}%
\hline\ignorespaces%
}%
{\end{longtable}}

\begin{document}
\begin{ComparisonTable}
%
% Row 1
\begin{Row}
$$y=ax^2+bx+c$$
\end{Row}
%
% Row 2
\begin{Row}
\Huge\LaTeXe
\end{Row}
\end{ComparisonTable}
\end{document}

-
@Hendrik: Thanks for this great solution. Gradually my code becomes more compact. – xport Jan 14 '11 at 17:52
@Hendrik: Could you help me again to modify the code such that \Row accept one argument? See my update for the details. – xport Jan 15 '11 at 11:15
@xport: I think I don't know any more about environments with arguments than you do, so it would take me as long to solve this as it would take you. I'm sorry! – Hendrik Vogt Jan 15 '11 at 11:23
@Hendrik: I will create a new post for this, is it OK? – xport Jan 15 '11 at 11:44
@xport: I think this is the best idea. Please don't forget to make a rollback to the previous version in this question. (Usually it isn't good practise to ask a question, accept an answer and then extend the question.) – Hendrik Vogt Jan 15 '11 at 11:46