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.

I have happily used the fancyvrb package with the Verbatim environment so far, but I want to change my figures to use the listing package with the lstlisting environment in order to have bold-faced keywords which improve readability.

Unfortunately, I have no clue to adjust the listing settings to get the same (very nice) font I had before with fancyvrb...

Here is my fancy verb settings:

% fancy verb
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}
\usepackage{relsize}
\fvset{fontfamily=fvm}
\fvset{fontsize=\relsize{-2}}
\fvset{baselinestretch=1.3}

And here for listings, using the Scala language:

% listings
\usepackage{listings}
\lstdefinelanguage{scala}{ % "define" Scala
  morekeywords={abstract,case,catch,class,def,do,else,extends,false,final,%
    finally,for,if,implicit,import,match,mixin,new,null,object,override,package,%
    private,protected,requires,return,sealed,super,this,throw,trait,true,try,%
    type,val,var,while,with,yield},
  otherkeywords={=>,<-,<\%,<:,>:,\#,@},
  sensitive=true,
  morecomment=[l]{//},
  morecomment=[n]{/*}{*/},
  morestring=[b]",
  morestring=[b]',
  morestring=[b]"""
}
\lstset{ % activate the language and predefine settings
    language=scala,%
    fontadjust=true,%
    columns=[c]fixed,%
    keepspaces=true,%
    basewidth={0.58em, 0.53em},%
    tabsize=2,%
    basicstyle=\renewcommand{\baselinestretch}{0.95}\ttfamily,%
    commentstyle=\itshape,%
    keywordstyle=\bfseries,%
    mathescape=true,%
    escapechar=€,%
    captionpos=b,%
    framerule=0.3pt,%
    firstnumber=0,%
    numbersep=1.5mm,%
    numberstyle=\tiny,%
}

And here is the document body contrasting both:

\documentclass{article}
% ... paste the fancy verb and listing settings from above here
\begin{document}

\begin{Verbatim}
object Stream {
  def cons[A](hd: A, tl: => Stream[A]) = new Stream[A] {
     def head = hd
     lazy val tail = tl
     ...
  }
}
\end{Verbatim}

\begin{lstlisting}
object Stream {
  def cons[A](hd: A, tl: => Stream[A]) = new Stream[A] {
     def head = hd
     lazy val tail = tl
     ...
  }
}
\end{lstlisting}

\end{document}

Neither does the font of listing look remotely like the T1/fancyvrb one, nor does LaTeX seem to pay attention to setting the keywords in bold-face:

enter image description here

I guess I need to change the basicstyle entry, but how?

share|improve this question
    
Just a short note: Did you notice, that you can use listings together with fancyvrb? See the according section in documentation of listings. –  Speravir Mar 3 '13 at 22:37
    
@Speravir Perfect, can you post that as an answer, then I will accept! –  Emit Taste Mar 3 '13 at 22:44
1  
Much better: Provide a self-answer with all bells and whistles. –  Speravir Mar 3 '13 at 22:45

1 Answer 1

up vote 2 down vote accepted

Ok, so this actually the answer of @Speravir :)

All that is needed is the following listing settings:

\lstset{
  language=scala,%
  commentstyle=\itshape,%
  keywordstyle=\bfseries,%
  fancyvrb=true % !!
}

Then everything already set in \begin{Verbatim}...\end{Verbatim} benefits from the keyword and comment highlighting.

share|improve this answer
    
One should read the section “Interface to fancyvrb” in the listings documentation for respective caveats. –  Speravir Mar 3 '13 at 22:51

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.