Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
  • My OS : Ubuntu 13.10
  • Latex version used : Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian)

In my report, I am using the following listing :

\lstdefinestyle{BashInputStyle}{
  language=bash,
  basicstyle=\small\sffamily,
  numbers=left,
  numberstyle=\tiny,
  numbersep=3pt,
  frame=tb,
  framerule=0pt,
  columns=fullflexible
}

I would like to know if it is possible to configure the font style of this listing (and this listing only!), setting upbasicstyle, I assume. I would like to configure this font style as Ubuntu Monospace (known by my OS).

Is there a simple way for doing it please ?

share|improve this question
add comment

2 Answers 2

If you're using the fontspec package to load fonts in XeTeX or LuaTeX, you can use

\newfontfamily\UbuntuMonospace{Ubuntu Monospace}

in your preamble, and then, in your list of options for listings, include

basicstyle=\small\UbuntuMonospace

If this is the only use of monospaced fonts in your document, you can instead use

\setmonofont{Ubuntu Monospace}

in the preamble, which will then define \texttt to use Ubuntu Monospace. Thus using this in your listing will require simply

basicstyle=\small\texttt
share|improve this answer
add comment

that is only possible with XeLaTeX or LuaLaTeX:

\documentclass{article}
\usepackage{fontspec}
\newfontface\UMono[Scale=0.9]{UbuntuMono-Regular}

\usepackage{listings}
\lstdefinestyle{BashInputStyle}{
  language=bash,
  basicstyle=\UMono,
  numbers=left,
  numberstyle=\tiny,
  numbersep=3pt,
  frame=tb,
  framerule=0pt,
  columns=fullflexible
}
\begin{document}

\begin{lstlisting}[style=BashInputStyle]
rsync -tovupgilr --progress --delete --exclude-from=/extern.txt / /extern
\end{lstlisting}

%the same with the default mono font:
\begin{lstlisting}[basicstyle=\small\ttfamily]
rsync -tovupgilr --progress --delete --exclude-from=/extern.txt / /extern
\end{lstlisting}

\end{document}

enter image description here

the used fonts in the pdf are:

voss@shania:~/Test> pdffonts test7.pdf
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
JLZYGL+LMRoman5-Regular              CID Type 0C       Identity-H       yes yes yes      4  0
UYSVMJ+UbuntuMono-Regular            CID TrueType      Identity-H       yes yes yes      5  0
FXXUVH+CMSY10                        Type 1            Builtin          yes yes no       6  0
PREOYV+LMMono9-Regular               CID Type 0C       Identity-H       yes yes yes      7  0
JFRMQG+LMRoman10-Regular             CID Type 0C       Identity-H       yes yes yes      8  0
share|improve this answer
1  
First of all, thanks for your answer. I suppose it means that I need to install textlive-full on my system then. There is no configuration possible on pdflatex if I understand you well? Why so? –  Header12 Dec 21 '13 at 9:47
    
I always use TeXLive full from tug.org/texlive and not the one from Ubuntu. However, it is also possible to use the font with pdflatex, if you create all the needed auxiliary files which is not really simple. –  Herbert Dec 21 '13 at 9:52
    
How did you compiled this ? I do not manage to handle it using xelatex, since I am receiving some "Option `pdftex' requires pdfTeX" errors. –  Header12 Dec 26 '13 at 14:28
    
looks like that you have an optional argument pdftex in your preamble when loading a package, e.g. graphicx. Delete that option it is already not needed. –  Herbert Dec 27 '13 at 7:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.