¿Cómo puedo mostrar cuadros de códigos?

¿Cómo puedo mostrar cuadros de códigos?

Estoy en el proceso de escribir un manual sencillo. En él, explico cómo configurar los archivos y programas necesarios para ejecutar una canalización que he escrito. Me gustaría incluir comandos de línea de comando en ese archivo de manera que se destaquen y sean fáciles de leer.

Básicamente, ¿cómo puedo conseguir este efecto en mi documento LaTeX?

cd ~/foo; mkdir bar

Estaba pensando en un \parboxcolor de fondo y un color de fondo, pero esperaba que hubiera una clase que simplifique este u otros trucos. No necesito resaltar el código, solo necesito una manera fácil de diferenciar los comandos de la prosa.

Respuesta1

Sugeriría usar el verbatimentorno ya que es sencillo y debería proporcionar la distinción que busca. Aquí hay un ejemplo mínimo:

ingrese la descripción de la imagen aquí

\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}

Quizás defina el suyo propio a través de la funcionalidad proporcionada porfancyvrbolistingsTambién podría ser una opción, como se sugiere enImprimir programas con su sintaxis adecuaday/oEscribir código fuente en LaTeX como texto.

Respuesta2

Como variación del verbatimtema, el numberedblockpaquete le permite etiquetar bloques de código con un número marginal y hacer referencia a ellos con\ref . Dependiendo de su aplicación, esto también puede resultar útil. (verhttp://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}

ingrese la descripción de la imagen aquí

información relacionada