無法使用清單定義 scala 語言

無法使用清單定義 scala 語言

我正在使用該解決方案這裡用於 scala 支持,但這無法正確為 scala 程式碼著色,並且在處理 lstset 時引發許多錯誤 -% ! Package keyval Error: breakatwhitespace undefined.誰能幫我找出這個簡單範例的問題所在?

\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}

編輯:添加後\listfiles,這是我看到的文件列表

 *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

答案1

正如 Peter 在他的評論中指出的那樣,您的 TeX 發行版似乎已經嚴重過時了。是時候清除它的鏽跡,並啟動你的套件管理器了。

另外,你後面少了一個逗號breakatwhitespace=true

此外,自 2013 年 10 月起,該listings軟體包附帶了 Scala 的語言定義(在lstdvrs.dtx文件)。如果您更新 TeX 發行版,則不必在文件中從頭開始重新定義該語言.tex即可使用它。

在此輸入影像描述

\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}

相關內容