Friday, January 27, 2006

A Simple Latex Listings Definition for C#

I'm thinking of moving my tutorials into pdf format. I couldn't find a nice formatter for C# code in Latex so I wrote this definition in Listings. (I find Latex's mascot to be a little disturbing.)


\lstdefinelanguage{CSharp}
{
morecomment = [l]{//},
morecomment = [l]{///},
morecomment = [s]{/*}{*/},
morestring=[b]",
sensitive = true,
morekeywords = {abstract, event, new, struct,
as, explicit, null, switch,
base, extern, object, this,
bool, false, operator, throw,
break, finally, out, true,
byte, fixed, override, try,
case, float, params, typeof,
catch, for, private, uint,
char, foreach, protected, ulong,
checked, goto, public, unchecked,
class, if, readonly, unsafe,
const, implicit, ref, ushort,
continue, in, return, using,
decimal, int, sbyte, virtual,
default, interface, sealed, volatile,
delegate, internal, short, void,
do, is, sizeof, while,
double, lock, stackalloc,
else, long, static,
enum, namespace, string}
}


As I said pretty simple. Also look all those keywords! I'm embarrased to say I don't know some of them! Volatile? What's that? And stackalloc? I'll have to do some reading!

2 comments:

Anonymous said...

Hey Daniel, thanks for posting that code. I'm writing a PhD thesis in LaTex and using C# code. Cheers!

Nick
(Aust. PhD Student, Uni Melbourne)

Unknown said...

You forgot LINQ keywords. Technically part of C# as well:

http://msdn.microsoft.com/en-us/library/bb310804.aspx

Some more new keywords for you to look up! :)

Otherwise, nice work. I'm using it for my report!