[Tex/LaTex] Display bash code in LaTeX

code

Is it possible to display bash code in LaTeX? Like the next one:

Here is the code's format i want to show in latex

Best Answer

In LaTeX, in order to display bash code and any other code, you can use the listings package.

The \lstset command is used to control the basic appearance, including the language of code. Please see page 13 of listings documentation.

The code to be displayed may be part of the LaTeX file or may be an external file.

\documentclass{report}

\usepackage{listings}
\lstset{
  language=bash,
  basicstyle=\ttfamily
}

\begin{document}

Code directly embedded in \LaTeX\ file.

\begin{lstlisting}
  Here is the code's format i want to show in latex
\end{lstlisting}

Code from an external file.

\lstinputlisting{my.bash}

\end{document}

Other possible/related options for tasks like the above are (not in any particular order):