Is it possible to define commands in a separate namespace so that they only work within a particular environment?
For example, can I create a package named foo that defines a foo environment and a \newfoocommand that works something like this:
\documentclass{article}
\newcommand{\asdf}{do something}
\newcommand{\zzz}{zzz}
\usepackage{foo}
% doesn't conflict with the above \asdf command because it's in a different
% namespace.
% this actually does \newcommand{\@foo@cmd@asdf}{do something else}
\newfoocommand{\asdf}{do something else}
\newfoocommand{\jkl}{blahblah}
\begin{document}
% expands to "do something"
\asdf
% expands to "zzz"
\zzz
% causes: ERROR: Undefined control sequence.
\jkl
\begin{foo}
% is interpreted as \@foo@cmd@asdf and expands to "do something else"
\asdf
% expands to "zzz" because \@foo@cmd@zzz isn't defined
\zzz
% is interpreted as \@foo@cmd@jkl and expands to "blahblah"
\jkl
\end{foo}
% expands to "do something"
\asdf
% expands to "zzz"
\zzz
% causes: ERROR: Undefined control sequence.
\jkl
\end{document}