# 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?

-

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
show 1 more comment