1

I want to switch to minted over listings for the superior syntax highlighting, especially for C++. But I can't get the font to look as nicely as with listings. Somehow the font is heavier and more condensed when generated with minted.

Here's an example (listings above, minted below):

listings above, minted below

This is my config for both of them:

\newfontfamily\UbuntuMono{Ubuntu Mono}
\setmonofont{Ubuntu Mono}

\lstset{
  backgroundcolor=\color{dsolar_back},
  basicstyle=\UbuntuMono\footnotesize\color{dsolar_text},
  breakatwhitespace=false,
  breaklines=true, 
  captionpos=b,
  commentstyle=\color{dsolar_comm},
  extendedchars=true, 
  frame=single, 
  keepspaces=true,
  keywordstyle=\color{dsolar_keyw}, 
  language=[11]C++,              
  numbers=left,                
  numbersep=5pt,
  rulecolor=\color{lightgrey},
  showspaces=false, 
  showstringspaces=false,
  showtabs=false,
  stepnumber=2,
  stringstyle=\color{dsolar_ltrl},
  tabsize=4,
  title=\lstname
}

\usepackage[cache=false]{minted}

\setminted[c++]{
    linenos=true,
    bgcolor=dsolar_back,
    fontsize=\footnotesize,
    style=solarizedlight,
    frame=single,
    framesep=0pt,
    rulecolor=\color{lightgrey},
    stepnumber=2,
    numbersep=5pt,
    resetmargins=true
}

Has anyone had experience with this? Are the some settings that I am missing? Thanks for your help!

3

Those are the default behaviors. If you are using a monospace font, you should follow the minted's spacing, because the wide spacing in listings is just to make sure that even normal fonts become monospace.

If you want to use a wide font, you can borrow microtype.

In the following code, the above is the normal spacing, the below is the modified spacing. I don't have your font family, so I use a similar one (DejaVu Sans Mono):

\documentclass{article}
\usepackage[scaled=0.85]{DejaVuSansMono}
\usepackage{minted}
\usepackage[letterspace=100]{microtype}
\usepackage{lipsum}
\newenvironment{myminted}
{\VerbatimEnvironment
\begingroup\lsstyle
\begin{minted}{C++}}
{\end{minted}
\endgroup}

\begin{document}
\lipsum[1]
\begin{minted}{C++}
#include <cstdio>
int main() {
    printf("Hello, world!");
}
\end{minted}

\begin{myminted}
#include <cstdio>
int main() {
    printf("Hello, world!");
}
\end{myminted}
\lipsum[2]
\end{document}

enter image description here

  • This fixes the spacing, thanks! Concerning the minted code being "heavier" / darker, this is apparently a problem with listings where the text color isn't the actual colour set via the options but a shade light for some reason. [I verified with a colour picker that the minted colour is correct.] – h-2 May 15 at 17:05
  • @h-2 If you use a normal font (not a typewriter font) in listings, you will know why listings produces such a giant space (I don't like it). Some people don't like formatting their code with code fonts :) – user156344 May 15 at 17:07
  • Is there a way to get \lsstyle into the minted options and not having to create a new env? – h-2 May 15 at 17:10
  • @h-2 I don't know yet. I don't use minted often recently so I don't think I am confident enough. But you can do some trial-and-error tests on fontstyle, etc. Anyway I think defining a new environment is the best option. – user156344 May 15 at 17:12

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.