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!
Post a Comment