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 want to embed a small program listing and have used Insert -> Program Listing in LyX's menu for that.

The settings dialog supports selecting a language (Java), but I can't actually see any difference.

Is there a way to get real syntax highlighting/coloring?

share|improve this question
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Mar 2 at 11:26

2 Answers 2

up vote 7 down vote accepted

Lyx's "Insert -> Program Listing" is internally based on the listings package, which provides a a plenty full of options to influence the typesetting. You can enter such listingsoptions on the "Advanced" page of the "Listing Settings" dialog. For instance, entering

keywordstyle={\color{blue}}

there would typeset all keywords in blue color. For a quick start take a look at other questions with the tag – or consult the (excellent!) listings documentation

The reason you do not "see any difference" in your current setup may be a font issue: The culprit is the standard typewriter font in LaTeX, which does not have a boldface version; however, the default of listings is keywordstyle=\bfseries, that is, keywords are typeset in boldface. So just try another typewriter font in "Document -> Settings -> Fonts" and see if this makes a difference.

(BeraMono is a good font for typesetting listings.)

share|improve this answer
    
I'm using "Latin Modern Typewriter" is this supposed to work? –  soc Sep 15 '11 at 23:55
    
@soc: So have you tried another font to see if this makes a difference? AFAIK LMT supports a boldface series, but at small font sizes the visual difference to normalfont is not too obvious. –  Daniel Sep 16 '11 at 7:12
    
Mhhh, I have tried various fonts, but bold worked with none of them... :-/ –  soc Sep 16 '11 at 9:43
    
@soc: Have you tried setting keywordstyle explicitly, as described in my answer? –  Daniel Sep 16 '11 at 11:49
    
Yes, I set the color to blue, which worked... –  soc Sep 16 '11 at 12:20

An example for GRASS-GIS module names. The code goes to the Listings section (to be found under Document > Settings... ):

alsoletter={*()"'0123456789.}
alsoother={\{\=\}}
backgroundcolor={\color{lightgray3}}
basicstyle={\small\ttfamily}
breaklines=true
commentstyle={\itshape\color{lightgray}}
fillcolor={\color{red}}
frame=l
framexleftmargin=1em
framextopmargin=1em
keywordstyle={\color{magenta}\bfseries}
language=bash
literate={{=}{{{\color{blue}=}}}1}
morecomment={[n][\keywordstyle]{{}{}}}
morekeywords={GRASS_OVERWRITE, region, zoom, nsres, ewres, MASK, input, in, rast, map, output, out, type, use, attrcolumn, rgbcolumn, labelcolumn, method, size, title, color, null(), S, N, W, E, a, b, c, d, e, f, g, n, s, w, e, --o, -c, -e, -s, -ca}
otherkeywords={g.access,g.cairocomp,g.copy,g.dirseps,g.filename,g.findetc,g.findfile,g.gisenv,g.gui,g.list,g.mapset,g.mapsets,g.message,g.mkfontcap,g.mlist,g.mremove,g.parser,g.pnmcat,g.pnmcomp,g.ppmtopng,g.proj,g.region,g.remove,g.rename,g.setproj,g.tempfile,g.version,r.basins.fill,r.bitpattern,r.buffer,r.carve,r.category,r.circle,r.clump,r.coin,r.colors,r.colors.out,r.composite,r.compress,r.contour,r.cost,r.covar,r.cross,r.describe,r.digit,r.distance,r.drain,r.external,r.external.out,r.fill.dir,r.flow,r.grow,r.grow.distance,r.gwflow,r.his,r.horizon,r.in.arc,r.in.ascii,r.in.bin,r.info,r.in.gdal,r.in.gridatb,r.in.lidar,r.in.mat,r.in.png,r.in.poly,r.in.xyz,r.kappa,r.lake,r.le,r.li,r.los,r.mapcalc,r.mfilter,r.mode,r.neighbors,r.null,r.out.arc,r.out.ascii,r.out.bin,r.out.gdal,r.out.gridatb,r.out.mat,r.out.mpeg,r.out.png,r.out.pov,r.out.ppm,r.out.ppm3,r.out.tiff,r.out.vrml,r.out.vtk,r.param.scale,r.patch,r.profile,r.proj,r.quant,r.quantile,r.random,r.random.cells,r.random.surface,r.reclass,r.recode,r.region,r.regression.line,r.report,r.resamp.bspline,r.resamp.filter,r.resamp.interp,r.resample,r.resamp.rst,r.resamp.stats,r.rescale,r.rescale.eq,r.ros,r.series,r.series.interp,r.shaded.relief2,r.slope.aspect,r.solute.transport,r.spread,r.spreadpath,r.statistics,r.statistics2,r.statistics3,r.stats,r.sun,r.sunmask,r.support,r.support.stats,r.surf.area,r.surf.contour,r.surf.fractal,r.surf.gauss,r.surf.idw,r.surf.idw2,r.surf.random,r.terraflow,r.texture,r.thin,r.timestamp,r.topidx,r.topmodel,r.to.rast3,r.to.rast3elev,r.to.vect,r.transect,r.univar,r.uslek,r.usler,r.viewshed,r.volume,r.walk,r.water.outlet,r.watershed,r.what,r.what.color,v.buffer,v.build,v.build.polylines,v.category,v.class,v.clean,v.colors,v.colors.out,v.convert,v.db.connect,v.db.select,v.delaunay,v.distance,v.drape,v.edit,v.external,v.external.out,v.extract,v.extrude,v.generalize,v.hull,v.in.ascii,v.in.db,v.in.dwg,v.in.dxf,v.info,v.in.lidar,v.in.ogr,v.in.region,v.in.sites,v.kcv,v.kernel,v.label,v.label.sa,v.lidar.correction,v.lidar.edgedetection,v.lidar.growing,v.lrs,v.mapcalc,v.mkgrid,v.neighbors,v.net,v.net.alloc,v.net.allpairs,v.net.bridge,v.net.centrality,v.net.components,v.net.connectivity,v.net.distance,v.net.flow,v.net.iso,v.net.path,v.net.salesman,v.net.spanningtree,v.net.steiner,v.net.timetable,v.net.visibility,v.normal,v.out.ascii,v.out.dxf,v.outlier,v.out.ogr,v.out.postgis,v.out.pov,v.out.svg,v.out.vtk,v.overlay,v.parallel,v.patch,v.perturb,v.proj,v.qcount,v.random,v.reclass,v.rectify,v.sample,v.segment,v.select,v.split,v.support,v.surf.bspline,v.surf.idw,v.surf.rst,v.timestamp,v.to.3d,v.to.db,v.to.points,v.to.rast,v.to.rast3,v.transform,v.type,v.univar,v.vect.stats,v.vol.rst,v.voronoi,v.what,v.what.rast,v.what.rast3,m.cogo,m.measure,m.nviz.image,m.nviz.script,m.transform}
prebreak={\textbackslash}
sensitive=true
stepnumber=1
tabsize=4
upquote=true

It works fine, except for one error: the keyword v.lidar.growing isn't colored correctly. Because there is an r.grow entry already, only a part of it appears to get the desired color (here the bold letters), v.lidar.growing.

share|improve this answer

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.