Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I intend to use the package listings for including C# code in a LaTeX document. There are a lot of languages supported by this package, but C# lacks at all. Is there an extension for adding support for this language? or where should I add the C# (ver 4.0) keywords to see them highlighted? Note that the support for Java/C++ does not suffice, as there are some keywords not introduced in these languages: ref, out, var etc.

share|improve this question

1 Answer 1

up vote 12 down vote accepted

The listings package supports it (see the manual, page 12). Your document could look something like this:

\documentclass{scrartcl}
\usepackage{listings}
\usepackage{xcolor}

\lstdefinestyle{sharpc}{language=[Sharp]C, frame=lr, rulecolor=\color{blue!80!black}}

\begin{document}

\lstset{style=sharpc}
\begin{lstlisting}
Your c# code here
\end{lstlisting}

\end{document}

As I don't know C#, I also don't know if the language definition of listings is sufficient for you, but it offers morekeywords key, so you can add the ones you are missing

share|improve this answer
    
Is it possible to get this in LyX? Because I don't see SharpC in the list of available languages. –  Dmitri Nesteruk Apr 27 '12 at 14:45
2  
@DmitriNesteruk You find it on page 12 of the manual. And it's [Sharp]C, which means use language C, the dialect Sharp. Without this listings would choose the standard dialect (ANSI in this case, therefore it is underlined in the manual). Although I don't use Lyx, I don't see any reason for it not to work. –  Tom Bombadil Apr 27 '12 at 16:24
2  
Thanks! Though I must admit this is beyond unintuitive... who on earth came up with that idea? C# as a dialect of C, pah! Ridiculous! –  Dmitri Nesteruk Apr 28 '12 at 7:41

Your Answer

 
discard

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.