# When is it ok to use \newcommand and \DeclareMathOperator?


If you're still feeling suspicious, you can check for yourself (e.g. using the Markdown preview feature in the "post an answer" box below) that the sneaky redefinitions used in the first formula above indeed do not leak out of this answer, thanks to the \endgroup after them.

Also, I'd be remiss if I didn't mention that the Stack Overflow Unofficial Patch (SOUP) user script / browser extension, which I maintain, automatically limits the scope of MathJax macro definitions to individual posts. However, it only does that when you're viewing the page with SOUP installed; if you don't use \begingroup / \endgroup in your own posts, any macros you define in them can still leak out when other users view them. Hopefully, someday something like this restricted macro scope feature will be adopted into the SE codebase itself, making this \endgroup trick unnecessary.

*) An unfortunate exception is the snippet view on the search page, which isn't MathJax-aware and may end up including the macro definitions in the snippet but leaving out the \endgroup. SOUP also includes a fix for this issue.

• Doing it this way should be required. Potentially modifying the content in other people's posts, without directly editing those posts, is just bad. Jun 21, 2017 at 2:03