In the context of writing something like homework solutions for a math class, I often face an awkward situation. Each problem will have some idiomatic functions that are cumbersome and error prone to rewrite. For example,
f(x)=\sup_{\xi\in\mathcal{A}}\sum_{k=1}^\infty \phi_k(x,\xi)
One solution, to avoid rewriting the right hand side is
\newcommand{\f}[1]{\sup_{\xi\in\mathcal{A}}\sum_{k=1}^\infty \phi_k(#1,\xi)}
This allows me to write out the right hand side in its entirety with less chance of typos, when I don't need to manipulate the subparts of the expression, making for cleaner code. However in some cases, the function f
may take on different definitions in different problems, so I would often need to redefine it.
Is there a way to make a definition local to some part of the code so that the redefinition will have less chance of affecting the other parts of my code in case I forget to redefine the variable? This is especially important if formatting the function requires some manual spacing adjustments which make the code cluttered.