7:49 AM
There were recently two posts on meta about problems which can be caused by newcommand/DeclareMathOperator/def in the title.
Typically when such posts appears among linked or related questions.
5

A linked question contained some malicious code in the title. I've removed it.

6

So I just passed the 2,000 rep threshold this morning and, eager to try out my newfound powers of automatic editing, I went ahead and looked for the first post I could find that could use some prettying up. I quickly found a post that was well written but had some funky-looking italic math format...

Perhaps a warning not to do this should be included in Guidelines for good use of $\rm\LaTeX$ in question titles.
Oh, I see it already is there:
5

I think that we should also forbid \newcommand on the title. Sure, if done right there's no harm in this, but this can be a huge slippery slope for either small mistakes that accumulate to ravage the front page, or worse.

Anyway, we should probably edit out occurrences of newcommand and DeclareMathOperator in the titles.
Searching for \def using built-in search does not work well: math.stackexchange.com/search?q=title%3A%5Cdef But we should be able to find such posts using SEDE: data.stackexchange.com/math/query/972169/…
@quid I remember that you have used Is this true: $\DeclareMathOperator{\Hom}{Hom}\Hom_R(S,R) \otimes_S P \cong \Hom_R(P,R)$? for testing purposes (in connection with one of the questions above).
I guess further tests are no longer needed - so it would be ok to edit this away from that question too.
I hope I'll find some time to start doing such edits later this week. The searches I linked above suggest that it's about 50 questions. (Well, unless I missed some other command that causes problem - apart from \newcommand, \DeclareMathOperator and \def.)

@MartinSleziak I removed it now.

Ok, I'll have to leave now, but I hope I'll find some time to look into this later.

I agree that this should be edited away. Another question would be if we should report it as a "missing case" now that it is fixed for most other thngs (posts and comments)
See you!

I don't really know what you mean by "fixed for posts and comments".
AFAICT if a post or commend contains newcommand without begingroup..endgroup that can still cause some problems.

@MartinSleziak math.meta.stackexchange.com/a/29621 I thought that's automatic since recently.

8:03 AM
11

It pains me to break this thread by fixing the issue, but here we are. :) We are now inserting \begingroup and \endgroup directives into post and comment bodies, so all command definitions should be scoped to individual posts. For now, I'm only enabling this on Math (and here on meta), but barr...

Oh, I completely missed that. This change is very recent.
A possible solution for titles would be to use begingroup/engroup also there. Another possibility is to forbid/blacklist \newcommand (and relatives) in the titles.
It seems that the issue isn't completely fixed. See math.meta.stackexchange.com/q/29702/18398Joel Reyes Noche 4 hours ago

Yes I just realized that.

Thanks for that! See you later!

12 hours later…
8:23 PM
Actually I have just realized that the solution with begingroup possible broke a few things.
> We are now inserting \begingroup and \endgroup directives into post and comment bodies, so all command definitions should be scoped to individual posts.
Previously people might have used macros which were defined in the question also in answers and comments - and they worked fine. But now that begingroup ..endgroup was added, they no longer work.
I have noticed this in the following comment:
@Did Uh, but I wanted that part. The bounds $\sqrt x$ and $\frac{1+x}2$ meant that $\agm(1,x)\in\mathcal O(x^\epsilon)$ for some $\epsilon\in[0.5,1]$, right? — Simply Beautiful Art Aug 19 '17 at 11:24
I do not know whether the comment was displayed fine before I edited the title.
Here is an example of a comment which is "broken" after this change:
I'm found $\rank(A + 4I_4),\rank(A + 4I_4)^2, \rank(A + 4I_4)^3, \dots$ then I calculated the number of Jordan blocks — Minh Dec 21 '18 at 4:07
And another one:
Well, the $\rank$ function is a function. So if $\bigcup x=x$, how can it have two different ranks? — Asaf Karagila ♦ Apr 21 '14 at 20:37
Both of them found by looking through comments containing \rank.
Is there actually some way this can be fixed other than manually editing the comments? (Which can only be done by mods - maybe in some cases it would be possible to delete and repost the comments without breaking the flow.)
Here is my answer which is now not displayed correctly: Subset of a P-ideal need not be a P-ideal. (I will edit it later, but it's good to have an example for the time being.)
Of course, there will be no such problems for questions where the OP used begingroup..endgroup.
I will just add a ping for @quid - since we discussed this recent change in using \newcommand earlier today.

@MartinSleziak Hmm, I don't think there is a way. I suppose one could write a query to find tex commands that aren't standard (after assembling all the standard ones)... but that sounds maybe impractical and at the least very annoying.

8:40 PM
Considering that there are thousands of posts which use newcommand, checking all of them seem like a huge task.
Probably it would be good to know at least what to do if somebody stumbles upon a problematic comment. (Posts can be edited by regular users.)
And this morning I though that the only posts that need attention are the ones with newcommand (and relatives) in the title, which is about 50.
I'd guess that this problem deserves a separate question on meta. But I'll wait first a bit to see what quid says (since originally this started as a discussion with them).
I also have to say that I do not have too much time these days, so if somebody decides to report this on meta, feel free to do so.
Here are too more examples of answers which are "broken" after this change: math.stackexchange.com/questions/168592/… and math.stackexchange.com/questions/168592/…
It seems that I am quite a bad offender regarding this issue.

@MartinSleziak This is actually sort of impressive. It means you looked at source to see what commands someone else edited, and then you began to use them.
I don't think I've ever done this.

8:56 PM
I probably did not know about potential problems back then.
And in some cases is possible that I thought that it would be nice to have consistent notation throughout both question and answers = and if the OP decides to tweak the notation slightly, there is only one place where the change is needed.
Simply said, I was quite foolish.
But certainly I am not the only user doing this: math.stackexchange.com/questions/540135/…
See you later!
BTW apart from \rank, the string \lcm seems like a good candidate to find some examples of broken comments, too.
(cont) as when we divide $-1$ by $m$, since $m$ divides $M$. Finally, we must show that no positive integer $x<M-1$ works. If $x$ leaves the right remainders, then since $-1$ also leaves the right remainders, $x-(-1)$ must be divisible by all of $2$ up to $10$. So $x+1$ must be divisible by the $\lcm$ of the numbers $2$ to $10$. It follows that $M$ divides $x+1$. The smallest positive $x$ for which this is true is $x=M-1$. — André Nicolas Feb 21 '12 at 7:48

2 hours later…
11:21 PM
@MartinSleziak thanks for the update. At some point I said on our meta (or maybe meta.MO) that if it was up to me newcommand and alike would've been blocked.
@MartinSleziak I'd say flag for mods. We sometimes get such flags. If people do that as they stumble over it, it could be mangable.
On the plus side often things stay comprehensible.
In addition it could be an occasion to evaluate if the comment should stay or if it could not be an edit to the post.