4

When typing answers in an edit-box of the TeX-LaTeX-StackExchange website, which is based on markdown, then from time to time I introduce control-sequence-tokens/sequences of inline-code not via nesting between backticks as in `\macro` but via nesting between HTML-tags <code> and </code> as in <code>\macro</code>. Usually this yields \macro, i.e., the leading backslash \ of the phrase \macro is present.

But when I do this with control-sequence-tokens whose name's first character is @, then the preceding backslash doesn't show up:

<code>\@currenvir</code> yields: @currenvir.

(The phrase \@currenvir is between HTML-tags <code> and </code> and as far as I know neither the backslash nor @ is a special/reserved character in HTML.)

Questions:

Why does the preceding backslash not show up in the output at the TeX-LaTeX-StackExchange website if in my markdown/HTML-input it is trailed by @?

Am I overlooking some subtle rule regarding syntax of markdown-input or HTML-input or HTML-inside-markdown-input?
If not: Is this a bug?


In case things render differently on different browsers here is a screenshot of what I get when viewing with Chromium under Debian Linux:

enter image description here

2
  • 1
  • @samcarter_is_at_topanswers.xyz The answer in that link says that with <pre><code>...</code></pre> you need to encode html-entities yourself, but it doesn't specify which characters (besides characters that are special/reserved in HTML) need to be encoded/escaped. Jul 2 at 18:01
5

The markdown backtick syntax does not only the formatting like the HTML <code> block, but it also escapes special characters, so a \ or a < or > have no special meaning. Inside a <code> block this escaping does not happen, so a backslash introduces an escape sequence. To have a backslash you need an escaped backslash, thus: <code>\\@currenvir</code>, which renders as \@currenvir. You can see the same thing with other non-alphanumeric characters like "!@#$%&*()_+=-'?/<> (in the source of this answer, all of those are preceded by a backslash).

That's also what you have to use when you want to type </code> outside of a backtick pair (or a markdown code block): <code>\</code\></code> renders as </code>, but without the backslashes it would render as  (an empty HTML <code> block, plus a stray </code>).

2
  • I am a bit confused now: Looking things up in HTML-reference I didn't find backslash to be a special character in HTML. But it is a special character in markdown. Does this mean with HTML inside markdown besides special html-characters you also need to escape special markdown-characters? Jul 2 at 13:27
  • 2
    @UlrichDiez I believe so, yes. < and > are special for HTML, so you have to escape them (usually with &lt; and &gt;, but here \< and \> also work), but since the edit box for stackexchange is officially markdown, rather than HTML, it makes sense that the backslash is only special for markdown and needs escaping. Jul 2 at 13:34

You must log in to answer this question.

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