
我正在寫一本簡單的手冊。在其中,我解釋瞭如何設定運行我編寫的管道所需的文件和程式。我想在該文件中包含命令列命令,使它們脫穎而出且易於閱讀。
基本上,我怎麼能在我的 LaTeX 文件中獲得這種效果:
cd ~/foo; mkdir bar
我正在考慮 a\parbox
和 a 背景顏色,但我希望可能有一個類別可以簡化這個或任何其他技巧。我不需要程式碼突出顯示,我只需要一種簡單的方法來區分命令和散文。
答案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}