I have been using the following trick to obtain the contents of a paragraph. It works most of the time, but not on macros like \lipsum
or \end{document}
or \end{minipage}
which expand the \par
internally. Is there a way to fix this?
\documentclass{article}
\usepackage{lipsum}
\newcounter{count}
\def\mypar#1\par{\stepcounter{count}\thecount(#1)\addtocounter{count}{-1}\par}
\begin{document}
\everypar{\mypar}
This is a test.
\lipsum[1]
This is a new paragraph.
\end{document}
This also demonstrats that another \mypar
is executed when \lipsum
expands inside \mypar
(recursively).
If I convert my application to a macro instead of an environment, the inability to detect the end of the environment is no longer an issue. In other words, I could just live with it.
I believe I can detect the presence of a \par
inside a macro by expanding it in a \savebox
and using \everypar
to increment a counter. If I store the input data as a token list, one can add tokens without expanding them. So it is just a matter of adding tokens one at a time until one expands a \par
.
Of course, this only works if the macro has a single \par
at the end. Macros like \item
which have a \par
at the beginning cannot be used with \parshape
(unless modified).
\lipsum*[1]
?lipsum
? Or just a general question about some areas where your\mypar
doesn't work as expected?\AtEndDocument{\par}
.shapepar
package.