comparison testing/utp_1.1/report/mcode.sty @ 44:409a22968d5e default

Add unit tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 18:42:11 +0100
parents
children
comparison
equal deleted inserted replaced
43:bc767aaa99a8 44:409a22968d5e
1 %%
2 %% This is file `mcode.sty'
3 %%
4 %% It is supposed to help you easily include MATLAB source code
5 %% into LaTeX document, but have it nicely highlighted, unsing
6 %% the great listings package.
7 %%
8 %% Usage: Include your MATLAB source code by using
9 %%
10 %% \begin{lstlisting}
11 %% YOUR CODE HERE
12 %% \end{lstlisting}
13 %%
14 %% or as an inline object via \mcode{YOURCODE}.
15 %%
16 %% For your convenience, this package has the following options:
17 %%
18 %% - bw if you intend to print the document (highlighting done
19 %% via text formatting (bold, italic) and shades of gray)
20 %%
21 %% - numbered if you want line numbers
22 %%
23 %% - framed if you want a frame around the source code blocks
24 %%
25 %% - final if you have ``gloablly'' set the draft option, the
26 %% listings package will not output the code at all. to
27 %% force it to do so anyway, load this package with the
28 %% final option (passes the ``final'' on to listings).
29 %%
30 %% Example of use: \usepackage[numbered,framed]{mcode}
31 %% in your document preamble.
32 %%
33 %% Note: inside code blocks you can 'escape' to LaTeX math mode
34 %% by using § YOUR LATEX CODE §, which is especially useful in
35 %% comments...
36 %%
37 %% Another feature of the listings package is that you can re-
38 %% place certain strings by LaTeX strings; this is used for
39 %% some relation symbols, see below...
40 %%
41 %% Mat Odijk pointed this out, you may include entire m-files
42 %% using the command \lstinputlisting{YOUR-FILE.m}. Thanks for
43 %% the tip!
44 %%
45 %% Feel free to edit things, and refer to the listings package
46 %% documentation for more infos.
47 %%
48 %% If you have any questions, feel free to ask: floz@gmx.de
49 %%
50 %% Usolved problem: long lines of code that are wrapped with
51 %% '...', and things thereafter being comments.....
52 %% but i'm working on it ;-)
53 %%
54 %% Author: Florian Knorn, floz@gmx.de
55 %%
56 %% Version history:
57 %% 1.2 -- Added \lstset{showstringspaces=false}
58 %% 1.1 -- Added \mcode command and [final] option
59 %% 1.0 -- Release
60
61 \def\fileversion{1.2}
62 \def\filedate{2005/11/17}
63
64 \typeout{Package: `mcode' \fileversion\space <\filedate>}
65 \NeedsTeXFormat{LaTeX2e}
66 \ProvidesPackage{mcode}[\filedate\space\fileversion]
67
68 % for bw-option
69 \newif\ifbw
70 \DeclareOption{bw}{\bwtrue}
71 \ifbw\typeout{mcode: settings optimized for printing!}
72 \else\typeout{mcode: settings optimized for display!}\fi
73
74 % numbered option
75 \newif\ifnumbered
76 \DeclareOption{numbered}{\numberedtrue}
77
78 % final option
79 \newif\iffinal
80 \DeclareOption{final}{\finaltrue}
81
82 % for framed option
83 \newif\ifframed
84 \DeclareOption{framed}{\framedtrue}
85
86 \DeclareOption*{% default
87 \PackageWarning{mcode}{Unknown option `\CurrentOption' !}%
88 }
89 \ProcessOptions
90
91 % with this command, you can typeset syntax highlighted mcode ``inline'',
92 % for example when you talk about \mcode{for}--loops ...
93 \newcommand{\mcode}[1]{\lstinline[basicstyle=\lstbasicfont]|#1|}
94
95 % check if color command exists
96 \ifx\color\undefined%
97 \RequirePackage{color}%
98 \fi
99
100 % check if listings has been loaded
101 \ifx\lstset\undefined%
102 \iffinal
103 \RequirePackage[final]{listings}
104 \else
105 \RequirePackage{listings}
106 \fi
107 \fi
108
109 % check if textcomp has been loaded (this package is needed
110 % for upright quotes '' (instead of typographic ones `´)...
111 \ifx\textasciigrave\undefined%
112 \RequirePackage{textcomp}%
113 \fi
114
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 % C O N F I G S --- C U S T O M I Z E H E R E %
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118
119 % define the wanted font for all highlightings here
120 \def\lstbasicfont{\fontfamily{pcr}\selectfont}
121
122 % now let's define our own version of matlab highlighting
123 \lstdefinelanguage{matlabfloz}{%
124 alsoletter={...},%
125 morekeywords={% % keywords
126 break,case,catch,continue,elseif,else,end,for,function,global,%
127 if,otherwise,persistent,return,switch,try,while,...},%
128 comment=[l]\%,% % comments
129 morecomment=[l]...,% % comments
130 morestring=[m]',% % strings
131 }[keywords,comments,strings]%
132
133
134 \ifbw % use font formating and gray 'colors'
135 \lstset{language=matlabfloz, % use our version of highlighting
136 keywordstyle=\bfseries, % keywords in bold
137 commentstyle=\color[gray]{0.6}\itshape, % comments light gray and italic
138 stringstyle=\color[gray]{0.5} % strings darker gray
139 }
140 \else% notbw => use colors : )
141 \lstset{language=matlabfloz, % use our version of highlighting
142 keywordstyle=\color[rgb]{0,0,1}, % keywords
143 commentstyle=\color[rgb]{0.133,0.545,0.133}, % comments
144 stringstyle=\color[rgb]{0.627,0.126,0.941} % strings
145 }
146 \fi%bw
147
148 \lstset{%
149 basicstyle={\lstbasicfont\footnotesize}, % use font and smaller size
150 showstringspaces=false, % do not emphasize spaces in strings
151 tabsize=4, % number of spaces of a TAB
152 mathescape=true,escapechar=§, % escape to latex with §...§
153 upquote=true, % upright quotes
154 aboveskip={1.5\baselineskip}, % a bit of space above
155 columns=fixed, % nice spacing
156 %
157 % the following is for replacing some matlab relations like >= or ~=
158 % by the corresponding LaTeX symbols, which are much easier to read ...
159 literate=%
160 {~}{{$\neg$}}1 % \neg
161 {<=}{{\tiny$\leq$}}1 % \leq
162 {>=}{{\tiny$\geq$}}1 % \geq
163 {~=}{{\tiny$\neq$}}1 % \neq
164 {delta}{{\tiny$\Delta$}}1% \Delta
165 }
166
167 \ifnumbered% numbered option
168 \lstset{%
169 numbersep=3mm, numbers=left, numberstyle=\tiny, % number style
170 }
171 \fi
172
173 \ifframed% framed option
174 \lstset{%
175 frame=single, % frame
176 }
177 \ifnumbered%
178 \lstset{%
179 framexleftmargin=6mm, xleftmargin=6mm % tweak margins
180 }
181 \fi
182 \fi
183
184 \endinput
185 %% End of file `mcode.sty'.