12

I've noticed that in comments, when you create `code region` with backticks, the backslash will still work as an escape character within that region (but it should not, IMHO).

To clarify:

  • In comments, `\\` will be rendered as \, but it should be rendered as \\
  • In the post body itself, `\\` will be rendered as \\ (i.e., correctly)

This is especially confusing when you enter regular expressions into a comment, since backslash-escaping is very common there, and confusion increases if you are dealing with a regex that is double-escaped for representation in a string.

At some point you lose track how many backslashes you must make so the comment renders correctly, or you don't notice fast enough (or at all) and the comment contains wrong code where the same markup in a question or answer would come out as perfectly correct.

It's just that comments can't be corrected anymore after the grace period, leaving you with the choice of either deleting the comment, thus crippling the conversation, or engaging in a trial-and-error game of writing another comment with even more backslashes to explain the issue.

My question is two-fold:

  • Will this error be corrected? If yes, existing comments should probably be searched and "fixed" by a routine that tries to do the right thing (this is probably somewhere between hard and impossible)
  • Or, can I rest assured that never ever the behavior of the backslash in comments is going to be changed, so I can start working around this issue by hand, knowing that they won't start displaying incorrectly at some point in the future?
3
  • "confusion increases if you are dealing with a regex that is double-escaped for representation in a string." You think that's bad, Java REQUIRES you to do that due to not having a literal string thingy (like C# has).
    – Powerlord
    Commented Feb 1, 2011 at 20:30
  • @RBemrose ...which was exactly my point.
    – Tomalak
    Commented Feb 1, 2011 at 22:30
  • 2
    it is improved now, but note that the backslash-backtick (escaped backtick) is the lone exception, eg, ` Commented Feb 14, 2011 at 2:10

3 Answers 3

7

All backslash escaping is disabled in code regions with the exception of

\`

This will always be considered an escape of the backtick itself, for now, even within a code block.

4
  • Thanks, that's great news! One question remains - how are the existing comments handled?
    – Tomalak
    Commented Feb 14, 2011 at 8:31
  • Wow, that's good. Now I'll have to try and make the tex.sx users aware of this, and rewrite my explanations about inline code in comments. Commented Feb 14, 2011 at 11:15
  • @hendrik there is still, as you noted, the issue with code blocks which end in backslash. We will also support the double-backtick method for this, and @balpha will check that in this week sometime. See: meta.stackoverflow.com/questions/78499/… Commented Feb 14, 2011 at 21:05
  • Yes, I've seen that it's "status-planned". Great! Have you seen my recent bug report about wrong rendering of old comments due to the recent change of backslash escaping? Hope it's OK pointing you there via this comment. Commented Feb 14, 2011 at 21:09
4

Concerning your first question: I think it would be bad idea to try and "fix" existing comments. I for myself got used to the necessary workarounds in comments, and who know's what'll happen if a routine comes around trying to fix things.

EDIT: The following is partly obsolete due to the changes explained in Jeff's answer.

Gilles wrote

But it wouldn't be a good idea to turn off backslash escaping in code sections.

Well, the backslash escaping is only needed for backticks (and it's only needed if the backtick is before a non-letter; yes, ``U` will give `U in comments). So I don't understand why there's escaping for (, ), [, ], * and _ as well. What one would need, in presence of backslash escaping, is an escape for the backslash itself; then `\\\\` would give the desired \\ in comments. But it would also be a bad idea to implement this, I guess. Over on tex.sx I'd strongly dislike it.

In my opinion, the best would be to enable double (or multiple) backticks in comments (thus allowing backticks within the inline code) and to disable backslash escaping. This would then be the same syntax as in questions/answers.

A suboptimal solution would be to make \\ in the very end of inline code in comments yield a single backslash that leaves the closing backtick unescaped.

1
  • 1
    I agree that it would be at least... difficult to "fix" existing comments. There is a pattern to the work-around, and you could try and find those comments only that obviously contain that pattern, but you indeed would risk to break existing comments. OTOH you also have a chance to fix existing, previously broken comments. Plus, things would get more consistent (thus more user-friendly and future-proof). It's a matter of giving more weight to the one side or the other. Personally, I would like things being consistent rather than just documented ("don't make me think").
    – Tomalak
    Commented Feb 1, 2011 at 20:08
2

I agree that the escaping in comments is confusing. The issue is partly explained here. There's a more detailed explanation on the TeX meta.

But it wouldn't be a good idea to turn off backslash escaping in code sections. Otherwise, how would you render a backquote in code in a comment? (Maybe you don't need it, others do.)

What would be nice is to have a preview for comments.

4
  • I think backticks are rarer than backslashes in code. You can always get the former using <code>`</code>.
    – moinudin
    Commented Jan 8, 2011 at 13:39
  • @marcog: They are indeed rarer in the languages I usually use, but other people may need them more. And in any case they must be possible to type. <code> is ok for answers, but this discussion is about comments. Commented Jan 8, 2011 at 13:54
  • <code>test ` </code>. Okay, you're right didn't realise it didn't work in comments. :-/
    – moinudin
    Commented Jan 8, 2011 at 13:57
  • 2
    Instead of arguing how escaping backticks works, I'd rather have the in-line code sections in comments behave the exact same way as their cousins in the question. If escaping backticks works there, all is fine anyway; if it doesn't, then there's no point in making it work in comments.
    – Tomalak
    Commented Jan 8, 2011 at 15:04

You must log in to answer this question.

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