|
| 1 | +%% |
| 2 | +%% Syntax-Highlight-File `dtsyntax.sty' :: D.Töpel |
| 3 | +%% _______________________________________________________________ |
| 4 | +%% | |
| 5 | +%% | Aufrufmöglichkeiten im Dokument : |
| 6 | +%% | |
| 7 | +%% | \begin[language=mcode|modelica|pearl|vhdl]{lstlisting} |
| 8 | +%% | Syntax - Code |
| 9 | +%% | \end{lstlisting} |
| 10 | +%% | |
| 11 | +%% | ** oder ** |
| 12 | +%% | |
| 13 | +%% | \mcode|modelica|pearl|vhdl{Syntax - Code} |
| 14 | +%% | |
| 15 | +%% | ** oder ** |
| 16 | +%% | |
| 17 | +%% | \lstinputlisting[language=mcode|modelica|pearl|vhdl]{YOUR-FILE.*} |
| 18 | +%% |_______________________________________________________________ |
| 19 | +%% |
| 20 | +%% For your convenience, this package has the following options: |
| 21 | +%% |
| 22 | +%% - bw |> Ausgabe in Schwarz, dafür Highlight in Fett |
| 23 | +%% und Kursiv |
| 24 | +%% |
| 25 | +%% - numbered |> Angabe von Zeilennummern |
| 26 | +%% |
| 27 | +%% - framed |> Rahmen um den Code Block |
| 28 | +%% |
| 29 | +%% - final |> bitte selbst übersetzen ... |
| 30 | +%% if you have ``gloablly'' set the draft option, the |
| 31 | +%% listings package will not output the code at all. to |
| 32 | +%% force it to do so anyway, load this package with the |
| 33 | +%% final option (passes the ``final'' on to listings). |
| 34 | +%% |
| 35 | +%% Beispiel: \usepackage[numbered,framed]{dtsyntax} |
| 36 | +%% im Dokumentenkopf. |
| 37 | +%% ________________________________________________________________ |
| 38 | +%% |
| 39 | +%% Grundlage dieses Style-Files ist die mcode.sty Datei, mit deren |
| 40 | +%% Hilfe ein Syntax-Highlight für Matlab möglich ist. |
| 41 | +%% |
| 42 | +%% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8015&objectType=File |
| 43 | +%% |
| 44 | +%% http://www.mathworks.com/matlabcentral/files/8015/mcode.sty |
| 45 | + |
| 46 | +\def\fileversion{1.01} |
| 47 | +\def\filedate{2009/09/24} |
| 48 | + |
| 49 | +\typeout{Package: `dtsyntax' \fileversion\space <\filedate>} |
| 50 | +\NeedsTeXFormat{LaTeX2e} |
| 51 | +\ProvidesPackage{dtsyntax}[\filedate\space\fileversion] |
| 52 | + |
| 53 | +% for bw-option |
| 54 | +\newif\ifbw |
| 55 | +\DeclareOption{bw}{\bwtrue} |
| 56 | +\ifbw\typeout{dtsyntax: settings optimized for printing!} |
| 57 | +\else\typeout{dtsyntax: settings optimized for display!}\fi |
| 58 | + |
| 59 | +% numbered option |
| 60 | +\newif\ifnumbered |
| 61 | +\DeclareOption{numbered}{\numberedtrue} |
| 62 | + |
| 63 | +% final option |
| 64 | +\newif\iffinal |
| 65 | +\DeclareOption{final}{\finaltrue} |
| 66 | + |
| 67 | +% for framed option |
| 68 | +\newif\ifframed |
| 69 | +\DeclareOption{framed}{\framedtrue} |
| 70 | + |
| 71 | +\DeclareOption*{% default |
| 72 | + \PackageWarning{dtsyntax}{Unknown option `\CurrentOption' !}% |
| 73 | +} |
| 74 | +\ProcessOptions |
| 75 | + |
| 76 | +% check if color command exists |
| 77 | +\ifx\color\undefined% |
| 78 | + \RequirePackage{color}% |
| 79 | +\fi |
| 80 | + |
| 81 | +\definecolor{lightblue}{rgb}{.3,.5,1} |
| 82 | +\definecolor{orange}{rgb}{1,.7,0} |
| 83 | +\definecolor{darkorange}{rgb}{1,.4,0} |
| 84 | +\definecolor{darkgreen}{rgb}{0,.4,0} |
| 85 | +\definecolor{gray}{rgb}{.3,.3,.3} |
| 86 | + |
| 87 | +\definecolor{blue}{rgb}{0,0,1} |
| 88 | +\definecolor{red}{rgb}{1,0,0} |
| 89 | +\definecolor{pink}{rgb}{.933,0,.933} |
| 90 | +\definecolor{green}{rgb}{0.133,0.545,0.133} |
| 91 | +\definecolor{darkblue}{rgb}{0,0,.4} |
| 92 | +\definecolor{darkred}{rgb}{.56,0,0} |
| 93 | +\definecolor{darkgray}{rgb}{.2,.2,.2} |
| 94 | +\definecolor{shadecolor}{gray}{0.925} |
| 95 | + |
| 96 | + |
| 97 | +% check if listings has been loaded |
| 98 | +\ifx\lstset\undefined% |
| 99 | + \iffinal |
| 100 | + \RequirePackage[final]{listings} |
| 101 | + \else |
| 102 | + \RequirePackage{listings} |
| 103 | + \fi |
| 104 | +\fi |
| 105 | + |
| 106 | +% check if textcomp has been loaded (this package is needed |
| 107 | +% for upright quotes '' (instead of typographic ones `´)... |
| 108 | +\ifx\textasciigrave\undefined% |
| 109 | + \RequirePackage{textcomp}% |
| 110 | +\fi |
| 111 | + |
| 112 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 113 | +% C O N F I G S --- C U S T O M I Z E H E R E % |
| 114 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 115 | + |
| 116 | + |
| 117 | +% ********************************************************************************** |
| 118 | +% Syntax : Matlab (mcode) * |
| 119 | +% ********************************************************************************** |
| 120 | +\lstdefinelanguage{mcode}{% |
| 121 | + otherkeywords={...},%alsoletter |
| 122 | + morekeywords=[1]{% |
| 123 | + break,case,catch,continue,elseif,else,end,for,function,global,% |
| 124 | + if,otherwise,persistent,return,switch,try,while,...},% |
| 125 | + comment=[l]\%,% % comments |
| 126 | + morecomment=[l][{\color{green}\bfseries}]{\%\%},% % comments keywordstyle |
| 127 | + morecomment=[l]...,% % comments |
| 128 | + morestring=[m]',% % strings |
| 129 | +}[keywords,comments,strings]% |
| 130 | + |
| 131 | + |
| 132 | +% ********************************************************************************** |
| 133 | +% Syntax : Modelica (modelica) * |
| 134 | +% ********************************************************************************** |
| 135 | +\lstdefinelanguage{modelica}{% |
| 136 | + alsoletter={...},% |
| 137 | + otherkeywords={-, =, +, [, ], (, ), \{, \}, :, *, !},% |
| 138 | + morekeywords=[1]{},%otherkeywords= |
| 139 | + morekeywords=[2]{% % keywords |
| 140 | + annotation,assert,block,class,connector,constant,discrete,% |
| 141 | + else,elseif,elsewhen,end,exit,extends,external,final,flow,for,% |
| 142 | + function,if,in,inner,input,import,loop,model,nondiscrete,outer,% |
| 143 | + output,package,parameter,record,redeclare,replaceable,return,% |
| 144 | + size,terminate,then,type,when,while,algorithm,equation,% |
| 145 | + protected,public,and,false,not,or,true},% |
| 146 | + morekeywords=[3]{% functions % keywords |
| 147 | + abs,acos,asin,atan,atan2,connect,cos,cosh,cross,der,edge,exp,% |
| 148 | + initial,noEvent,pre,reinit,sample,sign,sin,sinh,tan,tanh,terminal,Real},% |
| 149 | + comment=[l]//,% % comments |
| 150 | + morecomment=[s]{/*}{*/},% % comments |
| 151 | + morestring=[b]',% % strings |
| 152 | + morestring=[b]",% |
| 153 | +}[keywords,comments,strings]% |
| 154 | + |
| 155 | + |
| 156 | +% ********************************************************************************** |
| 157 | +% Syntax : Pearl (pearl) * |
| 158 | +% ********************************************************************************** |
| 159 | +\lstdefinelanguage{pearl}{% |
| 160 | + alsoletter={...},% |
| 161 | + morekeywords=[1]{% % keywords |
| 162 | + ACTIVATE,AFTER,ALL,ALPHIC,ALT,AND,AT,BASIC,BEGIN,BIT,BOLT,BY,CALL,CASE,CHAR,% |
| 163 | + CHARACTER,CLOCK,CLOSE,CONT,CONTINUE,CONTROL,CONVERT,CREATED,CYCLIC,DATION,DECLARE,DCL,% |
| 164 | + DIM,DIRECT,DISABLE,DUR,DURATION,DURING,ELSE,ENABLE,END,ENTER,EXIT,FIN,FIXED,FLOAT,FOR,% |
| 165 | + FORBACK,FORMAT,FORWARD,FREE,FROM,GET,GLOBAL,GOTO,HRS,IDENT,IDENTICAL,IF,IN,INDUCE,INIT,% |
| 166 | + INITIAL,INOUT,INTERRUPT,INV,IRPT,LEAVE,LENGTH,MAIN,MAX,MIN,MODEND,MODULE,NIL,NOCYCL,NOSTREAM,% |
| 167 | + ON,OPEN,OPERATOR,OUT,PRECEDENCE,PRESET,PREVENT,PRIO,PRIORITY,PROBLEM,PROC,PROCEDURE,PUT,READ,% |
| 168 | + REF,RELEASE,REPEAT,REQUEST,RESERVE,RESUME,RETURN,RETURNS,SEC,SEMA,SEND,SIGNAL,SPC,SPECIFY,% |
| 169 | + STREAM,STRUCT,SUSPEND,SYSTEM,TAKE,TASK,TERMINATE,TFU,THEN,TO,TRIGGER,TYPE,UNTIL,WHEN,WHILE,WRITE,% |
| 170 | + ABS,ADV,AND,ANY,ATAN,CAN,CAT,CONT,COS,CSHIFT,DATE,ENTIER,EQ,EXOR,EXP,FIT,GE,GT,IDF,IS,ISNT,% |
| 171 | + LE,LINE,LIST,LN,LT,LWB,NE,NEW,NOT,NOW,OLD,OR,PAGE,POS,PRM,REM,ROUND,RST,SHIFT,SIGN,SIN,SIZEOF,% |
| 172 | + SKIP,SOP,SQRT,TAN,TANH,TOBIT,TOCHAR,TOFIXED,TOFLOAT,TRY,UPB},% |
| 173 | + comment=[l]!,% % comments |
| 174 | + morecomment=[s]{/*}{*/},% % comments |
| 175 | + morestring=[m]',% % strings |
| 176 | +}[keywords,comments,strings]% |
| 177 | + |
| 178 | + |
| 179 | +% ********************************************************************************** |
| 180 | +% Syntax : VHDL (vhdl) * |
| 181 | +% ********************************************************************************** |
| 182 | +\lstdefinelanguage{vhdl}{% |
| 183 | + morekeywords=[1]{% % keywords |
| 184 | + abs,access,after,all,and,architecture,array,assert,attribute,begin,block,body,buffer,bus, |
| 185 | + case,component,configuration,disconnect,downto,else,elsif,end,entity,exit,file,for,function, |
| 186 | + generate,generic,group,guarded,if,impure,in,inertial,inout,is,label,library,linkage,literal,loop, |
| 187 | + map,mod,nand,new,next,nor,not,null,of,on,open,or,others,out,package,port,postponed,procedure, |
| 188 | + process,pure,range,record,register,reject,rem,report,return,rol,ror,select,severity,shared,sla,sll, |
| 189 | + sra,srl,then,to,transport,unaffected,units,until,use,,wait,when,while,with,xnor,xor,ActivPullUp, |
| 190 | + AndN,And2FF,AndNFF,Cnt1Bit,CntNBit,CntNBitDown,CntNBitMod,CntNBitOe,CntNBitSLd,CntNBitSR, |
| 191 | + CntNBitUpDown,CompNBit,CompNBitFF,DiffH2LWithFF,DiffL2HWithFF,Dff1,Dff1NegClk,Dffn,Encode4to5, |
| 192 | + Mux1of2,Mux1of8,Mux1Vof2V,Mux1Vof3V,Mux1Vof4V,PreScale1Bit,PreScale1BitAR,PreScale1BitARNegClk, |
| 193 | + PreScaleNBit,PreScaleNBitAR,Reg1Bit,Reg1BitAR,Reg1BitR,RegNBit,RegNBitAR,RSFFAsync,RSFFsync, |
| 194 | + RsSynchronizer,ShiftP2SRegNBitAR,ShiftRegNBitAR,ShiftS2SRegNBit,SRFFsync,SyncAndDiffL2HWithFF, |
| 195 | + SyncAndDiffH2LWithFF,SyncAndDiffL2HWithFFAndFg,SyncAndDiffH2LWithFFAndFg,SyncAndDiffLL2HHWithFF, |
| 196 | + SyncAndDiffHH2LLWithFF,SyncAndDiffLL2HHWithFFAndFg,SyncAndDiffHH2LLWithFFAndFg,ActivPullUp\_arch, |
| 197 | + AndN\_arch,And2FF\_arch,AndNFF\_arch,Cnt1Bit\_arch,CntNBit\_arch,CntNBitDown\_arch,CntNBitMod\_arch, |
| 198 | + CntNBitOe\_arch,CntNBitSLd\_arch,CntNBitSR\_arch,CntNBitUpDown\_arch,CompNBit\_arch,CompNBitFF\_arch, |
| 199 | + DiffH2LWithFF\_arch,DiffL2HWithFF\_arch,Dff1\_arch,Dff1NegClk\_arch,Dffn\_arch,Encode4to5\_arch, |
| 200 | + Mux1of2\_arch,Mux1of8\_arch,Mux1Vof2V\_arch,Mux1Vof3V\_arch,Mux1Vof4V\_arch,PreScale1Bit\_arch, |
| 201 | + PreScale1BitAR\_arch,PreScale1BitARNegClk\_arch,PreScaleNBit\_arch,PreScaleNBitAR\_arch,Reg1Bit\_arch, |
| 202 | + Reg1BitAR\_arch,Reg1BitR\_arch,RegNBit\_arch,RegNBitAR\_arch,RSFFAsync\_arch,RSFFsync\_arch, |
| 203 | + RsSynchronizer\_arch,ShiftP2SRegNBitAR\_arch,ShiftRegNBitAR\_arch,ShiftS2SRegNBit\_arch,SRFFsync\_arch, |
| 204 | + SyncAndDiffL2HWithFF\_arch,SyncAndDiffH2LWithFF\_arch,SyncAndDiffL2HWithFFAndFg\_arch, |
| 205 | + SyncAndDiffH2LWithFFAndFg\_arch,SyncAndDiffLL2HHWithFF\_arch,SyncAndDiffHH2LLWithFF\_arch, |
| 206 | + SyncAndDiffLL2HHWithFFAndFg\_arch,SyncAndDiffHH2LLWithFFAndFg\_arch, |
| 207 | + % |
| 208 | + alias,constant,type,variable,signal,subtype},% |
| 209 | + morekeywords=[4]{% color -> pink |
| 210 | + bit,bit\_vector,boolean,integer,real,std\_logic,std\_logic\_vector,time,character,string, |
| 211 | + IEEE,std_logic_1164,std_logic_textio,numeric_bit,numeric_std,std_logic_unsigned,math_real, |
| 212 | + std_logic_arith,std,textio,CONV\_INTEGER,CONV\_STD\_LOGIC\_VECTOR},% |
| 213 | + morekeywords=[5]{event,value},% |
| 214 | + comment=[l]{--},% % comments |
| 215 | + morestring=[m][\color{darkred}]',% % strings |
| 216 | + morestring=[m][\color{darkred}]",% |
| 217 | + alsoother={.},%otherkeywords |
| 218 | + sensitive=false |
| 219 | +}[keywords,comments,strings]% |
| 220 | + |
| 221 | + |
| 222 | +\ifbw % use font formating and gray 'colors' |
| 223 | + \lstset{ |
| 224 | + keywordstyle=\bfseries, % keywords in bold |
| 225 | + commentstyle=\color[gray]{0.6}\itshape, % comments light gray and italic |
| 226 | + stringstyle=\color[gray]{0.5} % strings darker gray |
| 227 | + } |
| 228 | +\else% notbw => use colors : ) |
| 229 | + \lstset{ |
| 230 | + backgroundcolor=\color{shadecolor}, |
| 231 | + keywordstyle=[1]\color{blue}, % keywords |
| 232 | + keywordstyle=[2]\color{blue}\bfseries, % keywords |
| 233 | + keywordstyle=[3]\color{red}, % keywords |
| 234 | + keywordstyle=[4]\color{pink}, % keywords |
| 235 | + keywordstyle=[5]\color{darkblue}\bfseries, % keywords |
| 236 | + commentstyle=\color{green}, % comments |
| 237 | + stringstyle=\color{red} % strings |
| 238 | + } |
| 239 | +\fi%bw |
| 240 | + |
| 241 | +\lstset{% |
| 242 | + basicstyle={\ttfamily\footnotesize}, % use font and smaller size \small \footnotesize |
| 243 | + showstringspaces=false, % do not emphasize spaces in strings |
| 244 | + tabsize=4, % number of spaces of a TAB |
| 245 | + mathescape=false,%escapechar=§, % escape to latex with §...§ |
| 246 | + upquote=true, % upright quotes |
| 247 | + aboveskip={1.5\baselineskip}, % a bit of space above |
| 248 | + columns=fixed, % nice spacing -> fixed / flexible |
| 249 | + texcl=false% |
| 250 | +} |
| 251 | + |
| 252 | +\ifnumbered% numbered option |
| 253 | + \lstset{% |
| 254 | + numbersep=1mm, numbers=left, numberstyle=\tiny, % number style |
| 255 | + } |
| 256 | +\fi |
| 257 | + |
| 258 | +\ifframed% framed option |
| 259 | + \lstset{% |
| 260 | + %basicstyle={\ttfamily\footnotesize}, |
| 261 | + frame=leftline,% single, % frame |
| 262 | + framerule=3pt, |
| 263 | + framexleftmargin=2pt, |
| 264 | + %xleftmargin=1cm, |
| 265 | + } |
| 266 | + \ifnumbered% |
| 267 | + \lstset{% |
| 268 | + numbersep=-5mm, % tweak margins |
| 269 | + } |
| 270 | + \fi |
| 271 | +\fi |
| 272 | + |
| 273 | + |
| 274 | +% with this command, you can typeset syntax highlighted code ``inline'', |
| 275 | +% for example when you talk about \pearl{for}--loops ... |
| 276 | +\newcommand{\mcode}[1]{\lstinline[basicstyle=\ttfamily,language=mcode]|#1|} |
| 277 | +\newcommand{\modelica}[1]{\lstinline[basicstyle=\ttfamily,language=modelica]|#1|} |
| 278 | +\newcommand{\pearl}[1]{\lstinline[basicstyle=\ttfamily,language=pearl]|#1|} |
| 279 | +\newcommand{\vhdl}[1]{\lstinline[basicstyle=\ttfamily,language=vhdl]|#1|} |
| 280 | + |
| 281 | +\endinput |
| 282 | +%% End of file `dtsyntax.sty'. |
0 commit comments