63

I have this recurring dilemma when writing posts involving terminal output which I need to to quote. You see, on one hand, it's a quote; but on the other hand, it's sort-of like code. So here are some options:

Option 1: Just quote it

einpoklum@myhost:~$ whoami einpoklum

Option 2: Treat it as code

einpoklum@myhost:~$ whoami
einpoklum

Option 3: Quote+backquotes+linebreaks

einpoklum@myhost:~$ whoami
einpoklum

Option 4: Quote+pre

einpoklum@myhost:~$ whoami
einpoklum

I do want the monospacing, so option 1 is off the table; and I don't like Option 2 since it doesn't indicate quoting - and this is a quote of text generated by something other than myself; so it should look different.

But 3 and 4 are cumbersome. What should I do?

Notes:

  • I'm asking about SO as it is now, not about potential new/different functionality.
  • When formatting as code it's a good idea to avoid auto-highlighting (as pointed out by @vaultah); but that doesn't help me choose between options.
13
  • 36
    FWIW I usually format it as code and disable highlighting by putting <!-- language: lang-none --> before it.
    – vaultah
    Commented Sep 27, 2015 at 17:02
  • 53
    +1 for not including a screenshot as a possible solution!
    – Jongware
    Commented Sep 27, 2015 at 19:23
  • @vaultah: See my added note.
    – einpoklum
    Commented Sep 27, 2015 at 19:26
  • 10
    @vaultah Why do you disable the highlighting? <!-- language: lang-bash --> gives a nice result.
    – A.L
    Commented Sep 28, 2015 at 15:57
  • Related: meta.stackoverflow.com/questions/303145/…
    – Luis Mendo
    Commented Sep 28, 2015 at 15:57
  • 3
    @einpoklum "that doesn't help me choose between options." - Treat it as code, Option 2.
    – vaultah
    Commented Sep 28, 2015 at 16:04
  • 2
    and I don't like Option 2 since it doesn't indicate quoting Why do you want to indicate that it's a quote? For me it's pretty clear that the code is something you quote (but maybe the HTML specs tell the contrary, I'm too lazy to check it).
    – A.L
    Commented Sep 28, 2015 at 16:10
  • @A.L: see edit.
    – einpoklum
    Commented Sep 28, 2015 at 16:12
  • 3
    Reductio ad absurdum: When you show code that has been written, you are, in fact, "quoting" it. Are you going to mark that as a quote as well? Commented Sep 29, 2015 at 7:48
  • @Jean-FrançoisCorbett: I'm writing it here for the first time. Or - I'm quoting myself. In both those cases I don't need quotation marks.
    – einpoklum
    Commented Sep 29, 2015 at 8:55
  • 1
    What if the guy on your left wrote it? Commented Sep 29, 2015 at 10:55
  • 1
    @usr2564301 Why screenshot shouldn't be used?
    – giordano
    Commented May 15, 2018 at 12:41
  • 2
    because screenshot of text is rarely useful and not directly copiable Commented Jun 15, 2018 at 18:52

6 Answers 6

24

You can combine code and quoting (as your 4th option).

  • I think this semantically matches, because you quoted the code (written in the Bash language) from the terminal.
  • And it's easy to mark actually - just paste -> press the code button -> press the quote button
einpoklum@myhost:~$ whoami
einpoklum
6
  • Ah. I had not realized that. I wish this would be made clearer somewhere.
    – einpoklum
    Commented Sep 27, 2015 at 21:25
  • just paste -> press code button -> press quote button - doesn't work for very long lines - quote button inserts linebreaks and screws up the result.
    – Roman
    Commented Sep 28, 2015 at 13:18
  • 1
    @Roman: You don't need to use the buttons. Just write > at the start of each line. Not hard! :) Commented Sep 28, 2015 at 13:21
  • 5
    I don't know if it's a side effect of Meta but there is a huge space below the commands, as if there was an empty line, that's strange.
    – A.L
    Commented Sep 28, 2015 at 16:07
  • 3
    @A.L You will see the same extra space on the main site, colored yellow. Commented Sep 28, 2015 at 16:22
  • Although option #4 looks better
    – Ethan
    Commented Oct 25, 2017 at 11:37
43

Treat it as code. That's the closest representation of what a user would actually see on their terminal.

10
  • 5
    But I want this to be visually distinct from just code... :-(
    – einpoklum
    Commented Sep 27, 2015 at 19:15
  • 31
    Why? ----------
    – Pekka
    Commented Sep 27, 2015 at 19:27
  • 4
    @Pekka웃: Because I'm quoting something that somebody/something else wrote, I'm not proposing a piece of code. It should look different.
    – einpoklum
    Commented Sep 28, 2015 at 16:11
  • 4
    @einpoklum I don't think it should. Can you give an example?
    – vaultah
    Commented Sep 28, 2015 at 16:13
  • 2
    @vaultah: It's not about one example, it's about the general case. But see the accepted answer for one example. Terminal output is quoted text - formatted as code; that's all.
    – einpoklum
    Commented Sep 28, 2015 at 16:20
  • 6
    @einpoklum Don't be too formalistic. You want something that's easy, distinguishes from plain text, and is monospaced. This is a Q&A site, not a word processing document for print publication. No offense intended.
    – Jan Doggen
    Commented Sep 28, 2015 at 19:23
  • @JanDoggen: You forgot that I want it to be distinguished from code :-) Anyway, apparently there's a perfectly simple solution - quoting+code works.
    – einpoklum
    Commented Sep 29, 2015 at 8:55
  • 2
    I agree with OP. When I am on a blog reading a tutorial on how to setup something that includes terminal commands, I want that distinction in whatever markup styling they're using. This is pretty industry standard even if SO isn't differentiating. Commented Sep 30, 2015 at 17:50
  • 1
    @Pekka웃 re why: for the same reason that anyone would want language-based style; They're different things. Commented Sep 30, 2015 at 17:59
  • What about the syntax highlighting? It goes all weird...
    – Ethan
    Commented Oct 25, 2017 at 11:38
20

I am a fan of just putting it in a code block as the quote seems distracting for program output. I like the form of

//Sample code block
#include <iostream>

int main()
{
    std::cout << "Hello World!";
}

Output:

Hello World!

This way the text looks like it would in the console, but I am not surrounding it with any extra markup. To me this is pretty clear what the code is and what the output of that code block is.

11

Option 5: Code with corresponding code highlighting:

<!-- language: lang-bash -->

    einpoklum@myhost:~$ echo -e "Hello, World!"
    Hello, World!

It gives:

einpoklum@myhost:~$ echo -e "Hello, World!"
Hello, World!

You can see that the command arguments are highlighted.

4
  • I feel like that at the time of writing this, your output looked different. Because right now it looks like normal code highlighting.
    – Neuron
    Commented May 15, 2018 at 11:09
  • @LonelyNeuron On my screen (Firefox 60 on desktop), "Hello, World!" is in red and Hello and World are in blue.
    – A.L
    Commented May 15, 2018 at 11:34
  • Does your console actually highlight the output like that? With only "Hello" and "World" in blue, but not the comma and exclamation mark? This highlighting really is the same as the default. "Hello, World!" is recognised as a String and "Hello" is capitalised, so it is assumed to be a class name
    – Neuron
    Commented May 15, 2018 at 11:41
  • Yes, comma and exclamation mark are not highlighted, they're black. To answer to your first question, I don't remember how it looked like 3 years ago.
    – A.L
    Commented May 15, 2018 at 11:48
5

For output of programs, I have adopted the following convention:

Output:

<!-- language: lang-none -->

    The quick brown
    The quick brown

Example: https://stackoverflow.com/a/26808009/434551

2
  • In the example you link to, the word "The" is highlighted. Commented Sep 30, 2015 at 22:27
  • @MarkRansom, thanks for letting me know. It's fixed now :)
    – R Sahu
    Commented Oct 1, 2015 at 2:43
-1

Here's another option, though it seems like an awful lot of effort for dubious value:

einpoklum@myhost:~$ whoami
einpoklum

This uses <kbd> markup surrounding backticks for code formatting.

The first problem is that the background is different for areas where there are/are not characters.

The second is that if you simply put backticks around the entire code block, you get an annoying indentation on the first line like so:

einpoklum@myhost:~$ whoami einpoklum

If you put backticks around individual lines, you lose the line breaks, so you have to add 2 spaces after each closing backtick.

<kbd>
`einpoklum@myhost:~$ whoami`__ <- 2 spaces
`einpoklum`
</kbd>

einpoklum@myhost:~$ whoami
einpoklum

Just for completeness, here's what <kbd> looks like without the code markup, but with the 2 spaces to force a line break. This breaks the first rule in that it is not monospaced.

einpoklum@myhost:~$ whoami
einpoklum

4
  • 4
    I would suggest against this because it abuses kbd's intended purpose. Commented Sep 30, 2015 at 17:53
  • @CarrieKendall I agree, it does stretch the purpose a bit since it is being used to format output as well as keyboard input (its original purpose). I guess it all comes down to one's tolerance for tag abuse. ;)
    – beaker
    Commented Sep 30, 2015 at 17:58
  • 2
    Ha ha, but it looks neat! I like :-)
    – einpoklum
    Commented Sep 30, 2015 at 20:09
  • Abusing formatting styles against their purposes has several problems. Just to name two that come to mind: If SO every changes the formatting of <kbd> to look more like an actual key, this could break horribly. Secondly, algorithms which work on the assumption that <kbd> are actually key highlights might screw up horribly. Think of google which pulls answers from SO or some tool that doesn't exist yet
    – Neuron
    Commented May 15, 2018 at 11:46

You must log in to answer this question.

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