In order to reduce copy-pasting, I want to create an environment that will produce a two-column table with headers and two listings in different languages, like below:
\begin{tabular}{l l}
Python & Haskell \\
\hline \\
\lstset{language=Python}
\begin{lstlisting}
A
\end{lstlisting}
&
\lstset{language=Haskell}
\begin{lstlisting}
B
\end{lstlisting}
\end{tabular}
I want to use it like below, hiding everything but code:
\begin{comparison}
A
\vs
B
\end{comparison}
So far I tried making two new environments (instead of a \vs command inside) with \lstnewenvironment, where first environment had \tabularx command and second \endtabularx. I also tried creating normal \newenvironment for this tabular, & for \vs command and manually inserting \begin{lstlistings} and \end{lstlistings} with code, but it stopped compiling when I put lstlistings inside.
How can I create such an environment?
EDIT: The most compact version I've came up with until now is
\newenvironment{comparison}
{\begin{parcolumns}[nofirstindent,distance=0pt,colwidths={1=0.35\textwidth}]{2}}
{\end{parcolumns}}
\lstnewenvironment{python}
{Python
\lstset{language=Python,frame=t}}
{}
\lstnewenvironment{haskell}
{Haskell
\lstset{language=Haskell,frame=t}}
{}
which is used like that:
\begin{comparison}
\colchunk{
\begin{python}
A
\end{python}
}
\colchunk{
\begin{haskell}
B
\end{haskell}
}
\end{comparison}
I'm still unable to hide \colchunk{} within python or haskell environments.

\newenvironmentbecause precautions have to be taken to define a new environment that is supposed to have some verbatim content. Thelistingspackage provides the\lstnewenvironmentmacro to create new environments for listings, but those environments can only contain one listing. You may have to define a new macro based on\lstnewenvironmentto achieve what you want. – jub0bs Dec 03 '13 at 17:20\tabularxinstead of\begin{tabularx}. Also, tabularx doesn't work well with verbatim-like environments inside, so I'm thinking of multicols/tabular and adding lstlistings environments manually (with options and headers hidden in my command). – Xilexio Dec 03 '13 at 17:50