# MarkDown quirk, including square brackets in link text of Comment

I recognized this Question as duplicate to one with square brackets in its title (unsurprisingly, since the Q is about irreducible polynomials over $\mathbb{Z}_2$).

The auto link from my vote-to-close (as "possible" duplicate) doesn't format correctly, and despite a couple of tries at a manual fix, no joy.

The problem appears to be that including square brackets inside the MathJax link text (enclosed by square brackets) confuses the link parsing mechanism.

I'm sure the naked URL is usable as is, but I don't recall having this problem before. According to this similar 2011 report, the "bug" was supposed to be "fixed in the next build" (and subsequently marked status-completed).

So for now I'm tagging this as a bug report as well.

Added: Based on experiments (see Comments below), this quirk is due to an interaction between MarkDown and MathJax. That is, the fix that resulted in status-completed items in 2011 involves escaping square brackets inside link text with backslashes. However if the square brackets also happen to be inside MathJax (dollar-sign) delimiters, that backslash escaping doesn't work, breaking both the MarkDown link text and the MathJax formula.

• Since this is a MarkDown bug, I took a look at Meta.SO for similar reports. Beyond two reporting threads from 2011 (accepted as bugs and marked status-completed) there were some slightly specialized problems reported in 2012 (and perhaps continuing, judging from Comments added recently) about brief Answers auto-converted to Comments (issues with footnote style links not displaying well in Comments, but hinging on square brackets in common with the issue raised here). Taken in toto, the "escaping" of internal square brackets in link text with backslashes is supposed to work (and doesn't). – hardmath Nov 15 '13 at 2:12
• Since the linked duplicate above is now closed, it no longers serves to illustrate the problem (auto-comment promoted to Close text in Question). So, let's reproduce the problem with this Comment, esp. to see if the bug requires a MathJax interaction: Find all irreducible monic polynomials in $\mathbb{Z}/(2)$x$$ with degree equal or less than 5. – hardmath Nov 15 '13 at 13:38
• Here's a version without MathJax decoration, but with backslash escaping of the square brackets: Find all irreducible monic polynomials in Z/(2)[x] with degree equal or less than 5. – hardmath Nov 15 '13 at 13:39
• I suppose one solution might be to add definitions in MathJax for $ and $ so that they produce [ and ] (and also add them as valid delimiters so that they work with \left and \right). That would not be difficult, but would require some additional custom MathJax configuration on these sites. – Davide Cervone Nov 16 '13 at 22:51

A manual fix I have found in the comments Works by defining MathJax commands outside of MarkDown and without the characters [] in them thus making the link part clear of any []:

You can manually edit the MathJax to not use literal [] for brackets. The commands are \lbrack and \rbrack. Thanks to Daniel Fischer for pointing this out.

[The link $\lbrack x \rbrack$](http://math.stackexchange.com)


Results in this correct display:


• \lbrack x\rbrack -> $\lbrack x\rbrack$ No need to define a new command. – Daniel Fischer Oct 8 '14 at 21:32
• @DanielFischer Thanks for bringing this to my attention. I will adapt. – AlexR Oct 8 '14 at 21:37