# Is there a way to enable syntax highlighting coloring in Lyx for program listings?

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?

-
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 '14 at 11:26

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 `listings`options 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.)

-
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
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}
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.lida``r.growing`.