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 am writing some document which contains Cg (C for Graphics) code in the document. I want to show the code in a neat highlighted mode. Any easy method to suggest? I tried the listings package but it doesn't support Cg language.

share|improve this question
I'm not very familiar with Cg, adding additional keywords to listings starting from, e.g., C, is not very difficult. I think to a zeroth approximation, a key like morekeywords={foo,bar,baz} might work, but better check the manual. – Ulrich Schwarz Dec 14 '10 at 22:03
OK, I found the solution. It is similar to your suggestion. Check my answer :-) – Rafid Dec 14 '10 at 22:54
up vote 8 down vote accepted

OK, I found the solution to my own question. I defined the Cg language using the following code:

    morekeywords={void, float, float2, float4, float4,
        float4x4, POSITION, TEXCOORD0, out, uniform},

Some notes:
1. The 'morekeywords' specify the keywords of the language. Obviously, there are many more keywords in the Cg language, but I used the ones I need.
2. The 'morecomment' is used to specify commenting styles in the language. Cg language use the same style as C language.

Then I used the following code to make some customization:


Finally, including my code in the document:


Don't forget to include the listings package:


Hope that helps!

share|improve this answer
Nice find, and +1 for being considerate enough to answer your own question for others :) – Adrian Petrescu Dec 15 '10 at 4:30

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.