I am using Bera Sans Mono as the monospaced font for typesetting code listings using the listings package. This is done for slides which are produced using beamer and XeLaTeX. My preamble includes the following (which used to work before a recent update to the MikTeX engine, the fontspec package, and the above-mentioned packages):

\setmonofont{Bera Sans Mono}[Scale=0.9] % for code listings beramono is used
\newfontfamily\quotefont{Linux Libertine O}[Ligatures=TeX] % selects Libertine for quotation marks

The output produced is: Garbled code listing

If I do not use \setmonofont and have the following preamble instead, the correct output is produced:

\newfontfamily\quotefont{Linux Libertine O}[Ligatures=TeX] % selects Libertine for quotation marks

Correct code listing

Why am I unable to use \setmonofont{Bera Sans Mono}[Scale=0.9] (which used to work before)?

Some additional points to note:

  1. XeLaTeX is able to find the font
  2. \setmonofont appears to work correctly with other fonts, just not Bera Sans Mono.
  • A minimal (non) working example? – egreg Sep 2 '15 at 12:35
  • Probably xetex and/or xdvipdfmx is finding a wrong font. This can happen if there are two versions of a font on a system. Add \XeTeXtracingfonts= 1 to your document, and then compile on the command line with xelatex --nopdf file and xdvipdfmx -vv file.xdv then the log and the terminal output will show the pathes of the fonts used. – Ulrike Fischer Sep 2 '15 at 13:30
  • I should have checked first. There is no opentype font "bera sans mono", it is a type1 font. You shouldn't load it with \setmonofont.Try \setmonofont{Bitstream Vera Sans Mono}[Scale=0.9]` instead. – Ulrike Fischer Sep 2 '15 at 13:54
  • @UlrikeFischer Thank you! Your suggestion to use the Bitstream font worked and helped to clear up some misunderstandings on my part. Do you want to post this as a formal answer? – Steve Sep 3 '15 at 7:59

There is no opentype font Bera Sans Mono, xelatex finds the normal type1 version and as it is not unicode encoded you get garbage.

To quote the CTAN info (http://www.ctan.org/pkg/bera)

The Bera fam­ily is a repack­ag­ing, for use with TEX, of the Bit­stream Vera fam­ily.

So with xelatex you should use

\setmonofont{Bitstream Vera Sans Mono}

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.