6

I'm using the fancyvrb package and the Verbatim (with an uppercase V) environment. However, the font I'm using is to light for my taste, so I'd like to make it bold without having to write \textbf{} on every line.

My code looks like this:

\documentclass[11pt,oneside]{book}
% preamble
\usepackage{fontspec}
\setmonofont[Ligatures={NoRequired,NoCommon,NoContextual},Numbers={Lining,Monospaced},Scale=0.8]{Courier New}
% more preamble
\usepackage{verbatim}
\usepackage{fancyvrb}
% final part of the preamble
\begin{document}
\begin{Verbatim}[commandchars=\\\{\}]
this text is in a monospace font
\end{Verbatim}
\end{document}

I've tried adding something like Uppercase=Bold,Lowercase=Bold,Numbers=Bold to the \setmonofont options, but I haven't been able to get it to work. I've also tried using the command \verbatimfont, but that didn't work for me either.

Thnks in advance for any help.

  • Are you tied to fancyvrb for other reasons than shown in your MWE? For example, you make no use of commandchars, etc. – Steven B. Segletes May 29 '19 at 17:58
  • I use Verbatim for computer code. I want to be able to display normal code in black and comments in grey so the reader doesn't have to be familiar with the specific language's comment delimiters and can just differentiate code and comments without any extra effort. If there's another package that can do that in a simple way, I'm not tied to fancyvrb. – Rain May 29 '19 at 18:04
  • You need a bold mo,o font. cm-unicode and Latin Modern have. – Bernard May 29 '19 at 18:12
5

Just load the Courier New Bold font as the mono font. I've removed your Ligatures and Numbers options since these aren't available in this font (they produce warnings.)

\documentclass[11pt,oneside]{book}
% preamble
\usepackage{fontspec}
\setmonofont[Scale=0.8]{Courier New Bold}
% more preamble
\usepackage{verbatim}
\usepackage{fancyvrb}
% final part of eh preamble
\begin{document}
\begin{Verbatim}[commandchars=\\\{\}]
this text is in a monospace font
\end{Verbatim}
\end{document}

output of code

  • Well, this works and is trivial to implement. Thanks a lot. :) Just out of academic interest, will this work for any font that has a defined bold version? And if a font doesn't have a bold version then how can I enforce a \textbf equivalent? – Rain May 29 '19 at 18:06
  • 1
    Yes (same for italics, italic bold etc); basically any face that the font has. If a font doesn't have a bold face, then no, it won't work. It's possible (but not recommended) to use FakeBold. See the fontspec documentation for details. – Alan Munn May 29 '19 at 18:09
  • Will do, thanks for the pointer! – Rain May 29 '19 at 18:09
4

An alternative version that loads the Black (or ExtraBold, etc.) weight as “bold”, and also sets up italics:

\setmonofont{Some Font}[
  Scale = MatchLowercase ,
  UprightFont = * Bold ,
  ItalicFont = * Bold Italic ,
  BoldFont = * Black ,
  BoldItalicFont = * Black Italic ]

Change this to match the names of your font files. For example, if you have Some Font-Bold.otf and Some Font-ExtraBold.otf on your system, you would instead load UprightFont = *-Bold, BoldFont = *-ExtraBold, and Extension = .otf.

  • Thanks, I'll give this a try late tonight; I like the idea of having italics as well. – Rain May 30 '19 at 12:49

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.