[Tex/LaTex] How to make bash-code look good both in LaTeX and HTML


As I am new to Latex and this kind of typing in general, I find myself in need of some basic guidelines when it comes to how to make things look good in text. I have a document that looks good when typeset into a .pdf, but when I compile it to .html using htlatex the text loses its color, making it more difficult to distinguish from the surrounding text.

How can I write bash text so that it looks good when compiled into an html-file? Is there a commonly used method that makes bash look good?

Right now I use an environment every time:


And then, when I want bash in text:

\$ Text text text text text

Best Answer

For pdf output you can use the minted package. This produces a nicely formatted and coloured PDF file for you.

As described in the minted package documentation, you have to install Pygments and run (pdf)latex with the -shell-escape option. To use this approach to produce html you also need to pass the -shell-scape option to htlatex. You can do this using

htlatex file.tex "" "" "" -shell-escape

Note that the three double quotes "" "" "" are necessary as the -shell-escape has to be the fifth option to htlatex.

Running htlatex on my MWE below gives the following html output:

HTML output

I was going to put up two images but, as far as I can tell, the PDF and HTML output are identical.

Finally, here is my MWE:

# removes backup files and TeX files

if [ $# -gt 0 ] && [ $1 = "-b" ]


Btw, I just learnt that minted also has a very useful command:


You can use this to typeset your source code without physically including it in your tex document.