1

I'm trying to get simple code highlighting working using minted, however the background color is always off.

My source:

\documentclass[a4paper]{article}
\usepackage{minted}
\usemintedstyle{monokai}
\begin{document}

\textbf{Code Example:}
\begin{minted}[frame=lines,
               framesep=2mm]{python}
    #!/usr/bin/env python2

    def example_function():
        return "hello world"

    a = 5
    b = "I am python code"
\end{minted}

\end{document}

The result:

enter image description here

This is supposed to be the Monokai theme, yet is clearly too bright.

  • Pygments Version: 2.2.0, (c) 2006-2017 by Georg Brandl.
  • LaTeX Version: 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian)

pdflatex log:

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=pdflatex 2016.8.4)  8 JUN 2017 21:31
entering extended mode
 \write18 enabled.
 %&-line parsing enabled.
**test.tex
(./test.tex
LaTeX2e <2016/02/01>
Babel <3.9q> and hyphenation patterns for 3 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/share/texlive/texmf-dist/tex/latex/minted/minted.sty
Package: minted 2015/09/09 v2.1 Yet another Pygments shim for LaTeX

(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks14
)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty
Package: kvoptions 2011/06/30 v3.11 Key value format for package options (HO)

(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ltxcmds.sty
Package: ltxcmds 2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
Package: kvsetkeys 2012/04/25 v1.16 Key value parser (HO)

(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/infwarerr.sty
Package: infwarerr 2010/04/08 v1.3 Providing info/warning/error messages (HO)
)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/etexcmds.sty
Package: etexcmds 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)

(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifluatex.sty
Package: ifluatex 2010/03/01 v1.3 Provides the ifluatex switch (HO)
Package ifluatex Info: LuaTeX not detected.
)
Package etexcmds Info: Could not find \expanded.
(etexcmds)             That can mean that you are not using pdfTeX 1.50 or
(etexcmds)             that some package has redefined \expanded.
(etexcmds)             In the latter case, load this package earlier.
)))
(/usr/share/texlive/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
Package: fancyvrb 2008/02/07

Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix 
<2008/02/07> (tvz)
\FV@CodeLineNo=\count87
\FV@InFile=\read1
\FV@TabBox=\box26
\c@FancyVerbLine=\count88
\FV@StepNumber=\count89
\FV@OutFile=\write3
) (/usr/share/texlive/texmf-dist/tex/latex/float/float.sty
Package: float 2001/11/08 v1.3d Float enhancements (AL)
\c@float@type=\count90
\float@exts=\toks15
\float@box=\box27
\@float@everytoks=\toks16
\@floatcapt=\box28
)
(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty
Package: ifthen 2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
)
(/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty
Package: calc 2014/10/28 v4.3 Infix arithmetic (KKT,FJ)
\calc@Acount=\count91
\calc@Bcount=\count92
\calc@Adimen=\dimen103
\calc@Bdimen=\dimen104
\calc@Askip=\skip43
\calc@Bskip=\skip44
LaTeX Info: Redefining \setlength on input line 80.
LaTeX Info: Redefining \addtolength on input line 81.
\calc@Ccount=\count93
\calc@Cskip=\skip45
)
(/usr/share/texlive/texmf-dist/tex/latex/ifplatform/ifplatform.sty
Package: ifplatform 2010/10/22 v0.4 Testing for the operating system

(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
Package: pdftexcmds 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO
)

(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifpdf.sty
Package: ifpdf 2011/01/30 v2.3 Provides the ifpdf switch (HO)
Package ifpdf Info: pdfTeX in PDF mode is detected.
)
Package pdftexcmds Info: LuaTeX not detected.
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode found.
)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/catchfile.sty
Package: catchfile 2011/03/01 v1.6 Catch the contents of a file (HO)
)
runsystem(uname -s > "test.w18")...executed.

 (./test.w18)
runsystem(rm -- "test.w18")...executed.

) (/usr/share/texlive/texmf-dist/tex/latex/etoolbox/etoolbox.sty
Package: etoolbox 2015/08/02 v2.2a e-TeX tools for LaTeX (JAW)
\etb@tempcnta=\count94
)
(/usr/share/texlive/texmf-dist/tex/generic/xstring/xstring.sty
(/usr/share/texlive/texmf-dist/tex/generic/xstring/xstring.tex
\@xs@message=\write4
\integerpart=\count95
\decimalpart=\count96
)
Package: xstring 2013/10/13  v1.7c  String manipulations (C Tellechea)
)
(/usr/share/texlive/texmf-dist/tex/latex/lineno/lineno.sty
Package: lineno 2005/11/02 line numbers on paragraphs v4.41
\linenopenalty=\count97
\output=\toks17
\linenoprevgraf=\count98
\linenumbersep=\dimen105
\linenumberwidth=\dimen106
\c@linenumber=\count99
\c@pagewiselinenumber=\count100
\c@LN@truepage=\count101
\c@internallinenumber=\count102
\c@internallinenumbers=\count103
\quotelinenumbersep=\dimen107
\bframerule=\dimen108
\bframesep=\dimen109
\bframebox=\box29
LaTeX Info: Redefining \\ on input line 3056.
)
\minted@appexistsfile=\read2
\FV@BreakIndent=\dimen110
\FV@BreakSymbolSepLeft=\dimen111
\FV@BreakSymbolSepRight=\dimen112
\FV@BreakSymbolIndentLeft=\dimen113
\FV@BreakSymbolIndentRight=\dimen114
\c@FancyVerbLineBreakLast=\count104
\FV@LineBox=\box30
\FV@LineIndentBox=\box31
\minted@bgbox=\box32
\minted@code=\write5
\c@minted@FancyVerbLineTemp=\count105
\@float@every@listing=\toks18
\c@listing=\count106
)
runsystem(mkdir -p "_minted-test")...executed.

runsystem(pygmentize -S default -f latex -P commandprefix=PYGdefault > "_minted
-test/default.pygstyle")...executed.


(./_minted-test/default.pygstyle)
runsystem(pygmentize -S monokai -f latex -P commandprefix=PYGmonokai > "_minted
-test/monokai.pygstyle")...executed.

 (./_minted-test/monokai.pygstyle)
runsystem(which "pygmentize" && touch "test.aex")...executed.

runsystem(rm "test.aex")...executed.


No file test.aux.
\openout1 = `test.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
(/usr/share/texlive/texmf-dist/tex/latex/xcolor/xcolor.sty
Package: xcolor 2007/01/21 v2.11 LaTeX color extensions (UK)

(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/color.cfg
File: color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
)
Package xcolor Info: Driver file: pdftex.def on input line 225.

(/usr/share/texlive/texmf-dist/tex/latex/pdftex-def/pdftex.def
File: pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX
\Gread@gobject=\count107

(/usr/share/texlive/texmf-dist/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count108
\scratchdimen=\dimen115
\scratchbox=\box33
\nofMPsegments=\count109
\nofMParguments=\count110
\everyMPshowfont=\toks19
\MPscratchCnt=\count111
\MPscratchDim=\dimen116
\MPnumerator=\count112
\makeMPintoPDFobject=\count113
\everyMPtoPDFconversion=\toks20
))
Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1337.
Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1341.
Package xcolor Info: Model `RGB' extended on input line 1353.
Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1355.
Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1356.
Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1357.
Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1358.
Package xcolor Info: Model `Gray' substituted by `gray' on input line 1359.
Package xcolor Info: Model `wave' substituted by `hsb' on input line 1360.
)
runsystem(pygmentize -S default -f latex -P commandprefix=PYG > "_minted-test/d
efault-pyg-prefix.pygstyle")...executed.

 (./_minted-test/default-pyg-prefix.pygstyle)
\openout3 = `test.pyg'.

runsystem(pygmentize -l python -f latex -P commandprefix=PYG -F tokenmerge -o "
_minted-test/3318EA94C8188411CBFFF36E96F147B7E7B905EAFB51304313A185A5EE7577BD.p
ygtex" "test.pyg" )...executed.


(./_minted-test/3318EA94C8188411CBFFF36E96F147B7E7B905EAFB51304313A185A5EE7577B
D.pygtex)
runsystem(rm "test.pyg")...executed.

 [1

{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./test.aux) ) 
Here is how much of TeX's memory you used:
 4213 strings out of 494953
 69833 string characters out of 6180978
 163369 words of memory out of 5000000
 7475 multiletter control sequences out of 15000+600000
 4116 words of font info for 16 fonts, out of 8000000 for 9000
 14 hyphenation exceptions out of 8191
 37i,5n,35p,818b,260s stack positions out of 5000i,500n,10000p,200000b,80000s
</usr/share/
texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb></usr/share/texliv
e/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/share/texlive/texmf
-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb>
Output written on test.pdf (1 page, 32945 bytes).
PDF statistics:
 20 PDF objects out of 1000 (max. 8388607)
 13 compressed objects within 1 object stream
 0 named destinations out of 1000 (max. 500000)
 1 words of extra memory for PDF output out of 10000 (max. 10000000)
  • Looks the same here on TL2017 (screenshot). If you do not like this colourtheme choose a different one or write your own. – Henri Menke Jun 9 '17 at 2:12
  • @HenriMenke No, the theme is not supposed to look like this. It's a dark theme, see here. – user2059300 Jun 9 '17 at 2:32
4

You have to set the background color yourself. This is not the default because it is really printer unfriendly.

\documentclass[a4paper]{article}
\usepackage{minted,xcolor}
\usemintedstyle{monokai}
\definecolor{bg}{HTML}{282828} % from https://github.com/kevinsawicki/monokai
\begin{document}

\textbf{Code Example:}
\begin{minted}[bgcolor=bg,
               frame=lines,
               framesep=2mm]{python}
    #!/usr/bin/env python2

    def example_function():
        return "hello world"

    a = 5
    b = "I am python code"
\end{minted}

\end{document}

enter image description here

  • Is it possible to set this option globally? – wvxvw Nov 12 '18 at 14:37
  • 2
    @wvxvw \setminted{bgcolor=bg} – Henri Menke Nov 12 '18 at 19:18

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.