2

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
11

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):

  • Thank you, I hadn't found an easy answer to this. Should it works for reportclass? – santimirandarp Aug 24 '17 at 4:41
  • 3
    @santimirandarp Yes, why not? Updated my answer for report class. Now you can accept my answer and upvote it. :-) – Masroor Aug 24 '17 at 4:46
  • Yes, i will try it and accept and upvote if it works...thank you again. – santimirandarp Aug 24 '17 at 4:51
  • you might add verbatim to that list. it doesn't have as many bells and whistles, but is simple, reliable, and maintained by the latex team so when something sneaky changes under the covers, it doesn't fall apart. – barbara beeton Aug 24 '17 at 16:56
  • @barbarabeeton Yes, of course. How could I miss that? – Masroor Aug 24 '17 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.