Как показать кодовые поля?

Как показать кодовые поля?

Я пишу простое руководство. В нем я объясняю, как настроить файлы и программы, необходимые для запуска конвейера, который я написал. Я хотел бы включить команды командной строки в этот файл таким образом, чтобы они выделялись и были легко читаемы.

В принципе, как мне добиться этого эффекта в моем документе LaTeX:

cd ~/foo; mkdir bar

Я думал о линиях a \parboxи цвете фона, но я надеялся, что может быть класс, который упростит это или любые другие трюки. Мне не нужна подсветка кода, мне просто нужен простой способ отличить команды от прозы.

решение1

Я бы предложил использовать verbatimсреду, поскольку она прямолинейна и должна обеспечить то различие, которое вам нужно. Вот минимальный пример:

введите описание изображения здесь

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

Возможно, определение вашего собственного функционала с помощьюfancyvrbилиlistingsтакже может быть вариантом, как предложено вПечатать программы с правильным синтаксисоми/илиНаписание исходного кода в LaTeX в виде текста.

решение2

В качестве вариации на verbatimтему numberedblockпакет позволяет вам маркировать блоки кода маргинальным номером и ссылаться на них с помощью \ref. В зависимости от вашего приложения это также может оказаться полезным. (см.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}

введите описание изображения здесь

Связанный контент