3

Since years I use for my book Garamond for normal text and Beramono as typewriter style. On my new laptop, new Cygwin with pdfTeX 3.14159265-2.6-1.40.17, these fonts give a conflict. Keywords in the listings aren't bold any more. If I skip Garamond, the keywords are bold, but then I have the wrong font for text.

\documentclass[]{article}                           
\usepackage[dutch]{babel}                           

\usepackage[urw-garamond,ttscaled=false]{mathdesign}
\usepackage[T1]{fontenc}                            
\usepackage[scaled=0.77]{beramono}                  

\usepackage[]{listings}                             

\lstset{                                            
  language=C,                                       
  basicstyle={\ttfamily\small},                     
  keywordstyle={\bfseries},                         
  commentstyle={\itshape},                          
  showstringspaces=false                            
}                                                   

\begin{document}                                    
This is normal text.                                
\begin{lstlisting}[]                                
#include <stdio.h>                                  

int main(void)                                      
{                                                   
  printf("Hello World\n);                           

  return 0;                                         
}                                                   
\end{lstlisting}                                    
This is normal text.                                
\end{document}

The words int, #include and void should be bold, but they are not. I hope someone knows what is wrong.

2
  • On my recent Debian/TeXLive install, I get the desired result if I replace \usepackage[urw-garamond,ttscaled=false]{mathdesign} with \usepackage{ebgaramond}. Can you try that? Aug 4, 2017 at 17:13
  • This solution is fine, but the font size of Garamond is different and ebgaramond has no bold. I also use bold in normal text.
    – Wim Dolman
    Aug 4, 2017 at 17:51

1 Answer 1

2

With the urw-garamond option, mathdesign redefines \bfdefault to be mb instead of b (or bx). Indeed, you get a warning

LaTeX Font Warning: Font shape `T1/fvm/mb/n' undefined
(Font)              using `T1/fvm/m/n' instead on input line 21.

If you just need the monospaced boldface font inside listings, the simplest workaround is to select the right font series.

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[dutch]{babel}

\usepackage[urw-garamond,ttscaled=false]{mathdesign}
\usepackage[scaled=0.77]{beramono}

\usepackage[]{listings}

\lstset{
  language=C,
  basicstyle=\ttfamily\small,
  keywordstyle=\fontseries{b}\selectfont,
  commentstyle=\itshape,
  showstringspaces=false,
}                                                   

\begin{document}

This is normal text.
\begin{lstlisting}[]
#include <stdio.h>

int main(void)
{
  printf("Hello World\n);

  return 0;
}
\end{lstlisting}
This is normal text.

\end{document}

enter image description here

A more complete solution can be obtained by defining the suitable font substitutions:

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[dutch]{babel}

\usepackage[urw-garamond,ttscaled=false]{mathdesign}
\usepackage[scaled=0.77]{beramono}

\usepackage[]{listings}

\makeatletter
\input{t1fvm.fd}
\DeclareFontShape{T1}{fvm}{mb}{n}{<->ssub * fvm/b/n}{}
\DeclareFontShape{T1}{fvm}{mb}{sl}{<->ssub * fvm/b/sl}{}
\DeclareFontShape{T1}{fvm}{mb}{it}{<->ssub * fvm/b/sl}{}
\makeatother

\lstset{
  language=C,
  basicstyle=\ttfamily\small,
  keywordstyle=\bfseries,
  commentstyle=\itshape,
  showstringspaces=false,
}                                                   

\begin{document}

This is normal text.
\begin{lstlisting}[]
#include <stdio.h>

int main(void)
{
  printf("Hello World\n);

  return 0;
}
\end{lstlisting}
This is normal text.

\end{document}
1
  • This answer gives the solution for myy problem. Thank you very much.
    – Wim Dolman
    Aug 4, 2017 at 17:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .