我找不到一个好的标题来表达我的问题。因此,请先解析以下代码。
最少代码
\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}
客观的
我想\Row
隐藏起来\begin{Capture}...\end{Capture}
以便可以改变
\begin{Capture}
\begin{equation}
y=ax^2+bx+c
\end{equation}
\end{Capture}
\begin{Row}
\end{Row}
到
\begin{Row}
\begin{equation}
y=ax^2+bx+c
\end{equation}
\end{Row}
这个怎么做?
答案1
以下操作无需\NewEnviron
;其想法是将其放在环境\begin{Row}\end{Row}
的末尾Capture
。此外,您不需要所有的\expandafter
s,定义\gtemp
一次就足够了。
\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}