I'm writing a long document and as a general rule, I try to write things down semantically. For example, when I introduce notation for $\mathcal{A}$ and $\mathcal{B}$, I add the following at the beginning of my section:
\section{An example section title}
\newcommand{\MySpecialA}{\mathcal{A}}
\newcommand{\MySpecialB}{\mathcal{B}}
Some example text. We see that \(\MySpecialA \neq \MySpecialB\)!
I will then always use my own commands. This makes formulas more readable and refactoring very easy.
However, these definitions are then available for the rest of the document, not only this section. I could use these later by accident. Also, when I want to use the same name for a variable later on, I have to be careful when overwriting it.
Is there a better way to handle these "scoped commands/variable names"?
\begingroupand\endgroupdirectives. – Mico Jan 25 '24 at 13:05\sectioncommand in a custom environment? Like a new environment which takes a section title, puts it into the section command and then adds the remaining content? Edit: see answer by @Cube707 – mixotrov Jan 25 '24 at 13:25\begingroupand\endgroupdirectives in suitably chosen locations is what you need. – Mico Jan 25 '24 at 13:36