2

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}
\begin{equation}
 y=ax^2+bx+c
\end{equation}
\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}
\begin{equation}
 y=ax^2+bx+c
\end{equation}
\end{Capture}
\begin{Row}
\end{Row}

to

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

How to do this?

Display Name
  • 46,933

1 Answers1

3

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}
\begin{equation}
 y=ax^2+bx+c
\end{equation}
\end{Row}
%
% Row 2
\begin{Row}
\Huge\LaTeXe
\end{Row}
\end{ComparisonTable}
\end{document}
Hendrik Vogt
  • 37,935
  • @Hendrik: Thanks for this great solution. Gradually my code becomes more compact. – Display Name 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. – Display Name 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? – Display Name 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
  • @xport: OK, it turned out that the argument wasn't really the problem, so it wasn't too hard for me after all. – Hendrik Vogt Jan 15 '11 at 12:26