tags:

views:

349

answers:

1

I am wondering how one is supposed to format Objective C code using the listings package of LaTeX? I know that the language supports C (Objective) , so how do i set this in the \lstset language option?

Thanks

+3  A: 

Like this:

\documentclass{article}

\usepackage{listings}

\begin{document}

\lstset{language=[Objective]C, breakindent=40pt, breaklines}

\begin{lstlisting}
@interface classname : superclassname {
    // instance variables
}
+classMethod1;
+(return_type)classMethod2;
+(return_type)classMethod3:(param1_type)param1_varName;

-(return_type)instanceMethod1:(param1_type)param1_varName :(param2_type)param2_varName;
-(return_type)instanceMethod2WithParameter:(param1_type)param1_varName andOtherParameter:(param2_type)param2_varName;
@end
\end{lstlisting}

\end{document}

Detailed introduction: http://mirror.hmc.edu/ctan/macros/latex/contrib/listings/listings.pdf

Bart Kiers
That's for C. For Objective C, you'd want to use `\lstset{language=[Objective]C}`.
Joachim Sauer
thanks - i have a problem though, my source is quite long, and is going off the width of the page - Overfull problems, can this be solved? thanks
joec
@Joachim, I've never used Objective C and since joec put it between parenthesis, I guessed the languages didn't differ that much. I was wrong! :). Grabbed some Objective C from the net and fixed my example. Thanks.
Bart Kiers
@joec, it appears you didn't look into the link I posted (or too briefly). The breaking of lines is explained in `4.10 Margins and line shape`. I adjusted my example. Next time please first read what is already suggested. Thanks.
Bart Kiers