我正在使用解决方案这里用于 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}