# How make \parshape declared inside an environment to apply the next paragraph outside the environment?

I'm trying to do something like the MWE below:

\documentclass{article}
\usepackage{lipsum}

\newenvironment{myenv}{%
\parshape = 4
0pt 0.5\textwidth
0pt 0.5\textwidth
0pt 0.5\textwidth
0pt \textwidth
}{}

\begin{document}

\begin{myenv}
\end{myenv}%
\lipsum[1]

\end{document}

I need the \parshape declared inside the myenv environment to apply to the next paragraph that follows the myenv environment. But obviously it doesn't do that right now. Is there anyway of getting that to work?

• This seems like a very odd thing to do: could you give us a little more context? – Joseph Wright Aug 31 '13 at 19:27
• I'm basically trying to do my own implementation of wrapping around a figure with text. So I declare the figure using an environment, which then generates the \parshape that create the empty space in which the figure will be put. But since the \parshape is declared inside the environment, it doesn't apply to the paragraph which comes first after the environment. I know there's various packages for this but I've not been satisfied with them. Also, I like the challenge. =) floatflt and wrapfig do this with environments so it is possible (I think). – gablin Aug 31 '13 at 19:31

Please always post complete documents not just fragments.

Note setting \parshape in LaTeX is almost always the wrong thing to do unless done with great care (almost all LaTeX constructs use the \list mechanism which relies heavily on \parshape not being messed with).

However

\documentclass{article}
\usepackage{lipsum}
\newenvironment{myenv}{%
\gdef\foo{\parshape = 4
0pt 0.5\textwidth
0pt 0.5\textwidth
0pt 0.5\textwidth
0pt \textwidth}\aftergroup\foo
}{}

\begin{document}

\begin{myenv}
\end{myenv}%
\lipsum[1]

\end{document}
• It was a complete example, but I forgot an additional linebreak so the beginning of the code got put into the running text above. I've edited the question accordingly. – gablin Aug 31 '13 at 19:33
• Cool, it works! Although it requires that myenv and the next paragraph are not separated by a linebreak, but that's a minor thing. Could you please explain how it works? I'm not familiar with \gdef and \aftergroup. – gablin Aug 31 '13 at 19:38
• @gablin TeX resets the \parshape at each \par. This can be subverted (see for example l3galley), but I think I'd avoid that in LaTeX2e as things rely on \par's behaviour. – Joseph Wright Aug 31 '13 at 19:41
• @gablin \gdef makes a global definition so it is in force after the environment and \aftergroup inserts a token just after the current group ends. – David Carlisle Aug 31 '13 at 19:55
• I would have approached this a bit differently by putting the \aftergroup\foo in the closing part to the definition of the new environment. Why does putting it into where you have work? – A.Ellett Aug 31 '13 at 20:22