[Tex/LaTex] way to enable syntax highlighting coloring in Lyx for program listings

codecolorlistingslyxsyntax

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?

Best Answer

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.)