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.)

  1. Would it be useful to include add begingroup..endgroup also for titles? (In the same way they are added around answers, questions, comments.)

  2. 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?

  • 2
    $\begingroup$ I was not entirely sure whether to post this here on the network-wide meta. Since the previous discussion and the announcement of the change were posted on this meta, posting follow-up here seemed reasonable to me. $\endgroup$ Commented Jun 17, 2019 at 13:39
  • 4
    $\begingroup$ Blacklist them all. $\endgroup$
    – Asaf Karagila Mod
    Commented Jun 19, 2019 at 5:53
  • $\begingroup$ @AsafKaragila I wonder whether this was originally an answer and it was autoconverted to a comment. On a more serious note, perhaps with adding a few sentences about the reason why blacklisting is the way to go, your comment could be expanded to an answer - which would have the advantage that other users could leave some feedback on this. (If nothing else, at least by upvoting/downvoting.) $\endgroup$ Commented Jun 19, 2019 at 5:57
  • 1
    $\begingroup$ Yes, but that might take a few days, since I'm traveling right now. So I left the comment to record my view on this. $\endgroup$
    – Asaf Karagila Mod
    Commented Jun 19, 2019 at 5:58
  • $\begingroup$ @AsafKaragila I have posted a CW answer which suggest to blacklist such stuff in titles. Feel free to comment there if something should be added. (From your previous comment I gather that you are now accessing the site mostly from mobile devices - which probably makes editing more difficult.) $\endgroup$ Commented Jun 19, 2019 at 8:06
  • $\begingroup$ You wrote "There is a separate question whether macros should be used in the titles at all." It seems illogical to propose such blacklisting before addressing this more fundamental matter, i.e. if someone makes a strong argument for needing such capability then that will certainly influence decisions on this matter. That some users cannot imagine a good use for something does not imply that it should be blacklisted (when instead it could easily be made safe). What's next, blacklisting of infinitesimals and surreals on main? $\endgroup$ Commented Jul 7, 2019 at 13:59
  • 1
    $\begingroup$ I have raised this on Meta Stack Exchange, perhaps in that way we are more likely to get some response from the Stack Exchange team: Shouldn't the titles be enclosed in the begingroup..endgroup, too? $\endgroup$ Commented Sep 13, 2020 at 9:29

1 Answer 1


Proposal: Defining macros in the titles should be strongly discouraged and we should ask Stack Exchange to add them to blacklisted phrases in the titles.1 This would mean blacklisting: \DeclareMathoperator, \newcommand, \renewcommand, \def\ in the titles.2,3,4 Possibly also \let - as pointed out by Hagen von Eitzen in the comments.

Here are some problems that might be caused by macros in the titles:

  • A macro defined in the title can "spill" into other places. (And some examples showing that this can cause problems can be found on this meta.) Since the titles are displayed in many places on the site, it's probably not that easy to take care of all of them.
  • It's quite plausible to assume that titles from this site can be displayed in many other places online, some of them do render MathJax. Even if the titles on this site are inside begingroup...endgroup and this prevents potential collision, we cannot be sure about the same thing on other sites.
  • Cite button is intended to make easily accessible BibTeX entries for posts on Stack Exchange sites. If the title contains macro definitions, people using those citations in their documents would have to edit them manually.

1For the stuff that is currently blacklisted, see: Which are blacklisted tags and blacklisted phrases?

2Notice that in MathJax all of these syntaxes work: \DeclareMathOperator{\rk}{rank}, \DeclareMathOperator\rk{rank} and \DeclareMathOperator{rk}{rank}. It is similar for \newcommand and \renewcommand (where \newcommand{\Lim}{....}, \newcommand\Lim{....} and \newcommand{Lim}{....} are valid). This should be kept in mind when creating a regex for the blacklist. (There is a difference between MathJax and LaTeX - in LaTeX \DeclareMathOperator{rk}{rank} and \newcommand{Lim}{....} don't work.)

3In the case of \def we should be careful not to blacklist some legitimate MathJax/LaTeX commands which have \def as a prefix. (Although I cannot think of any from the top of my head.) As far as I know, when \def is used to define a macro, it has to be followed by a backslash.

4As pointed out in the comments, some questions with \newcommand in the title outside math mode might be a legitimate question about use of \newcommand. Such questions are more likely to be on-topic on meta than on main. Nevertheless, this is another thing to keep in mind when actually blacklisting the commands for defining macros.

I have posted this as an answer - this suggestion was made in comments, but answer is a better option for getting some feedback from the community. (Even if nobody posts a comment, at least from upvotes/downvotes we can see something about opinions of users around here on this.)

The answer is community wiki feel free to edit it further if needed. (Of course, without changing it to the opposite position.)

  • 1
    $\begingroup$ But you might want to ask about those macros, and then use the macro names in the title for that purpose. I think blacklisting would prevent that as well. Unless it is possible to blacklist them only inside MathJax expressions, I'm against blacklisting. (BTW, is blacklisting site specific? Because blacklisting any LaTeX macro names in titles would be terrible for tex.SE) $\endgroup$
    – celtschk
    Commented Jun 20, 2019 at 10:37
  • $\begingroup$ @celtschk AFAICT, different sites has different blacklists for titles, tags, post bodies. Regarding blacklisting only inside MathJax, perhaps somebody with more experience in regular expressions can tell how difficult it would be. However, I have difficulties imagining on-topic question on Mathematics Stack Exchange where "\DeclareMathOperator" would be needed in the title - and even if there are such questions, I think that very likely changing "\DeclareMathOperator" to "DeclareMathOperator" would not decrease readability that much. $\endgroup$ Commented Jun 20, 2019 at 10:41
  • $\begingroup$ Still, pointing out that blacklisting only inside MathJax could be reasonable is a very good point. $\endgroup$ Commented Jun 20, 2019 at 10:41
  • 1
    $\begingroup$ Given that double dollar signs are already blacklisted, I guess it would be as simple as checking that there's an odd number of dollar signs preceding it (are there any ways to trigger MathJax without a dollar sign?) $\endgroup$
    – celtschk
    Commented Jun 20, 2019 at 10:46
  • $\begingroup$ @celtschk I believe that stuff such as \begin{equation}x^2+y^2=z^2\end{equation} or \begin{pmatrix} \lambda & 1 & 0 \\ 0 & \lambda & 1 \\ 0 & 0 & \lambda \\ \end{pmatrix} is a way to get MathJax without dollar signs. However, I think that most users include dollar. Just as an experiment, I have tried whether I'd be allowed to used them in a title (after the test I have immediately deleted the question). $\endgroup$ Commented Jun 20, 2019 at 11:09
  • $\begingroup$ In any case, I think that such environments are rather rarely used edge cases. (Which is probably the reason that they have not even been blacklisted in the titles. Blacklisting equation environment probably makes sense if $$..$$ is blacklisted - but as hardly anybody would use them, they were probably not worth blacklisting.) $\endgroup$ Commented Jun 20, 2019 at 11:09
  • 1
    $\begingroup$ @celtschk: Blacklisting is not only different for different websites, it is also different between a site and its meta. If someone wants to ask, on the main site, a question where \DeclareMathOperator is in the title, not in an "active capacity", then this question is in fact off topic. $\endgroup$
    – Asaf Karagila Mod
    Commented Jun 27, 2019 at 13:14
  • $\begingroup$ @AsafKaragila: OK, so on the main site it can be blacklisted unconditionally, but the problem of course exists on the meta site as well. $\endgroup$
    – celtschk
    Commented Jun 27, 2019 at 17:23
  • 1
    $\begingroup$ @celtschk: Yes, but there's not as much math on meta for this to be a serious problem. It would be reasonable to allow these on titles on meta, and we should just make sure that the usage is not... trollish. $\endgroup$
    – Asaf Karagila Mod
    Commented Jun 27, 2019 at 17:24
  • 2
    $\begingroup$ Also block \let? $\endgroup$ Commented Jun 30, 2019 at 2:55
  • $\begingroup$ To add to Hagen von Eitzen's comment, I did not find posts with \let in the title. There were two questions where \let was in the title, by it was later edited away: chat.stackexchange.com/transcript/88939/2019/6/30 $\endgroup$ Commented Jun 30, 2019 at 10:45
  • 1
    $\begingroup$ \DeclareMathOperator{rk}{rank} and \newcommand{Lim}{…} don't work in LaTeX (with default catcodes), but the other two (with or without braces around the command name) work just fine in LaTeX. $\endgroup$
    – LSpice
    Commented Jul 5, 2019 at 2:51
  • 1
    $\begingroup$ @LSpice Thanks for letting me know. I have edited the post - feel free to edit it further, if needed. (After all, it is community wiki.) $\endgroup$ Commented Jul 7, 2019 at 7:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .