TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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

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.lidar.growing.

share|improve this answer

Your Answer


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.