GeneralCreating a line break in a code sample

LaTeX specific issues not fitting into one of the other forums of this category.
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Re: Creating a line break in a code sample

Post by tripwire45 »

Just when you thought it was safe to ignore this thread and move on... :mrgreen:

I've been reviewing the list of supported languages by listings in the documentation, and notice that C# isn't listed. How critical an issue is this? I've used both the \lstset{language=C} and \lstset{language=VBScript} tags and compiled the document as a PDF and can't see any difference in presentation.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Re: Creating a line break in a code sample

Post by tripwire45 »

:bump:

Any ideas?
Ted
Posts: 94
Joined: Sat Jun 23, 2007 4:11 pm

Creating a line break in a code sample

Post by Ted »

tripwire45 wrote:Any ideas?
It's not a big deal. It's easy to augment the language definition within your TeX to add any words you use that are missing. For example...

Code: Select all

\lstset{language=Matlab,
    morekeywords={xlim,ylim,var,alpha,factorial,poissrnd,normpdf,normcdf,getfield},
    morekeywords=[2]{on, off, interp},
    morekeywords=[3]{my_function},
    morecomment=[l][\color{blue}]{...}}
The first morekeywords line adds MATLAB functions not included in the default set. The second line includes MATLAB function parameters. The third line has user-defined functions. The morecomment turns text after line continuation (...) into a comment. Each line gets styled differently (and you can change those styles in a similar way).

See the listings documentation for more information. In particular, check out the "Language definitions" section 3.2 for information on how to use morekeywords, morecomment, and morestring. Of course, you can define your own new language entirely as well.

In the case of C#, nearly everything is going to be the same as C++ (or even Java), but there might be small differences. For example, C# has its own way of handling mutable class members (the keyword they use escapes me for a second). If you need such a construct, you can add it pretty easily.

And if worse comes to worst, everything is displayed but it's just not displayed as pretty as it could.
Last edited by Ted on Fri Aug 01, 2008 4:30 pm, edited 3 times in total.
-- Ted [home/blog]
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Re: Creating a line break in a code sample

Post by tripwire45 »

Cheers for that, Ted. Thanks. :)

-Trip
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

Creating a line break in a code sample

Post by T3. »

Trip,

I've just seen mentioned in another thread that somebody wrote a listing environment for C#. I thought it might interest you.

Cheers,

Tomek
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Re: Creating a line break in a code sample

Post by tripwire45 »

Great catch, Tomek. Thanks for letting me know. :)
Post Reply