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
\parinternally in ways that I don't want to touch. - Other environments (e.g., also lists) clobber my redefinition of
\parglobally. - There should be an easy way to exclude a set of paragraphs from the
\parredefinition.
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?
\gdefthis? 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. – barbara beeton Dec 14 '11 at 19:08\gdefis 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. – Chel Dec 14 '11 at 19:11\a{\a}to use two different defs for\acan only be done using\currentgrouplevelor\currentgrouptype. Reverting the\gdef\a{weird}at the end of the{}group is doable with\aftergroup. – Bruno Le Floch Dec 14 '11 at 20:12\currentgrouplevelis exactly what I wanted before I asked the question. If I combine that with someeveryhookstuff, I think that'd put me well on my way to a solution. Thanks! – Chel Dec 14 '11 at 20:45