10
$\begingroup$

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?

$\endgroup$
5
  • 3
    $\begingroup$ 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} $\endgroup$
    – Tim Campion Mod
    Jul 11 at 22:37
  • 1
    $\begingroup$ @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? $\endgroup$
    – LSpice
    Jul 11 at 22:40
  • 1
    $\begingroup$ 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. $\endgroup$
    – Tim Campion Mod
    Jul 11 at 22:41
  • 1
    $\begingroup$ @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. $\endgroup$
    – LSpice
    Jul 11 at 22:44
  • 2
    $\begingroup$ 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.) $\endgroup$ Jul 17 at 23:43

4 Answers 4

12
$\begingroup$

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.

$\endgroup$
2
  • 1
    $\begingroup$ 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! $\endgroup$
    – LSpice
    Jul 12 at 20:51
  • 1
    $\begingroup$ 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$. $\endgroup$ Jul 20 at 14:45
4
$\begingroup$

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.

$\endgroup$
1
  • 1
    $\begingroup$ Thank you! I didn't know about that neat last trick. Just to point to it, you demonstrated it in the MO editors' lounge. $\endgroup$
    – LSpice
    Jul 12 at 8:00
3
$\begingroup$

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.

$\endgroup$
6
  • 2
    $\begingroup$ $\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$. $\endgroup$
    – LSpice
    Jul 12 at 0:59
  • 1
    $\begingroup$ Non-mods have no ability to open the source of a comment for editing (since we can't edit it!), correct? $\endgroup$
    – LSpice
    Jul 12 at 1:00
  • 1
    $\begingroup$ 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. $\endgroup$
    – LSpice
    Jul 12 at 1:12
  • 2
    $\begingroup$ @LSpice re I think that's correct. $\endgroup$
    – Tim Campion Mod
    Jul 12 at 14:04
  • 2
    $\begingroup$ I will confirm that for me the macros are displayed in this way. In the first diagram I get \quad\newcommand{\x}{\large\blacksquare}\begin{align}\x\\[-5pt]\x\\[-5pt]\x\end{align}\,\cup\, from Show Math As $\to$ TeX Commands. (Of course, not in the subsequent formulas.) Generally, it would seem rather surprising if browser treated \newcommand for some reason differently from other parts MathJax. (In case it is relevant, I use Google Chrome under Windows.) $\endgroup$ Jul 13 at 6:38
  • 2
    $\begingroup$ @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. $\endgroup$
    – LSpice
    Jul 13 at 17:51
1
$\begingroup$

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 second comment: "The set $\newcommand{\NN}{\mathbb{N}}\newcommand{\ZZ}{\mathbb{Z}}\ZZ$ is countable: $|\ZZ|=|\NN|$."

The set $\newcommand{\NN}{\mathbb{N}}\newcommand{\ZZ}{\mathbb{Z}}\ZZ$ is countable: $|\ZZ|=|\NN|$.

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

$\endgroup$
4
  • 1
    $\begingroup$ Composition: $\newcommand{\inv}[1]{#1^{-1}} \inv{(g\circ f)}=\inv f\circ \inv g$ and self-inverse $\inv{(\inv f)}=f$. $\endgroup$ Jul 12 at 7:01
  • 1
    $\begingroup$ The set $\newcommand{\NN}{\mathbb{N}}\newcommand{\ZZ}{\mathbb{Z}}\ZZ$ is countable: $|\ZZ|=|\NN|$. $\endgroup$ Jul 12 at 7:02
  • 1
    $\begingroup$ $\newcommand{\E}{\operatorname{\mathsf E}}$ Linearity of expectation: $\E(X+Y)=\E(X)+\E(Y)$ and $\E(\alpha X)=\alpha\E(X)$. $\endgroup$ Jul 12 at 7:02
  • 1
    $\begingroup$ $\DeclareMathOperator{\Hom}{Hom}\Hom(X,Y)$ functor $A \mapsto \Hom(A,{-})$, italics and a link $\endgroup$ Jul 13 at 10:09

You must log in to answer this question.

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