As some of you may know, you can use \newcommand
and \DeclareMathOperator
to create new TeX macros. For example, $\DeclareMathOperator{\cosine}{cosine}$
$\DeclareMathOperator{\cosine}{cosine}$ allows you to write $\cosine$
and see $\cosine$. Unfortunately, using either of these commands affects the entire page they were used on, not just the question or answer they were used in. This would seem like terrible programming practice. However, there are obviously benefits to this. For example you don't need to write $\operatorname{Hom}$
ten times because you prefer a capital 'H'.
I've been avoiding using these commands myself because I think it is a better practice, but I am starting to wonder if I am being overly cautious.
Are there instances where it is ok to use these commands? Are there instances where it is crucial not to use these commands? (Other than purposeful destruction of course.)
Of course, one should not renew commands (e.g. $\renewcommand{\mathbb}{\mathbf}$
)
Some behaviour tests:
$\DeclareMathOperator{\Hom}{Hom} \Hom$
$\DeclareMathOperator{\Hom}{hom} \Hom$
$\newcommand{\Hom}{\text{apple}} \Hom$
$\DeclareMathOperator{\Hom}{Hom} \Hom$
$\DeclareMathOperator{\Hom}{Hom} \Hom$
$\DeclareMathOperator{\Hom}{hom} \Hom$
$\newcommand{\Hom}{\text{apple}} \Hom$
$\DeclareMathOperator{\Hom}{Hom} \Hom$
It seems like using these commands overwrites previous definitions. If this is the case then it would seem like there is no danger of conflict.
\newcommand
is arguably a bit too strong - it will happily let you do things like\newcommand{\sin}{\operatorname{\cos}}
. That's obviously not OK on SE sites. $\endgroup$\let\phi\varphi
if the question uses\varphi
and I feel lazy. Apparently I should better not do that in the future ... $\endgroup$