# paracol and environments: reflexion aroung the way environments work

I'm facing an interesting problem. In my mind, the environments are defined my a name, a code to execute at the beginning and a code to execute at the end.

Yet, I'm trying to do:

\documentclass[]{article}

\usepackage{paracol}
\usepackage{lipsum}

\newenvironment{env1}{%
\begin{paracol}{2}%
}{}

\newenvironment{env2}{%
\switchcolumn
}{%
\end{paracol}%
}

\begin{document}

\begin{env1}
\lipsum[1]
\end{env1}

\begin{env2}
\lipsum[1]
\end{env2}

\end{document}


but this does not work.

That sounds very strange to me as I thought the environments begining and end codes were executed at that's written in the definition. This small example shows the environment definition does something else.

How to make my code work ?

Other question: the code does not work if I put \switchcolumn at the end code of env1. What's going on ?

## Edit

To understand the purpose, have a look at this question I asked 2 days ago. That was the same problem with the markdown package. These environments are the basis for a recipe book implementation.

I'd like to start the paracol environment at the beginning of the ingredient environment and finish it at the end of the preparation environment (eventually, at the end of the recipe environment would be ok also.

• Could you please add some background information about the purpose of these environments? Mar 23 '20 at 12:55
• Environments are executed inside a group. Mar 23 '20 at 13:38
• Paracol already provides column and nthcolumn environments. The only thing they can't do is start and stop paracol itself. Mar 23 '20 at 14:59

I don't think you gain much by doing this split. Anyway, you can do it in a different way.

Why doesn't your way work? Because environments form groups, so when you close your env1, much of the setup done by \begin{paracol}{2} is forgotten.

\documentclass[]{article}
\usepackage[latin]{babel}

\usepackage{paracol,environ}
\usepackage{lipsum}

\NewEnviron{env1}{\global\let\envone\BODY}
\newenvironment{env2}{%
\paracol{2}\envone\switchcolumn
}{\endparacol}

\begin{document}

\begin{env1}
\lipsum[1]
\end{env1}

\begin{env2}
\lipsum[1]
\end{env2}

\end{document}


I used latin just to get good hyphenation in narrow columns.

The first environment just stores the text, which is used in the second one.

• Thanks, that works perfectly. I need such separation as env1 is an environment containing the ingredients of the recipe while env2 is for preparation. I need this distinction for clarity. Mar 23 '20 at 17:31

You can do it (more or less) using the environ package. You can store the text as a global macro, savebox or token list (I believe \BODY is a token list).

\documentclass[]{article}

\usepackage{paracol}
\usepackage{environ}
\usepackage{lipsum}

\newsavebox{\mycolumn}

\NewEnviron{env1}{%
\global\setbox\mycolumn=\vbox{\hsize=\dimexpr 0.5\textwidth-0.5\columnsep\relax
\BODY}%
}

\NewEnviron{env2}{%
\begin{paracol}{2}%
\unvbox\mycolumn
\switchcolumn
\BODY
\end{paracol}%
}

\begin{document}
\sloppy% for lipsum in particular

\begin{env1}
\lipsum[1]
\end{env1}

\begin{env2}
\lipsum[1]
\end{env2}

\end{document}