Wie kann ich Codeboxen anzeigen?

Wie kann ich Codeboxen anzeigen?

Ich bin gerade dabei, ein einfaches Handbuch zu schreiben. Darin erkläre ich, wie man die Dateien und Programme einrichtet, die zum Ausführen einer von mir geschriebenen Pipeline erforderlich sind. Ich möchte Befehlszeilenbefehle so in diese Datei aufnehmen, dass sie auffallen und leicht zu lesen sind.

Wie kann ich grundsätzlich diesen Effekt in meinem LaTeX-Dokument erzielen:

cd ~/foo; mkdir bar

Ich dachte an eine \parboxund eine Hintergrundfarbe, aber ich hoffte, dass es vielleicht eine Klasse gibt, die diesen oder andere Tricks vereinfacht. Ich brauche keine Codehervorhebung, ich brauche nur eine einfache Möglichkeit, Befehle von Prosa zu unterscheiden.

Antwort1

Ich würde vorschlagen, die verbatimUmgebung zu verwenden, da sie unkompliziert ist und die gewünschte Unterscheidung bieten sollte. Hier ist ein minimales Beispiel:

Bildbeschreibung hier eingeben

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

Vielleicht definieren Sie Ihre eigene Funktion über die vonfancyvrboderlistingskönnte auch eine Option sein, wie vorgeschlagen inProgramme mit der richtigen Syntax druckenund/oderQuellcode in LaTeX als Text schreiben.

Antwort2

Als Variation des verbatimThemas numberedblockermöglicht Ihnen das Paket, Codeblöcke mit einer Randnummer zu kennzeichnen und sie mit zu referenzieren \ref. Je nach Anwendung kann sich dies auch als nützlich erweisen. (siehehttp://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}

Bildbeschreibung hier eingeben

verwandte Informationen