# Lyx code tag with highlighting for C

I just installed Lyx and when I try to insert the program I observe that there is no syntax highlighting. What is the best way to allow for syntax highlighting in LYX?

• LyX is a LaTeX code editor, but I think it's not designed for program listings in other languages. Or do you want to use a listing inside a (La)TeX document? – user31729 Mar 6 '15 at 12:23
• Its the latter. I have some code which I need to insert – Sab Mar 6 '15 at 12:25
• I think, the LyX experts will know some solution to this, but you will need the `listings` package for highlighting in the document itself. – user31729 Mar 6 '15 at 12:26
• @SoundsOfSilence LyX is not really a LaTeX code editor. Insert --> Program listings uses the `listings` package, so it's just a matter of setting it up correctly in Document --> Settings --> Listings. – Torbjørn T. Mar 6 '15 at 12:29
• @TorbjørnT. You know more of it, definitely. I never used LyX – user31729 Mar 6 '15 at 12:29

I assume you need highlighted code in the PDF. When you do Insert --> Program listing, or if you insert a child document as a Program listing, it is the features of the `listings` package that is used. The look of all listings in a document can be modified under Document --> Settings --> Listings, where you can add any of the `<key>=<value>` pairs listed in the manual.

For example, to specify that the language is C, add `language=C`, to say that comments should be italic and yellow, add `commentstyle=\color{yellow}\itshape`, and so on. Again, the manual is the reference. (I've never really used it much myself.)

``````language=C,keywordstyle=\color{blue},
emphstyle=\color{red},
breaklines,
basicstyle=\ttfamily,
stringstyle=\color{green},
identifierstyle=\color{cyan}
``````

to the settings, this hello world from Wikipedia (with an added comment) turns out as shown below:

``````#include <stdio.h>

// comment!

int main(void)
{
printf("hello, world\n");
}
``````