# Is it possible to see the source for a comment?

Although this question seems to be new to M.MO, @MartinSleziak points out several related posts on Meta.MSE.

I was curious about the diagrammatic magic of @YaakovBaruch's recent comment, and so clicked on the relevant diagram and viewed its TeX source.

This source turned out to use a macro \x which, I assume, was defined earlier in the comment. In this case, I think that I can find the definitions in the parent post Tiling rectangle with trominoes — an invariant; but let's imagine that I couldn't. (Actually, @MartinSleziak pointed out in chat that I was viewing the TeX source for the wrong diagram, so the resolution in this case was even easier than I thought! But the main question still stands.)

Is there any way to see the entire MathJax source for a comment, as there is for a post?

• Using mod powers, I see that the macro actually is defined in the comment. But the macro command seems to be stripped out when I ask my browser to display the Latex commands. I don't know the answer to your meta question, but in order to ease your curiosity, and at risk of spilling YaakovBaruch's trade secrets, I can reveal that the macro is \newcommand{\x}{\large\blacksquare}
– Tim Campion Mod
Jul 11, 2022 at 22:37
• @TimCampion, thanks! But, without invoking a mod's powers or—horror of horrors!—asking the original commenter, there would have been no way to see the macro definition? Jul 11, 2022 at 22:40
• Right. I would assume the same issue arises when a macro is defined in a question or answer, but you've just never noticed it because you can always open the question / answer for editing and see the source there.
– Tim Campion Mod
Jul 11, 2022 at 22:41
• @TimCampion, thanks again! That seems like an answer; would you post it so I can accept it? Or, if the matter is too trivial, then I can close or delete my question. Jul 11, 2022 at 22:44
• I'm too tired to write a full answer, but let me just note that there's a userscript for this. (Actually, there's more than one.) Jul 17, 2022 at 23:43

One approach would be to use the MathJax contextual menu to select the "Plain Source" renderer, which will show the TeX commands rather than typeset expressions. That means you would not have to locate "invisible" expressions. You could then change back to whichever renderer you usually use when you are done.

• I thought I'd commented to thank you for teaching me this neat trick, but I seem not to have done—or else it got deleted for some reason. Either way, to be on the safe side, I'll say thank you again! Jul 12, 2022 at 20:51
• For others like me whose brains are working slowly in the heat: To bring-up the contextual menu, right-click (or ctrl-click) on any piece of MathJax, then follow the submenus $\textsf{Math Settings}$ ▶ $\textsf{Math Renderer}$ ▶ $\textsf{Plain Source}$. Try it out here: $|\mathbb{N}| = \aleph_0$. Jul 20, 2022 at 14:45

Some related posts elsewhere:

Some suggestions what you can do:

• Temporarily switch Math Renderer to Plain Source. (See also: How do I change Math Renderer for MathJax?) This was suggested in Davide Cervone's answer.
• View source of the page in your browser. (Various browsers might have various shortcuts for this - Ctrl+U in Google Chrome.) You will not see the comments which are not expanded - StackPrinter might help.
• You can get a comment from SEDE. Here is a query listing comments under a specific post. (This will only help if the comment is in the database, which is updated once a week. So this possibility does not work for the recent comments. For example, for the post you linked, this specific comment isn't displayed among the result - but it should be there after the next update of the database.)
• Among the bookmarklets created by NormalHuman, there is a bookmarklet called Comments. If you use this bookmarklet, it copies all comments under the question into the answer field.
• You can probably find some other userscripts on StackApps, for example: Get Comment markdown, copy comment code to clipboard
• It should be possible to get the text of a comment using Stak Exchange API, see Usage of /comments/{ids}. However, the resulting format does not seem to be very comfortable to work with.
• If you have a chatroom where this won't disturb anybody, simply take the link to the comment and post it in a chatroom. (For example, using the Sandbox would probably ok - that room is intended a room for various experiments in chat.)

Some aspects are different for various methods mentioned above. For example, if you get the text of a comment from SEDE, you get MarkDown. If you look at the source code of the page, you'll get HTML. However, if your main interest is MathJax (and not formatting/MarkDown), that will be the same either way.

• Thank you! I didn't know about that neat last trick. Just to point to it, you demonstrated it in the MO editors' lounge. Jul 12, 2022 at 8:00

As mentioned in the comments, what appears to be happening is that macro definitions are stripped out when you ask your browser to display the Latex commands for some math you've highlighted (on chrome on mac, this is done by highlighting, right-clicking and selecting Show Math As -> Tex Commands). If you have sufficient privileges, you can get around this by opening the source for editing and just looking at what the source actually says there (even if you have no intention of actually editing). If it's your own post, you should always be able to open for editing. The reputation thresholds to be able to edit others' questions (respectively answers) are _____ rep (respectively ____ rep). Only moderators have the ability to edit others' comments (an ability very rarely invoked for actual editing purposes!).

I conjecture (but have not checked) that macro commands are stripped out by my browser in the same way for questions and answers as for comments.

• $\def\pre{\text{pre}}$I thought that the macro might be in a separate math block. Here's a test comment: $\def\peri{\text{peri}}\peri$. Indeed, as long as it's in the same math block, the definition is included. So I assume that the problem is when the definition is in a separate, 'invisible' math block, as here: $\pre$. Jul 12, 2022 at 0:59
• Non-mods have no ability to open the source of a comment for editing (since we can't edit it!), correct? Jul 12, 2022 at 1:00
• I apologise for accepting and unaccepting this answer, which is very informative; but I think I have to go with @DavideCervone's answer, which both literally answers the question and teaches a neat trick. Jul 12, 2022 at 1:12
• @LSpice re I think that's correct.
– Tim Campion Mod
Jul 12, 2022 at 14:04
• @MartinSleziak, I agree. I didn't realise that the first diagram was split into several pieces, so, when I clicked on what seemed to be the first one and didn't see the macro definition, I thought that it must be in a separate math environment at the beginning of the post. Jul 13, 2022 at 17:51

Just for testing purposes - so that one can try how to get source of a comment (under an answer) - a few comments below this answer contain some macros.

The answer is a community wiki - feel free to edit it further, if you have some additions.

The first comment: "Composition: $$\newcommand{\inv}[1]{#1^{-1}} \inv{(g\circ f)}=\inv f\circ \inv g$$ and self-inverse $$\inv{(\inv f)}=f$$."

Composition: $\newcommand{\inv}[1]{#1^{-1}} \inv{(g\circ f)}=\inv f\circ \inv g$ and self-inverse $\inv{(\inv f)}=f$.



The third comment - macro is (on purpose) in a separate block, which will make it more difficult to get the macro through the MathJax menu: "$$\newcommand{\E}{\operatorname{\mathsf E}}$$ Linearity of expectation: $$\E(X+Y)=\E(X)+\E(Y)$$ and $$\E(\alpha X)=\alpha\E(X)$$."

$\newcommand{\E}{\operatorname{\mathsf E}}$ Linearity of expectation: $\E(X+Y)=\E(X)+\E(Y)$ and $\E(\alpha X)=\alpha\E(X)$.

The question was mainly about macros and MathJax - but let us try something with MarkDown, too.

$\DeclareMathOperator{\Hom}{Hom}\Hom(X,Y)$ **functor** $A \mapsto \Hom(A,{-})$, _italics_ and [a link](https://en.wikipedia.org/wiki/MathOverflow)

$$\DeclareMathOperator{\Hom}{Hom}\Hom(X,Y)$$ functor $$A \mapsto \Hom(A,{-})$$, italics and a link

• Composition: $\newcommand{\inv}[1]{#1^{-1}} \inv{(g\circ f)}=\inv f\circ \inv g$ and self-inverse $\inv{(\inv f)}=f$. Jul 12, 2022 at 7:01
• $\newcommand{\E}{\operatorname{\mathsf E}}$ Linearity of expectation: $\E(X+Y)=\E(X)+\E(Y)$ and $\E(\alpha X)=\alpha\E(X)$. Jul 12, 2022 at 7:02
• $\DeclareMathOperator{\Hom}{Hom}\Hom(X,Y)$ functor $A \mapsto \Hom(A,{-})$, italics and a link Jul 13, 2022 at 10:09