4

I'm using the solution here for scala support, but this fails to properly color the scala code, and throws a number of errors when processing lstset - % ! Package keyval Error: breakatwhitespace undefined. Can anyone help me figure out what's wrong with this simple example?

\documentclass[journal]{IEEEtran}
\usepackage{listings}

% "define" Scala
\lstdefinelanguage{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]"""
}

\usepackage{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
  language=scala,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  frame=single,
  breaklines=true,
  breakatwhitespace=true
  tabsize=3
}
% A number of keyval errors occur here - basically 
% nothing in lstset is recognized. Errors look like:
% ! Package keyval Error:   breakatwhitespace undefined.

\begin{document}

\begin{lstlisting}
object Test {
   def main(args: Array[String]) {
      var a = 0;
      // for loop execution with a range
      for( a <- 1 to 10){
         println( "Value of a: " + a );
      }
   }
}
\end{lstlisting}

\end{document}

EDIT: After adding in \listfiles, here's the file list I see

 *File List*
IEEEtran.cls    2007/03/05 V1.7a by Michael Shell
  ot1ptm.fd    2001/06/04 font definitions for OT1/ptm.
  xspace.sty    2009/10/20 v1.13 Space after command names (DPC,MH)
  epsfig.sty    1999/02/16 v1.7a (e)psfig emulation (SPQR)
graphicx.sty    1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    1999/03/16 v1.13 key=value parser (DPC)
graphics.sty    2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2010/04/23 v1.9 graphics configuration of TeX Live
  pdftex.def    2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
 ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
     url.sty    2006/04/12  ver 3.3  Verb mode for urls, etc.
    cite.sty    2010/09/10  v 5.3
fancybox.sty    2010/05/15 1.4
listings.sty    2007/02/22 1.4 (Carsten Heinz)
 lstmisc.sty    2007/02/22 1.4 (Carsten Heinz)
listings.cfg    2007/02/22 1.4 listings configuration
   color.sty    2005/11/14 v1.0j Standard LaTeX Color (DPC)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
lstlang1.sty    2004/09/05 1.3 listings language file
lstlang1.sty    2004/09/05 1.3 listings language file
supp-pdf.mkii
pdftexcmds.sty    2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO)
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
   ifpdf.sty    2011/01/30 v2.3 Provides the ifpdf switch (HO)
epstopdf-base.sty    2010/02/09 v2.5 Base part for package epstopdf
  grfext.sty    2010/08/19 v1.1 Manage graphics extensions (HO)
kvdefinekeys.sty    2011/04/07 v1.3 Define keys (HO)
kvoptions.sty    2011/06/30 v3.11 Key value format for package options (HO)
kvsetkeys.sty    2012/04/25 v1.16 Key value parser (HO)
etexcmds.sty    2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
epstopdf-sys.cfg    2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
  ot1pcr.fd    2001/06/04 font definitions for OT1/pcr.
sections/introduction.tex
sections/background.tex
sections/challenges.tex
sections/solution.tex
figures/vnc-overview.pdf
sections/results.tex
  omsptm.fd
figures/client-heap.png
figures/master-heap.png
sections/relatedwork.tex
sections/conclusion.tex
   clasp.bbl
6
  • This compiles fine for me (with updated TeXLive2014). Must be some issue related to an out of date package. I'd suggest adding \listfiles just before \begin{document} and posting the versions of all the packages here and we can compare. Sep 22, 2014 at 0:21
  • Added, thanks for looking! If it matters, I'm using latexmk -pdf to compile because I'm a Latex compilation noob and need to focus on my dissertation :-P
    – Hamy
    Sep 22, 2014 at 0:26
  • I meant add \listfiles to the MWE above, not you full doc as then many other packages are being added. Yep, your packages are way out of date: I have keyval.sty 2014/05/08 v1.15, listings.sty 2014/09/06. I'd recommend you use an update distribution rather than try to patch one package at a time. Sep 22, 2014 at 0:28
  • Ah yea that makes sense, my bad. Upgrading fixed the issues, works fine now. If you'll post that as an answer I'll accept to mark this as closed
    – Hamy
    Sep 22, 2014 at 0:45
  • 1
    Thanks, but I think @Jubobs answer is better than what I would have written. Sep 22, 2014 at 14:15

1 Answer 1

5

As noted by Peter in his comments, your TeX distribution seems badly out of date. Time to blow the rust off it, and fire up your package manager.

Also, you're missing a comma after breakatwhitespace=true.

Besides, since October 2013, the listings package comes with a language definition for Scala (in the lstdvrs.dtx file). If you update your TeX distribution, you shouldn't have to redefine that language from scratch in your .tex file in order to use it.

enter image description here

\documentclass{article}

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

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstdefinestyle{myScalastyle}{
  frame=tb,
  language=scala,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  frame=single,
  breaklines=true,
  breakatwhitespace=true,
  tabsize=3,
}


\begin{document}
\begin{lstlisting}[style=myScalastyle]
object Test {
   def main(args: Array[String]) {
      var a = 0;
      // for loop execution with a range
      for( a <- 1 to 10){
         println( "Value of a: " + a );
      }
   }
}
\end{lstlisting}
\end{document}
3
  • I had to run sudo tlmgr update --all to get the latest, MacTex 2014 was outdated. I think it's only fair to give Peter the answer credit, but if he doesn't answer within the next few days I'll mark this as accepted
    – Hamy
    Sep 22, 2014 at 13:31
  • Leave Peter an "@" comment below your question to ask him to post an answer.
    – jub0bs
    Sep 22, 2014 at 13:32
  • Good point, done
    – Hamy
    Sep 22, 2014 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .