3

I like the beramono font, and I want to use it for code listings (using the listings package). I want the standard CMR tt font for typewriter font in the body of the text.

I could do this using XeLaTeX, by importing beramono using fontspec - but I can't find the proper name of the font! All I can find is (for LaTeX):

\usepackage[T1]{fontenc}
\usepackage{beramono}

which is all very well, but it changes all typewriter fonts, not just the ones in the listings. What I want is to use XeLaTeX with something like

\usepackage{fontspec}
\newfontface\lstmono[scale=0.9]{The Proper Name for Beramono}

and then in my listing preamble include

basicstyle=\lstmono

However, I don't know the proper name for beramono. The command fc-list has not been much help. Can beramono be used with XeLaTeX?

  • Is the point that you really want to use XeTeX or is the point that you really want to use beramono just for listings? Because you can certainly set (any supported) font up so that you can use it only for certain elements of your document with (pdf)TeX. The font is type1. Can XeTeX use type1 fonts? fc-list will only help if it is installed for your system. You probably only have it installed right now for TeX. – cfr May 21 '14 at 2:47
  • Well, my question really is how do I use beramono just for listings. Is there a way with pdfLaTeX? – Alasdair May 21 '14 at 3:05
  • Just discovered that basicstyle=\small\fontfamily{fvm}\selecfont does the job... – Alasdair May 21 '14 at 4:39
  • @Alasdair would you like to write a self-answer so this can be taken off the unanswered list? – Paul Gessler Jan 6 '15 at 12:29
4

Download the ttf version from

http://ftp.gnome.org/pub/GNOME/sources/ttf-bitstream-vera/1.10/

and save the files in a directory where your system will find the fonts. Then define a typeface

\newfontfamily\Bera{Bitstream Vera Sans Mono}[Scale=0.85]

As an alternative use the file name.

Then you can use listings with

\lstset{basicstyle=\Bera\small,...}

An example:

\documentclass{article}
\usepackage{fontspec}
\usepackage{listings,xcolor}
\newfontfamily\Bera{Bitstream Vera Sans Mono}[Scale=0.85]
\lstset{basicstyle=\Bera\small,keywordstyle=\bfseries,commentstyle=\itshape}
\begin{document}

\begin{lstlisting}[language={[LaTeX]TeX}]
\documentclass{article}% standard class
\usepackage{pst-eps}
\usepackage{graphicx}
\begin{document}
\end{lstlisting}

\texttt{Default monotype} 
\textbf{\texttt{Default bold monotype}} 
\end{document}

enter image description here

1

This is based on the OP's comment that solved the problem. Under pdflatex, xelatex or lualatex you can select the font explicitly at any point using

\fontencoding{T1}\fontfamily{fvm}\selectfont

Note the specific declaration of the font encoding, which is needed if you have not set this globally in the document. For listings, you can then set basicstyle to call use this font.

Sample output

\documentclass{article}

\usepackage{listings}
\lstset{basicstyle=\small\fontencoding{T1}\fontfamily{fvm}\selectfont}

\begin{document}

Demonstrating ordinary typerwriter font \texttt{ordinary typewriter
font} for comparison.

\begin{lstlisting}
  Some = code + bera mono;
\end{lstlisting}

\end{document}

A similar approach can be used with xelatex (or lualatex) combined with fontspec, but you would need an open type bera font, and I am not sure that exists. Here is the relevant code with another fixed width font.

Second sample

\documentclass{article}

\usepackage{fontspec}
\usepackage{listings}

\newfontfamily\lstfont{almfixed.otf}
\lstset{basicstyle=\small\lstfont}

\begin{document}

Demonstrating ordinary typerwriter font \texttt{ordinary typewriter
font}.

\begin{lstlisting}
  Some = code;
\end{lstlisting}

\end{document}

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.