How can I produce black and white source code using the minted package?

I just started using the minted package, to produce formatted source codes.

I thought the style bw is a black and white style of pygmentize and it just uses italic and bold to format the code (I tried the code below), but I was wrong. Is there any way to produce formatted code which looks good in black and white?

\documentclass{minimal}
\usepackage{minted}

\begin{document}
\usemintedstyle{bw}
\inputminted{bash}{sample.sh}
\end{document}


Thanks

-
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Jan 17 at 17:39
add comment

3 Answers

The problem isn’t the style – bw is correct and works fine! – but the font. The default monospace font of LaTeX doesn’t support italics and bold.

You need to switch to a different font – e.g. by loading the courier package, or by using XeLaTeX and loading a custom font.

-
Thanks, for helping, I just need the courier package. I did not know, the default LaTeX font doesn't support italics and bold. Thanks again! –  user13474 Apr 11 '12 at 9:37
add comment

As far as I could see, there's no predefined style to achieve the desired formatting; a list of predefined styles can be obtained by running

pygmentize -L styles


in a terminal.

You can define your own style, and instructions can be found in the website under Creating Own Styles.

Another option would be to use some of the options for the \inputminted command (or for the minted environment) to quickly get something like you want. A little example:

\documentclass{article}
\usepackage{xcolor}
\usepackage{minted}

\begin{document}

\inputminted[bgcolor=black,formatcom=\color{white}]{console}{sample.sh}

\begin{minted}[bgcolor=black,formatcom=\color{white}]{bash}
#! /bin/bash
# script to turn the screen blue
setterm -background blue
echo It is a blue day
\end{minted}

\end{document}


and the file sample.sh:

#! /bin/bash
# script to turn the screen blue
setterm -background blue
echo It is a blue day


-
Not true -- bw is included by default. –  Ben Alpert Apr 7 '12 at 21:09
@BenAlpert: Yes, of course, bw is included; all I said is that the style I thought the OP wanted was not one of the predefined ones. –  Gonzalo Medina Apr 8 '12 at 21:21
add comment

You can also try to use \renewcommand{\ttdefault}{pcr} in your preambule. I use this solution so as to have bold face when I use the listings package. This solution does not need to use the package courrier.

-
Please extend this answer to explain what is happening and how this would fix the issue. This way other users will have a better chance to understand the issue and solution. –  Martin Scharrer Apr 11 '12 at 9:45
I can do better... –  projetmbc Apr 11 '12 at 9:51
add comment