我想知道一个应该如何使用胶乳的listings包格式化目标C代码?我知道的语言支持C(目的),让我怎么设置这个在\lstset language选项?

由于

有帮助吗?

解决方案

像这样:

\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}

详细介绍: http://mirror.hmc.edu /ctan/macros/latex/contrib/listings/listings.pdf

其他提示

虽然这个答案没有回答OP的问题的本身的,我想别人找Objective-C的listings相关信息过这个问题会跌倒。

下面是Objective-C的2.0,GNU99,和ANSI C99一listings \lstdefinelanguage。虽然listings包括用于C和Objective-C的定义,这些定义是对于上了年纪C89标准和Objective-C 1.0。下面的版本增加C99,添加GNU99至C99,然后将目标C(2.0)至GNU99。

你可能只是去看看差别,如果你使用的字体样式的关键字,它比“正常”的字体样式不同。

我下面的代码(除ANSI C99定义,将其从listings ANSI C衍生的或修改后用于ANSI C99)的作者。您可以使用它,你希望的任何方式,包括将其合并到其他作品,没有归属或赔偿。我在此将其放置在公共领域。 (注:这主要是为那些谁雇主谁是真正挑剔这样的事情的工作,我真的不在乎的)

\lstdefinelanguage[Objective]{C}[GNU99]{C}
  {morekeywords={@catch,@class,@encode,@end,@finally,@implementation,%
      @interface,@private,@protected,@protocol,@public,@selector,%
      @synchronized,@throw,@try,BOOL,Class,IMP,NO,Nil,SEL,YES,_cmd,%
      bycopy,byref,id,in,inout,nil,oneway,out,self,super,%
      % The next two lines are Objective-C 2 keywords.
      @dynamic,@package,@property,@synthesize,readwrite,readonly,%
      assign,retain,copy,nonatomic%
      },%
   moredirectives={import}%
  }%

\lstdefinelanguage[GNU99]{C}[99]{C}
  {morekeywords={asm,__asm__,__extension__,typeof,__typeof__}%
  }%

\lstdefinelanguage[99]{C}%
  {morekeywords={_Bool,_Complex,_Imaginary,auto,break,case,char,%
      const,continue,default,do,double,else,enum,extern,float,for,%
      goto,if,inline,int,long,register,restrict,return,short,signed,%
      sizeof,static,struct,switch,typedef,union,unsigned,void,volatile,%
      while},%
   sensitive,%
   morecomment=[s]{/*}{*/},%
   morecomment=[l]//,%
   morestring=[b]",%
   morestring=[b]',%
   moredelim=*[directive]\#,%
   moredirectives={define,elif,else,endif,error,if,ifdef,ifndef,line,%
      include,pragma,undef,warning}%
  }[keywords,comments,strings,directives]%
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top