0

I am writing a tutorial, and I need to include a UNIX command which is run from the shell. How do I represent this? It looks extremely strange if I simply use the verbatim environment.

  • There are many options besides verbatim. – jon May 06 '16 at 01:34
  • You only need verbatim style environments if special LaTeX characters are involved like backslashes, percents, carats, pound signs, etc. Otherwise, you can pick a way to differentiate the UNIX command from your document text. Italics, for example, might work; sans serif is another possibility... – Steven B. Segletes May 06 '16 at 02:09
  • I recommend using the listings package. If you provide a minimal working example I can give more details as to how it works. –  May 06 '16 at 07:59
  • what do you find strange about verbatim (the question is impossible to answer if you just need things to match your unstated preferences) is it the font or the fact that it is a display environment, perhaps the inline \verb|cp file1.txt file2.txt| is what you want or .... – David Carlisle May 06 '16 at 08:43
  • Here's an example how to 'mime' UNIX shell and it's commands: http://tex.stackexchange.com/questions/307129/terminal-screenshot-generator/307130#307130 –  May 06 '16 at 13:48
  • @David Carlisle I find it looks strange because it needs a new paragraph afterwards, and the text within verbatim is at the very left. I would prefer it if it displayed commands a bit more to the right, without having to insert spaces, which feels wrong to me. – sadljkfhalskdjfh May 07 '16 at 01:33
  • It doesn't need a new paragraph, a paragraph starts just if there is a blank line after or before, just as with all latex displays, to center it: \begin{center}\begin{minipage}{.5\textwidth}\begin{verbatim}... or whatever width you want for the verbatim code – David Carlisle May 07 '16 at 08:26
  • @David Carlisle OK, that solved the problem (I was ignorant of the minipage environment.) – sadljkfhalskdjfh May 07 '16 at 11:28

1 Answers1

3

If your code lines are not too long so you want to centre or offset the display block you can do

text text text
\begin{center}
\begin{minipage}{.5\textwidth}
\begin{verbatim}
code
  lines
here
\end{verbatim}
\end{minipage}
\end{center}

Replacing verbatim by lstlisting or minted or similar environments if you want syntax colour highlighting or other features rather than simple monospace verbatim text.

David Carlisle
  • 757,742