[Tex/LaTex] Change in \lstdefinelanguage the font

fontslanguageslistings

Im using \lstdefinelanguage to add some new languages. Now everything is fine, I just would like to add another font to my language. I would like to use inconsolata.

I have now this:

%...
\usepackage{inconsolata}
\lstdefinelanguage{Scala}
{
  %...
  basicstyle=\small %what else do i have to add to use inconsolata?
}

Any ideas? Thanks

Best Answer

Just loading the inconsolata package, the monospaced font is redefined, so it's enough to add \ttfamily (you could also access the font using \fontfamily{fi4}\selectfont):

\documentclass{article}
\usepackage{listings}
\usepackage{inconsolata}
\lstdefinelanguage{Scala}
{
  %...
  basicstyle=\ttfamily\small
}
\begin{document}

\begin{lstlisting}[language=Scala]
object HelloWorld {
    def main(args: Array[String]) {
      println("Hello, world!")
    }
  }
\end{lstlisting}

\end{document}

enter image description here

Related Question