Not too long ago, a Stack Exchange software was changed in such way that macros defined in a post are valid only inside that post (similarly for comments). It was announced in an answer on this meta: The scope of \newcommand is the entire page.1
However, as titles are not enclosed in begingroup..endgroup, if a macro is defined in the title, it is still valid on the entire page (in the question, the answers and the comments).2 (You may also notice that the problem with the titles was mentioned by Joel Reyes Noche and quid in the comments under the linked answer.)
Would it be useful to include add begingroup..endgroup also for titles? (In the same way they are added around answers, questions, comments.)
Or would blacklisting
\newcommand
,\renewcommand
,\def
,\DeclareMathOperator
in the titles be a better solution?
One issue is the consistency. It seems unusual that in the posts, macros are limited only for the given post (and the same for comments), while macros defined in the title work on the entire page. There is a separate question whether macros should be used in the titles at all.
On one hand, using macros defined directly in the titles is probably not good practice, it is even explicitly mentioned in Guidelines for good use of $\rm\LaTeX$ in question titles. However, I think the main reason for that recommendation is probably the fear that the macro definition can "spill" into other posts (when the title is in the list of questions, frontpage, linked questions, related questions, etc.) and cause some problems.3
On the other hand, if adding begingroup .. endgroup around the title prevents the possibility that the macro defined in the title can cause problems elsewhere, perhaps there can be some legitimate uses. For example, by defining macro the source code can be made shorter and more readable. (One such instance would be using \operatorname
only once in the macro definition, if the same operator is used several times in the title.) Readability matters for users editing the post - and also in the cases when the title of a question appears in some place where MathJax is not rendered.
Although macros in the title very likely bring all sorts of technical issues. Probably it's possible to make sure that the macro does not "leak" out of the title when the title appears within Stack Exchange networks - but it's reasonable to assume that the titles of posts from this site are also used elsewhere. Another issue is how the macros would be handled in the citations created by cite button. (And possibly many other problems which I have completely missed.)
1The same change is also mentioned on the networkwide meta in the post Recent feature changes to Stack Exchange: "2019-01-14: On sites with MathJax enabled, the effect of \newcommand
and similar directives is now scoped to individual posts and comments rather than the entire page. (Bug report on Math.SE's meta)"
2I have edited several instances of macros defined in the titles following the recommendation in the linked thread - perhaps I should have asked first (before the edits) here on meta how this recommendation is influenced by the recent changes in Stack Exchange software. Using SEDE, you can find posts where \DeclareMathOperator, \newcommand, \renewcommand or \def was removed from the title at some point.
Still, here are some examples showing that macros defined in titles are valid on the whole page: This question (Wayback Machine) has macro \Q defined in the title, it is used in the question without being defined in the body. This question (Wayback Machine) has macro \Re defined in the title - it is used in the question without being defined in the body. To include also one particularly bad example, in the title of this question (Wayback Machine) the macro \int is defined as \operatorname{int}
$\operatorname{int}$ which overrides the usual meaning of \int
$\int$.
To find questions where the title contains a macro definition, you can search for title:\DeclareMathOperator, title:\newcommand or title:\renewcommand. For \def it is better to use a SEDE query, since the built-in search would return quite a few false positives.
3Here is an example of a problem which was caused by a macro defined in the title: A possible bug regarding MathJax, previews, and the arctangent/tangent functions?