Not sure if this is possible at all. I have to display UNIX commands in a user manual, some of them quite long. These will not fit in a single line so they have to wrap.

To display them I tried both using the verbatim environment and the listings package (with breaklines set to true). However, when I go to the final PDF and double click the line, which is now wrapped, it does not select the entire command but only the single line in which I double clicked.

Imagine a command like the one below. Is there an environment I can use that allows me to double click the command in the final PDF document and have it select the entire command?

$ keytool -genkeypair -dname "cn=sub.example.com"
-alias sub_root -keyalg RSA -keysize 2048 -validity 500
-keystore sub.ks -storepass pass -storetype jks

Clarification: Currently, at least with the verbatim environment, the reader can click-and-hold and then drag to select the entire command; but when this is pasted into the terminal, the terminal reads it as several lines and that won't do. Alternatively, I can add \ at the end of each line (except last one) but then the user pastes the command and cannot edit it. Ideally, we'd have the command automatically wrapped and without back slashes, and double clicking in any line would select the entire command so we can paste it as a single editable line.

  • Outsider question: why you don't just escape the newline in the shell command with a '\' at the end of the line? In this way, even if dragging is required to select all the command, it will be pasted as one single command.
    – gigabytes
    Jul 19, 2016 at 22:08
  • @gigabytes: That's a good idea. I've tried escaping the new line with `\`, but then the user can only edit the last line after pasting and not the previous ones.
    – Daniel
    Jul 19, 2016 at 23:13

1 Answer 1


Try this. Here, I use the accsupp package that allows, when creating the PDF, different things to be placed on the paper versus in the PDF "internal" document (used for copy/paste). The nice feature is that the text placed in the internal document from an AccSupp call is a single entity to the PDF and cannot be copy/pasted in part, but only in whole. Furthermore, that internal representation of the AccSupp text does not have line breaks within it, regardless of what text is placed on the visible paper of the PDF.

It does not copy with a double click, but via click and drag. However, merely dragging over the beginning part of the \copypaste argument will copy the whole thing (it will not be broken) and will paste as a continuous line without line feeds.

Here is some text, and now the stuff of interest:
\copypaste{$ this-is-my-long-command -with-lots-of-flags -with-lots-of-flags
-with-lots-of-flags -with-lots-of-flags -with-lots-of-flags
-with-lots-of-flags -with-lots-of-flags -with-lots-of-flags
-with-lots-of-flags -with-lots-of-flags -somearg xyz}
more text.  Now, as its own paragraph:

\copypaste{$ this-is-my-long-command -with-lots-of-flags -with-lots-of-flags
-with-lots-of-flags -with-lots-of-flags -with-lots-of-flags
-with-lots-of-flags -with-lots-of-flags -with-lots-of-flags
-with-lots-of-flags -with-lots-of-flags -somearg xyz}

More text

enter image description here

  • Actually, I just realized I explained myself incorrectly. I wanted to be able to double click to select the entire line, and not to copy. So double click selects entire line, and then I can use e.g. <kbd>Ctrl+C</kbd> to do the copy. Your answer does what I want because when I double click at the beginning of the command the entire line is selected. It is unfortunate that I cannot double click anywhere on the line, that would be ideal. Still, I'm quite happy with the answer, many thanks!
    – Daniel
    Jul 19, 2016 at 20:21

You must log in to answer this question.

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