Okay, I know this is a pretty tall order, but I'm working on a package based on my answer here, and I'm including Ahmed Musa's environment which redefines \par
. The problems are:
- Some environments (e.g., lists) use
\par
internally in ways that I don't want to touch. - Other environments (e.g., also lists) clobber my redefinition of
\par
globally. - There should be an easy way to exclude a set of paragraphs from the
\par
redefinition.
And it's all well and good to just explain in the documentation that the environment which redefines \par
is for convenience only and that you should only really put flat text in it. But I was wondering if there was a better way.
What I want to do, if possible, is redefine the macro (really \par
, but let's call it \a=\a@new
) in such a way that when any environment or {
-delimited group begins, it gets set to \a@old
. And then when that specific environment or group ends, it should be set right back to \a@new
, even if \a
got globally redefined in the interim.
So, disregarding whitespace,
\def\a{old a}
\def\a@new{new a}
\a
\begin{redefa}
\a
{\a}
{
\gdef\a{\emph{weird} a}
\a
{\a}
}
\a
\end{redefa}
\a
Should give
old a
new a
old a
weird a
weird a
new a
old a
Is this even remotely possible?
\gdef
this? if you simply\def
(or better, for latex,\renewcommand{\a})
inside the group, then it will automatically go back at the end of the group to its definition before the group was opened.\gdef
is what other packages apparently do, and I'm trying to clean up after that. @JosephWright Yeah, I know this could mean sanitizing a hack with an even worse hack. But at least partly I'm asking this out of curiosity.\a{\a}
to use two different defs for\a
can only be done using\currentgrouplevel
or\currentgrouptype
. Reverting the\gdef\a{weird}
at the end of the{}
group is doable with\aftergroup
.\currentgrouplevel
is exactly what I wanted before I asked the question. If I combine that with someeveryhook
stuff, I think that'd put me well on my way to a solution. Thanks!