How do I mark my inline code in questions and answers, and how can I mark code in comments?
1 Answer
The simplest way is to surround the inline code by backticks `
: To get the output \section
, just type `\section`
. If you don't like typing backticks, you can also highlight the inline code and hit Ctrl+K (or click the "code" button, with "{ }" on it), but this doesn't work in comments. In questions and answers, there are only two (quite rare) cases where things might go wrong (see below for backslash escaping of backticks in comments):
You need a backtick in the inline code. Then you can either use double backticks
``
or<code>...</code>
to mark your code. For example, both``\catcode`@=11``
and<code>\catcode`@=11</code>
give
\catcode`@=11
. Another example:`` "` ``
gives"`
(note the spaces!).You want spaces in the beginning and/or the end of the inline code, or you need multiple spaces within. Then you have to use
<code>...</code>
:<code> a test </code>
gives
a test
, which has 3 spaces between "a" and "test".
Thus, <code>...</code>
is an alternative for backticks, but it behaves differently: You can use HTML entities such as
inside. For example, <code> </code>
gives
, whereas ` `
gives
.
As a rule of thumb, use <code>...</code>
only as a last resort. And then be aware that you can run into trouble if you try to use <
inside: <code>a<b</code>
gives a
! The way out: <code>a<b</code>
gives a<b
. Moreover, <code>a < b</code>
gives a < b
.
Until 20 February 2011, markdown in comments was quite a hassle. Now the rules are almost the same as for questions and answers. These are the differences:
<code>...</code>
to mark inline code doesn't work in comments.If you need a backtick in inline code in a comment, you can (and must) escape it (doesn't work in questions/answers!):
`\catcode\`@=11`
gives\catcode`@=11
.#2 means that
`\\`
will not give\\
because the second backslash is interpreted as an escape for the subsequent backtick. This can be solved by using double backticks``
if the inline code ends with a backslash:``\\``
gives\\
.It is not possible to have spaces in the beginning and/or the end of inline code in comments.
One more important recent change: Inline code in comments can now be followed by a letter. For example, `\vspace`s
now renders as \vspace
s.
-
@Hendrik: Can you tell me how to backtick-quote something like "` (German opening quote). No combinations so far work. See this answer where I had this issue. Feb 11, 2011 at 18:19
-
-
3@Martin: Easy, use double backticks, but with spaces:
`` "` ``
. Feb 11, 2011 at 18:45