34

Is there a way to type something in a comment that renders like this?

You'll need to escape it with a backslash - that is, the \ character.

I've tried various combinations, but a single backslash formatted as code seems to be impossible.
Can this be fixed, or can I be enlightened please?

And to clarify: I expect this:

You'll need to escape it with a backslash - that is, the `\\` character.

to work properly, but it doesn't. Instead, one backslash escapes the ` and I'm left with a mess.

8

3 Answers 3

31

Ah, solved it:

The syntax you're looking for is:

``\``

which will produce exactly the comment you want without all the gymnastics, as seen in my test comment below this answer...


The problem is that the syntax you would expect

`\`

causes the closing backtick to be escaped by the backlash, which means no code formatting is applied (because you haven't properly closed the inline code block).

However, by inserting a space between the backslash and the backtick, you can cleverly disrupt this escaping behavior:

`\ `

This produces almost what you want, except that there's an ugly gap rendered after the backslash (see test comments elsewhere on this page).

So the next apparent hack would be to use a Unicode zero-width space, which will still disrupt the escaping behavior, but won't render as an ugly gap in your comment. Thus,

`\​`

will render exactly as you would expect it to.

5
  • Good idea, that's what I'll use for now. This is definitely looking like a bug, though.
    – Ry-
    Commented Apr 19, 2012 at 4:41
  • More testing: \
    – Cody Gray
    Commented Apr 19, 2012 at 4:47
  • 2
    Dennis got the double-backticks answer first (by several minutes). Commented Apr 19, 2012 at 4:55
  • 4
    Oh no! That means he wins! I guess I'd better give back this gold-plated unicorn statue that I won... @brock
    – Cody Gray
    Commented Apr 19, 2012 at 4:58
  • Just saying, that your answer LOOKS like plagiarism. Veterans know that you probably worked it out in parallel, but it could all be cleared up with a simple attribution. Commented Apr 19, 2012 at 5:03
22
`\`

doesn't work, because the backslash escapes the backtick.

Double backticks (``) can also be used to delimit inline code blocks. This produces a single backslash:

``\``
5
  • <code> doesn't work in comments.
    – Cody Gray
    Commented Apr 19, 2012 at 4:30
  • @TheEstablishment: I meant the markdown syntax for <code>. Fixed.
    – Dennis
    Commented Apr 19, 2012 at 4:32
  • It actually doesn't ignore trailing whitespace in comments, sorry. I missed that. \ See, there's a space.
    – Ry-
    Commented Apr 19, 2012 at 4:38
  • @minitechη: Sadly, you're right. Testing: \ OK, that worked.
    – Dennis
    Commented Apr 19, 2012 at 4:39
  • "because the backslash escapes the backtick". Yeah, but then why is it rendered correctly in a Question/Answer? The parsing should be consistent in Comment as well as Question/Answer.
    – wisbucky
    Commented Jun 26, 2019 at 21:26
2

Update:
Looks like Dennis was first to probably the easiest answer to execute, the double-backtick approach.


One way to do it is to use a space after:

`\ `

Another, without the pesky space is to use the "Fullwidth Reverse Solidus"

`\`

Comparison:

`\ ` versus
`\`


On windows systems, you can often generate the full-width slash by holding down the Alt key and pressing + (numeric keypad), F F 3 C (lower-case is fine).

2
  • Neither are really attractive solutions, though; awkward space or awkward backslash.
    – Ry-
    Commented Apr 19, 2012 at 4:38
  • 3
    "Perfect"? Hmm. It looks like a backslash on drugs, at least on my machine.
    – Cody Gray
    Commented Apr 19, 2012 at 4:56

You must log in to answer this question.

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