How can I show codeboxes?

I am in the process of writing a simple manual. In it, I explain how to set up the files and programs necessary to run a pipeline I have written. I would like to include command line commands in that file in a way that makes them stand out and easy to read.

Basically, how can I get this effect in my LaTeX document:

cd ~/foo; mkdir bar


I was thinking along the lines of a \parbox and a background color but I was hoping there might be a class that simplifies this or any other tricks. I don't need code highlighting, I just need an easy way to differentiate commands from prose.

I would suggest using the verbatim environment since it's straight-forward and should provide the distinction you're after. Here's a minimal example:

\documentclass{article}
\begin{document}
I am in the process of writing a simple manual. In it, I explain how to set up the
files and programs necessary to run a pipeline I have written. I would like to include
command line commands in that file in a way that makes them stand out and easy to read.

Basically, how can I get this effect in my LaTeX document:
\begin{verbatim}
cd ~/foo; mkdir bar
\end{verbatim}
I was thinking along the lines of a \verb|\parbox| and a background color but I was
hoping there might be a class that simplifies this or any other tricks. I don't need
code highlighting, I just need an easy way to differentiate commands from prose.
\end{document}


Perhaps defining your own via functionality provided by fancyvrb or listings could also be an option, as suggested in Print programs with its proper syntax and/or Writing source code in LaTeX as text.

• Wow, I'm currently looking at fancyrvb and it's everything I wanted and then some. Thanks! – terdon Sep 24 '14 at 17:59

As a variation on the verbatim theme, the numberedblock package allows you to label code blocks with a marginal number, and reference them with \ref. Depending on your application, this may prove useful, too. (see http://ctan.org/pkg/numberedblock)

\documentclass{article}
\usepackage{numberedblock}
\begin{document}
I am in the process of writing a simple manual. In it, I explain how to set up the
files and programs necessary to run a pipeline I have written. I would like to include
command line commands in that file in a way that makes them stand out and easy to read.

Basically, how can I get this effect in my LaTeX document:

\begin{numVblock}[\nbVlabel{nb:A}]
cd ~/foo; mkdir bar
\end{numVblock}

I was thinking along the lines of a \verb|\parbox| and a background color but I was
hoping there might be a class that simplifies this or any other tricks. I don't need
code highlighting, I just need an easy way to differentiate commands from prose.

I can number larger blocks

\begin{numVblock}[\nbVlabel{nb:B}]
program test
implicit none
integer a, x
c\$
a = 0
x = 1
10 a = a + x
if (a .eq. 100) stop
goto 10
end
\end{numVblock}

\noindent and can then reference code blocks \ref{nb:A} and \ref{nb:B}.
\end{document}