\documentclass[a4paper,10pt]{article}
    \usepackage{alltt}
    \usepackage{color}
    \usepackage{fullpage}
    \definecolor{string}{rgb}{0.7,0.0,0.0}
    \definecolor{comment}{rgb}{0.13,0.54,0.13}
    \definecolor{keyword}{rgb}{0.0,0.0,1.0}
    \title{highlight.m}
    \author{\textsc{Matlab}, The Mathworks, Inc.}
\begin{document}
\maketitle
\begin{alltt}
0001 \textcolor{keyword}{function} highlight(mfile,options,outfile)
0002 \textcolor{comment}{%HIGHLIGHT - Syntax Highlighting of Matlab M-files in HTML, LaTeX, RTF and XML.}
0003 \textcolor{comment}{%  HIGHLIGHT(MFILE) takes an M-file MFILE in input and writes on disk an HTML}
0004 \textcolor{comment}{%  file with the same basename ('foo.m' => 'foo.html') adding colored syntax }
0005 \textcolor{comment}{%  highlighting on comment, string and Matlab keyword elements.}
0006 \textcolor{comment}{%  HIGHLIGHT(MFILE,OPTIONS) with OPTIONS being string 'html', 'xhtml', 'tex', }
0007 \textcolor{comment}{%  'rtf' or 'xml', allows to choose the output format between HTML, XHTML, LaTeX}
0008 \textcolor{comment}{%  RTF or XML. The same rule is used to determine the name of the output file.}
0009 \textcolor{comment}{%  HIGHLIGHT(MFILE,OPTIONS) allows to specify some options in a structure:}
0010 \textcolor{comment}{%     options.type - Output file type }
0011 \textcolor{comment}{%             [ \{'html'\} | 'tex' | 'rtf' | 'xml' | 'xhtml']}
0012 \textcolor{comment}{%     options.tabs - Replace '\(\backslash\)t' in source code by n white space}
0013 \textcolor{comment}{%                           [ 0 ... \{4\}  ... n]}
0014 \textcolor{comment}{%     options.linenb - Display line number in front of each line [ 0 | \{1\} ]}
0015 \textcolor{comment}{%  HIGHLIGHT(MFILE,OPTIONS,OUTFILE) allows to specify the name of the output }
0016 \textcolor{comment}{%  file. OUTFILE can also be a file handle. In that case, no header will be }
0017 \textcolor{comment}{%  written, only the highlighted Matlab code will be sent to the OUTFILE stream.}
0018 
0019 \textcolor{comment}{%  Output file can be customized (font style, font color, font size, ...):}
0020 \textcolor{comment}{%     o HTML: use CSS (Cascading Style Sheets) to define 'comment', 'string', }
0021 \textcolor{comment}{%       'keyword', 'cont' and 'code' SPAN elements and 'mcode' PRE tag.}
0022 \textcolor{comment}{%     o LaTeX: packages 'alltt' and 'color' are required, you can modify colors}
0023 \textcolor{comment}{%       in defining colors 'string', 'comment' and 'keyword' using command}
0024 \textcolor{comment}{%                      \(\backslash\)definecolor\{mycolor\}\{rgb\}\{a,b,c\}}
0025 \textcolor{comment}{%     o RTF: Colors are defined in the Color Table at the beginning of the}
0026 \textcolor{comment}{%       document. See Rich Text Format Specifications for more details:}
0027 \textcolor{comment}{%       <http://msdn.microsoft.com/library/en-us/dnrtfspec/html/rtfspec.asp>}
0028 \textcolor{comment}{%     o XML: you will find the DTD of the resulting XML file in matlab.dtd}
0029 \textcolor{comment}{%       You can then use XSL to transform your XML file in what you want.}
0030 \textcolor{comment}{%       For example, mat2html.xsl transforms your XML file in HTML as it would}
0031 \textcolor{comment}{%       be if you would have used highlight.m to to so.}
0032 \textcolor{comment}{%       On Matlab 6.5, the command is:}
0033 \textcolor{comment}{%               xslt highlight.xml mat2html.xsl highlight.html}
0034 \textcolor{comment}{%       On Linux, using libxslt <http://xmlsoft.org/XSLT/>, the command is: }
0035 \textcolor{comment}{%               xsltproc -o highlight.html mat2html.xsl highlight.xml}
0036 
0037 \textcolor{comment}{%  Copyright (C) 2003 Guillaume Flandin}
0038 \textcolor{comment}{%  \$Revision: 1.1 \$Date: 2003/09/07 15:39:33 \$}
0039 
0040 \textcolor{comment}{%  This program is free software; you can redistribute it and/or}
0041 \textcolor{comment}{%  modify it under the terms of the GNU General Public License}
0042 \textcolor{comment}{%  as published by the Free Software Foundation; either version 2}
0043 \textcolor{comment}{%  of the License, or any later version.}
0044 \textcolor{comment}{% }
0045 \textcolor{comment}{%  This program is distributed in the hope that it will be useful,}
0046 \textcolor{comment}{%  but WITHOUT ANY WARRANTY; without even the implied warranty of}
0047 \textcolor{comment}{%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}
0048 \textcolor{comment}{%  GNU General Public License for more details.}
0049 \textcolor{comment}{% }
0050 \textcolor{comment}{%  You should have received a copy of the GNU General Public License}
0051 \textcolor{comment}{%  along with this program; if not, write to the Free Software}
0052 \textcolor{comment}{%  Foundation Inc, 59 Temple Pl. - Suite 330, Boston, MA 02111-1307, USA.}
0053 
0054 \textcolor{comment}{% Suggestions for improvement and fixes are always welcome, although no}
0055 \textcolor{comment}{% guarantee is made whether and when they will be implemented.}
0057 
0058 \textcolor{comment}{%- Set up options}
0059 error(nargchk(1,3,nargin));
0060 
0061 opt = struct(\textcolor{string}{'type'},   \textcolor{string}{'html'}, \textcolor{keyword}{\underline{...}}
0062              \textcolor{string}{'tabs'},   4, \textcolor{keyword}{\underline{...}}
0063              \textcolor{string}{'linenb'}, 1, \textcolor{keyword}{\underline{...}}
0064              \textcolor{string}{'indent'}, 0);
0065 \textcolor{keyword}{if} nargin >= 2
0066     \textcolor{keyword}{if} isstruct(options)
0067         names = fieldnames(options);
0068         \textcolor{keyword}{for} i=1:length(names)
0069             opt = setfield(opt,names\{i\},getfield(options,names\{i\}));
0070         \textcolor{keyword}{end}
0071     \textcolor{keyword}{elseif} ischar(options)
0072         opt.type = options;
0073     \textcolor{keyword}{else}
0074         error(\textcolor{string}{'Bad input argument.'});
0075     \textcolor{keyword}{end}
0076 \textcolor{keyword}{end}
0077 \textcolor{keyword}{if} strcmp(lower(opt.type),\textcolor{string}{'latex'}), opt.type = \textcolor{string}{'tex'}; \textcolor{keyword}{end}
0078 \textcolor{keyword}{if} strcmp(lower(opt.type),\textcolor{string}{'xml'}), opt.linenb = 1; \textcolor{keyword}{end}
0079 
0080 \textcolor{comment}{%- If no output filename is provided, one is chosen according to mfile}
0081 \textcolor{keyword}{if} nargin < 3
0082     [pathstr, name, ext] = fileparts(mfile);
0083     outfile = fullfile(pathstr, [name, \textcolor{string}{'.'} lower(opt.type)]);
0084 \textcolor{keyword}{end}
0085 
0086 \textcolor{comment}{%- If an output filename is provided, a standard header is created}
0087 \textcolor{keyword}{if} ischar(outfile)
0088     outfid = fopen(outfile,\textcolor{string}{'wt'});
0089     \textcolor{keyword}{if} outfid == -1
0090         error(sprintf(\textcolor{string}{'Cannot open '},outfile));
0091     \textcolor{keyword}{end}
0092     feval([lower(opt.type) \textcolor{string}{'\_file\_start'}],outfid,mfile);
0093 \textcolor{comment}{%- Otherwise a file handle is provided}
0094 \textcolor{keyword}{else}
0095     outfid = outfile;
0096 \textcolor{keyword}{end}
0097 
0098 \textcolor{comment}{%- Open the Matlab mfile to be highlighted}
0099 mfid = fopen(mfile,\textcolor{string}{'rt'});
0100 \textcolor{keyword}{if} mfid == -1
0101     error(sprintf(\textcolor{string}{'Cannot open '},mfile));
0102 \textcolor{keyword}{end}
0103 
0104 \textcolor{comment}{%- Write the syntax highlighted mfile code in the output file}
0105 write\_highlighted\_code(mfid,outfid,opt)
0106 
0107 \textcolor{comment}{%- Close the Matlab mfile and potentially the output file}
0108 fclose(mfid);
0109 \textcolor{keyword}{if} ischar(outfile), 
0110     feval([lower(opt.type) \textcolor{string}{'\_file\_end'}],outfid);
0111     fclose(outfid); 
0112 \textcolor{keyword}{end}
0113 
0114 \textcolor{comment}{%===============================================================================}
0115 \textcolor{keyword}{function} write\_highlighted\_code(mfid,outfid,opt)
0116     matlabKeywords = getMatlabKeywords;
0117     mKeySort       = getMatlabKeywordsSorted;
0118     out\_format     = feval([lower(opt.type) \textcolor{string}{'\_format'}]);
0119     strtok\_delim   = sprintf(\textcolor{string}{' \(\backslash\)t\(\backslash\)n\(\backslash\)r()\{\}[]<>+-*\~{}!|\(\backslash\)\(\backslash\)@\&/.,:;="''\%'});
0120     
0121     fprintf(outfid,out\_format.pre\_start);
0122     nbline = 1;
0123     nbblanks = 0;
0124     flagnextline = 0;
0125     \textcolor{keyword}{while} 1
0126         tline = fgetl(mfid);
0127         \textcolor{keyword}{if} \~{}ischar(tline), \textcolor{keyword}{break}, \textcolor{keyword}{end}
0128         tline = feval([lower(opt.type) \textcolor{string}{'\_special\_char'}],horztab(tline,opt.tabs));
0129         \textcolor{comment}{%- Display the line number at each line}
0130         \textcolor{keyword}{if} opt.linenb
0131             fprintf(outfid,out\_format.nb\_line,nbline);
0132             nbline = nbline + 1;
0133         \textcolor{keyword}{end}
0134         \textcolor{comment}{%- Remove blanks at the beginning of the line}
0135         \textcolor{keyword}{if} opt.indent
0136             tline = fliplr(deblank(fliplr(tline)));
0137         \textcolor{keyword}{end}
0138         nbblanks = nbblanks + flagnextline;
0139         flagnextline = 0;
0140         \textcolor{comment}{%- Split code into meaningful chunks}
0141         splitc = splitcode(tline);
0142         newline = \textcolor{string}{''};
0143         \textcolor{keyword}{for} i=1:length(splitc)
0144             \textcolor{keyword}{if} isempty(splitc\{i\})
0145             \textcolor{keyword}{elseif} splitc\{i\}(1) == \textcolor{string}{''''}
0146                 newline = [newline sprintf(out\_format.string,splitc\{i\})];
0147             \textcolor{keyword}{elseif} splitc\{i\}(1) == \textcolor{string}{'\%'}
0148                 newline = [newline sprintf(out\_format.comment,splitc\{i\})];
0149             \textcolor{keyword}{elseif} \~{}isempty(strmatch(\textcolor{string}{'...'},splitc\{i\}))
0150                 newline = [newline sprintf(out\_format.cont,\textcolor{string}{'...'})];
0151                 \textcolor{keyword}{if} \~{}isempty(splitc\{i\}(4:end))
0152                     newline = [newline sprintf(out\_format.comment,splitc\{i\}(4:end))];
0153                 \textcolor{keyword}{end}
0154             \textcolor{keyword}{else}
0155                 \textcolor{comment}{%- Look for Matlab keywords}
0156                 r = splitc\{i\};
0157                 stringcode = \textcolor{string}{''};
0158                 \textcolor{keyword}{while} 1
0159                     [t,r,q] = strtok(r,strtok\_delim);
0160                     stringcode = [stringcode q];
0161                     \textcolor{keyword}{if} isempty(t), \textcolor{keyword}{break}, \textcolor{keyword}{end};
0162                     isNextIncr  = any(strcmp(t,mKeySort.nextincr));
0163                     isNextIncr2 = any(strcmp(t,mKeySort.nextincr2));
0164                     isCurrDecr  = any(strcmp(t,mKeySort.currdecr));
0165                     isNextDecr  = any(strcmp(t,mKeySort.nextdecr));
0166                     isOther     = any(strcmp(t,mKeySort.other));
0167                     \textcolor{keyword}{if} isNextDecr \textcolor{comment}{% if strcmp(t,'end')}
0168                         \textcolor{comment}{% 'end' is keyword or array subscript ?}
0169                         rr = fliplr(deblank(fliplr(r)));
0170                         icomma = strmatch(\textcolor{string}{','},rr);
0171                         isemicolon = strmatch(\textcolor{string}{';'},rr);
0172                         \textcolor{keyword}{if} \~{}(isempty(rr) | \~{}isempty([icomma isemicolon]))
0173                             isNextDecr = 0;
0174                         \textcolor{keyword}{else}
0175                             nbblanks = nbblanks - 1;
0176                             flagnextline = flagnextline + 1;
0177                         \textcolor{keyword}{end}
0178                         \textcolor{comment}{% TODO \% false detection of a([end,1])}
0179                     \textcolor{keyword}{end}
0180                     \textcolor{keyword}{if} isNextIncr, flagnextline = flagnextline + 1; \textcolor{keyword}{end}
0181                     \textcolor{keyword}{if} isNextIncr2, flagnextline = flagnextline + 2; \textcolor{keyword}{end}
0182                     \textcolor{keyword}{if} isNextDecr, flagnextline = flagnextline - 1; \textcolor{keyword}{end}
0183                     \textcolor{keyword}{if} isCurrDecr, nbblanks = nbblanks - 1; \textcolor{keyword}{end}
0184                     \textcolor{comment}{% if any(strcmp(t,matlabKeywords))}
0185                     \textcolor{keyword}{if} isNextIncr | isNextIncr2 |isCurrDecr | isNextDecr | isOther
0186                         \textcolor{keyword}{if} \~{}isempty(stringcode)
0187                             newline = [newline sprintf(out\_format.code,stringcode)];
0188                             stringcode = \textcolor{string}{''};
0189                         \textcolor{keyword}{end}
0190                         newline = [newline sprintf(out\_format.keyword,t)];
0191                     \textcolor{keyword}{else}
0192                         stringcode = [stringcode t];
0193                     \textcolor{keyword}{end}
0194                 \textcolor{keyword}{end}
0195                 \textcolor{keyword}{if} \~{}isempty(stringcode)
0196                     newline = [newline sprintf(out\_format.code,stringcode)];
0197                 \textcolor{keyword}{end}
0198             \textcolor{keyword}{end}
0199         \textcolor{keyword}{end}
0200         \textcolor{keyword}{if} \~{}opt.indent, nbblanks = 0; \textcolor{keyword}{end}
0201         \textcolor{comment}{%- Print the syntax highlighted line}
0202         fprintf(outfid,out\_format.line,[blanks(nbblanks*opt.tabs) newline]);
0203     \textcolor{keyword}{end}
0204     fprintf(outfid,out\_format.pre\_end);
0205 
0206 \textcolor{comment}{%===============================================================================}
0207 \textcolor{comment}{%                                  HTML FORMAT                                 \%}
0208 \textcolor{comment}{%===============================================================================}
0209 \textcolor{keyword}{function} html\_file\_start(fid,mfile)
0210     fprintf(fid,[ \textcolor{keyword}{\underline{...}}
0211     \textcolor{string}{'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0212     \textcolor{string}{'\(\backslash\)t"http://www.w3.org/TR/REC-html40/loose.dtd">\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0213     \textcolor{string}{'<html>\(\backslash\)n<head>\(\backslash\)n<title>\%s</title>\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0214     \textcolor{string}{'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0215     \textcolor{string}{'<meta name="generator" content="highlight.m \&copy; 2003 Guillaume Flandin">\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0216     \textcolor{string}{'<style type="text/css">\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0217     \textcolor{string}{'  .comment \{color: \#228B22;\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0218     \textcolor{string}{'  .string \{color: \#B20000;\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0219     \textcolor{string}{'  .keyword, .cont \{color: \#0000FF;\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0220     \textcolor{string}{'  .cont \{text-decoration: underline;\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0221     \textcolor{string}{'  .code \{color: \#000000;\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0222     \textcolor{string}{'</style>\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0223     \textcolor{string}{'</head>\(\backslash\)n<body>\(\backslash\)n'}],mfile);
0224 
0225 \textcolor{comment}{%-------------------------------------------------------------------------------}
0226 \textcolor{keyword}{function} html\_file\_end(fid)
0227     fprintf(fid,\textcolor{string}{'\(\backslash\)n</body>\(\backslash\)n</html>'});
0228 
0229 \textcolor{comment}{%-------------------------------------------------------------------------------}
0230 \textcolor{keyword}{function} format = html\_format
0231     format.string    = \textcolor{string}{'<span class="string">\%s</span>'};
0232     format.comment   = \textcolor{string}{'<span class="comment">\%s</span>'};
0233     format.code      = \textcolor{string}{'\%s'}; \textcolor{comment}{%'<span class="code">\%s</span>';}
0234     format.keyword   = \textcolor{string}{'<span class="keyword">\%s</span>'};
0235     format.cont      = \textcolor{string}{'<span class="cont">\%s</span>'};
0236     format.pre\_start = \textcolor{string}{'<pre class="mcode">'};
0237     format.pre\_end   = \textcolor{string}{'</pre>\(\backslash\)n'};
0238     format.nb\_line   = \textcolor{string}{'\%04d '};
0239     format.line      = \textcolor{string}{'\%s\(\backslash\)n'};
0240 
0241 \textcolor{comment}{%-------------------------------------------------------------------------------}
0242 \textcolor{keyword}{function} str = html\_special\_char(str)
0243     \textcolor{comment}{%- See http://www.w3.org/TR/html4/charset.html\#h-5.3.2}
0244     str = strrep(str,\textcolor{string}{'\&'},\textcolor{string}{'\&amp;'});
0245     str = strrep(str,\textcolor{string}{'<'},\textcolor{string}{'\&lt;'});
0246     str = strrep(str,\textcolor{string}{'>'},\textcolor{string}{'\&gt;'});
0247     str = strrep(str,\textcolor{string}{'"'},\textcolor{string}{'\&quot;'});
0248 
0249 \textcolor{comment}{%===============================================================================}
0250 \textcolor{comment}{%                                  XHTML FORMAT                                \%}
0251 \textcolor{comment}{%===============================================================================}
0252 \textcolor{keyword}{function} xhtml\_file\_start(fid,mfile)
0253     fprintf(fid,[ \textcolor{keyword}{\underline{...}}
0254     \textcolor{string}{'<?xml version="1.0"?>\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0255     \textcolor{string}{'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '} \textcolor{keyword}{\underline{...}}
0256     \textcolor{string}{'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0257     \textcolor{string}{'<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0258     \textcolor{string}{'<head>\(\backslash\)n<title>\%s</title>\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0259     \textcolor{string}{'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0260     \textcolor{string}{'<meta name="generator" content="highlight.m \&copy; 2003 Guillaume Flandin" />\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0261     \textcolor{string}{'<style type="text/css">\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0262     \textcolor{string}{'  .comment \{color: \#228B22;\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0263     \textcolor{string}{'  .string \{color: \#B20000;\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0264     \textcolor{string}{'  .keyword, .cont \{color: \#0000FF;\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0265     \textcolor{string}{'  .cont \{text-decoration: underline;\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0266     \textcolor{string}{'  .code \{color: \#000000;\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0267     \textcolor{string}{'</style>\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0268     \textcolor{string}{'</head>\(\backslash\)n<body>\(\backslash\)n'}],mfile);
0269 
0270 \textcolor{comment}{%-------------------------------------------------------------------------------}
0271 \textcolor{keyword}{function} xhtml\_file\_end(fid)
0272     fprintf(fid,\textcolor{string}{'\(\backslash\)n</body>\(\backslash\)n</html>'});
0273 
0274 \textcolor{comment}{%-------------------------------------------------------------------------------}
0275 \textcolor{keyword}{function} format = xhtml\_format
0276     format.string    = \textcolor{string}{'<span class="string">\%s</span>'};
0277     format.comment   = \textcolor{string}{'<span class="comment">\%s</span>'};
0278     format.code      = \textcolor{string}{'\%s'}; \textcolor{comment}{%'<span class="code">\%s</span>';}
0279     format.keyword   = \textcolor{string}{'<span class="keyword">\%s</span>'};
0280     format.cont      = \textcolor{string}{'<span class="cont">\%s</span>'};
0281     format.pre\_start = \textcolor{string}{'<pre class="mcode">'};
0282     format.pre\_end   = \textcolor{string}{'</pre>\(\backslash\)n'};
0283     format.nb\_line   = \textcolor{string}{'\%04d '};
0284     format.line      = \textcolor{string}{'\%s\(\backslash\)n'};
0285 
0286 \textcolor{comment}{%-------------------------------------------------------------------------------}
0287 \textcolor{keyword}{function} str = xhtml\_special\_char(str)
0288     \textcolor{comment}{%- See http://www.w3.org/TR/html4/charset.html\#h-5.3.2}
0289     str = strrep(str,\textcolor{string}{'\&'},\textcolor{string}{'\&amp;'});
0290     str = strrep(str,\textcolor{string}{'<'},\textcolor{string}{'\&lt;'});
0291     str = strrep(str,\textcolor{string}{'>'},\textcolor{string}{'\&gt;'});
0292     str = strrep(str,\textcolor{string}{'"'},\textcolor{string}{'\&quot;'});
0293 
0294 
0295 \textcolor{comment}{%===============================================================================}
0296 \textcolor{comment}{%                                   XML FORMAT                                 \%}
0297 \textcolor{comment}{%===============================================================================}
0298 \textcolor{keyword}{function} xml\_file\_start(fid,mfile)
0299     fprintf(fid,[ \textcolor{keyword}{\underline{...}}
0300     \textcolor{string}{'<?xml version="1.0" encoding="iso-8859-1" ?>\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0301     \textcolor{string}{'<!DOCTYPE mfile SYSTEM "matlab.dtd">\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0302     \textcolor{string}{'<mfile name="\%s">\(\backslash\)n'}],mfile);
0303 
0304 \textcolor{comment}{%-------------------------------------------------------------------------------}
0305 \textcolor{keyword}{function} xml\_file\_end(fid)
0306     fprintf(fid,\textcolor{string}{'</mfile>'});
0307 
0308 \textcolor{comment}{%-------------------------------------------------------------------------------}
0309 \textcolor{keyword}{function} format = xml\_format
0310     format.string    = \textcolor{string}{'<string>\%s</string>'};
0311     format.comment   = \textcolor{string}{'<comment>\%s</comment>'};
0312     format.code      = \textcolor{string}{'\%s'}; \textcolor{comment}{%'<code>\%s</code>';}
0313     format.keyword   = \textcolor{string}{'<keyword>\%s</keyword>'};
0314     format.cont      = \textcolor{string}{'<cont>\%s</cont>'};
0315     format.pre\_start = \textcolor{string}{''};
0316     format.pre\_end   = \textcolor{string}{''};
0317     format.nb\_line   = \textcolor{string}{'<line nb="\%04d ">'};
0318     format.line      = \textcolor{string}{'\%s</line>\(\backslash\)n'};
0319 
0320 \textcolor{comment}{%-------------------------------------------------------------------------------}
0321 \textcolor{keyword}{function} str = xml\_special\_char(str)
0322     \textcolor{comment}{%- See http://www.w3.org/TR/REC-xml\#sec-predefined-ent}
0323     str = strrep(str,\textcolor{string}{'\&'},\textcolor{string}{'\&amp;'});
0324     str = strrep(str,\textcolor{string}{'<'},\textcolor{string}{'\&lt;'});
0325     str = strrep(str,\textcolor{string}{'>'},\textcolor{string}{'\&gt;'});
0326     str = strrep(str,\textcolor{string}{'"'},\textcolor{string}{'\&quot;'});
0327     \textcolor{comment}{%str = strrep(str,'''','\&apos;');}
0328     
0329 \textcolor{comment}{%===============================================================================}
0330 \textcolor{comment}{%                                  LaTeX FORMAT                                \%}
0331 \textcolor{comment}{%===============================================================================}
0332 \textcolor{keyword}{function} tex\_file\_start(fid,mfile)
0333     fprintf(fid,[\textcolor{string}{'\(\backslash\)\(\backslash\)documentclass[a4paper,10pt]\{article\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0334                  \textcolor{string}{'    \(\backslash\)\(\backslash\)usepackage\{alltt\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0335                  \textcolor{string}{'    \(\backslash\)\(\backslash\)usepackage\{color\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0336                  \textcolor{string}{'    \(\backslash\)\(\backslash\)usepackage\{fullpage\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0337                  \textcolor{string}{'    \(\backslash\)\(\backslash\)definecolor\{string\}\{rgb\}\{0.7,0.0,0.0\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0338                  \textcolor{string}{'    \(\backslash\)\(\backslash\)definecolor\{comment\}\{rgb\}\{0.13,0.54,0.13\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0339                  \textcolor{string}{'    \(\backslash\)\(\backslash\)definecolor\{keyword\}\{rgb\}\{0.0,0.0,1.0\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0340                  \textcolor{string}{'    \(\backslash\)\(\backslash\)title\{\%s\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0341                  \textcolor{string}{'    \(\backslash\)\(\backslash\)author\{\(\backslash\)\(\backslash\)textsc\{Matlab\}, The Mathworks, Inc.\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0342                  \textcolor{string}{'\(\backslash\)\(\backslash\)begin\{document\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0343                  \textcolor{string}{'\(\backslash\)\(\backslash\)maketitle\(\backslash\)n'}],mfile);
0344 
0345 \textcolor{comment}{%-------------------------------------------------------------------------------}
0346 \textcolor{keyword}{function} tex\_file\_end(fid)
0347     fprintf(fid,\textcolor{string}{'\(\backslash\)\(\backslash\)end\{document\}'});
0348 
0349 \textcolor{comment}{%-------------------------------------------------------------------------------}
0350 \textcolor{keyword}{function} format = tex\_format
0351     format.string    = \textcolor{string}{'\(\backslash\)\(\backslash\)textcolor\{string\}\{\%s\}'};
0352     format.comment   = \textcolor{string}{'textcolor\{comment\}\{\%s\}'}; \textcolor{comment}{% '\%' has been replaced by '\(\backslash\)\%'}
0353     format.code      = \textcolor{string}{'\%s'};
0354     format.keyword   = \textcolor{string}{'\(\backslash\)\(\backslash\)textcolor\{keyword\}\{\%s\}'};
0355     format.cont      = \textcolor{string}{'\(\backslash\)\(\backslash\)textcolor\{keyword\}\{\(\backslash\)\(\backslash\)underline\{\%s\}\}'};
0356     format.pre\_start = \textcolor{string}{'\(\backslash\)\(\backslash\)begin\{alltt\}\(\backslash\)n'};
0357     format.pre\_end   = \textcolor{string}{'\(\backslash\)\(\backslash\)end\{alltt\}\(\backslash\)n'};
0358     format.nb\_line   = \textcolor{string}{'\%04d '};
0359     format.line      = \textcolor{string}{'\%s\(\backslash\)n'};
0360 
0361 \textcolor{comment}{%-------------------------------------------------------------------------------}
0362 \textcolor{keyword}{function} str = tex\_special\_char(str)
0363     \textcolor{comment}{% Special characters: \# \$ \% \& \~{} \_ \^{} \(\backslash\) \{ \}}
0364     str = strrep(str,\textcolor{string}{'\(\backslash\)'},\textcolor{string}{'\(\backslash\)(\(\backslash\)backslash\(\backslash\))'}); \textcolor{comment}{% \$\(\backslash\)backslash\$ or \(\backslash\)textbackslash or \(\backslash\)verb+\(\backslash\)+}
0365     str = strrep(str,\textcolor{string}{'\#'},\textcolor{string}{'\(\backslash\)\#'});
0366     str = strrep(str,\textcolor{string}{'\$'},\textcolor{string}{'\(\backslash\)\$'});
0367     str = strrep(str,\textcolor{string}{'\%'},\textcolor{string}{'\(\backslash\)\%'});
0368     str = strrep(str,\textcolor{string}{'\&'},\textcolor{string}{'\(\backslash\)\&'});
0369     str = strrep(str,\textcolor{string}{'\_'},\textcolor{string}{'\(\backslash\)\_'});
0370     str = strrep(str,\textcolor{string}{'\{'},\textcolor{string}{'\(\backslash\)\{'});
0371     str = strrep(str,\textcolor{string}{'\}'},\textcolor{string}{'\(\backslash\)\}'});
0372     str = strrep(str,\textcolor{string}{'\^{}'},\textcolor{string}{'\(\backslash\)\^{}\{\}'});
0373     str = strrep(str,\textcolor{string}{'\~{}'},\textcolor{string}{'\(\backslash\)\~{}\{\}'}); \textcolor{comment}{% or \(\backslash\)textasciitilde}
0374 
0375 \textcolor{comment}{%===============================================================================}
0376 \textcolor{comment}{%                                   RTF FORMAT                                 \%}
0377 \textcolor{comment}{%===============================================================================}
0378 \textcolor{keyword}{function} rtf\_file\_start(fid,mfile)
0379     fprintf(fid,[\textcolor{string}{'\{\(\backslash\)\(\backslash\)rtf1\(\backslash\)\(\backslash\)ansi\(\backslash\)n\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0380                  \textcolor{string}{'\{\(\backslash\)\(\backslash\)fonttbl\{\(\backslash\)\(\backslash\)f0\(\backslash\)\(\backslash\)fmodern\(\backslash\)\(\backslash\)fcharset0\(\backslash\)\(\backslash\)fprq1 Courier New;\}\}\(\backslash\)n\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0381                  \textcolor{string}{'\{\(\backslash\)\(\backslash\)colortbl;\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0382                  \textcolor{string}{'\(\backslash\)\(\backslash\)red0\(\backslash\)\(\backslash\)green0\(\backslash\)\(\backslash\)blue0;\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0383                  \textcolor{string}{'\(\backslash\)\(\backslash\)red0\(\backslash\)\(\backslash\)green0\(\backslash\)\(\backslash\)blue255;\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0384                  \textcolor{string}{'\(\backslash\)\(\backslash\)red0\(\backslash\)\(\backslash\)green255\(\backslash\)\(\backslash\)blue255;\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0385                  \textcolor{string}{'\(\backslash\)\(\backslash\)red0\(\backslash\)\(\backslash\)green255\(\backslash\)\(\backslash\)blue0;\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0386                  \textcolor{string}{'\(\backslash\)\(\backslash\)red255\(\backslash\)\(\backslash\)green0\(\backslash\)\(\backslash\)blue255;\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0387                  \textcolor{string}{'\(\backslash\)\(\backslash\)red255\(\backslash\)\(\backslash\)green0\(\backslash\)\(\backslash\)blue0;\}\(\backslash\)n\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0388                  \textcolor{string}{'\{\(\backslash\)\(\backslash\)info\{\(\backslash\)\(\backslash\)title \%s\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0389                  \textcolor{string}{'\{\(\backslash\)\(\backslash\)author HighLight.m Copyright 2003\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0390                  \textcolor{string}{'\{\(\backslash\)\(\backslash\)creatim\(\backslash\)\(\backslash\)yr\%s\(\backslash\)\(\backslash\)mo\%s\(\backslash\)\(\backslash\)dy\%s\}'} \textcolor{keyword}{\underline{...}}
0391                  \textcolor{string}{'\{\(\backslash\)\(\backslash\)*\(\backslash\)\(\backslash\)manager Guillaume Flandin\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0392                  \textcolor{string}{'\{\(\backslash\)\(\backslash\)*\(\backslash\)\(\backslash\)company gllmflndn.com\}\(\backslash\)n'} \textcolor{keyword}{\underline{...}}
0393                  \textcolor{string}{'\{\(\backslash\)\(\backslash\)*\(\backslash\)\(\backslash\)hlinkbase https://www.gllmflndn.com/software/'} \textcolor{keyword}{\underline{...}}textcolor{comment}{ }
0394                  \textcolor{string}{'matlab/highlight/\}\}\(\backslash\)n\(\backslash\)n'}],mfile,\textcolor{keyword}{\underline{...}}
0395                  datestr(date,\textcolor{string}{'yyyy'}),datestr(date,\textcolor{string}{'mm'}),datestr(date,\textcolor{string}{'dd'}));
0396 
0397 \textcolor{comment}{%-------------------------------------------------------------------------------}
0398 \textcolor{keyword}{function} rtf\_file\_end(fid)
0399     fprintf(fid,\textcolor{string}{'\}'});
0400 
0401 \textcolor{comment}{%-------------------------------------------------------------------------------}
0402 \textcolor{keyword}{function} format = rtf\_format
0403     format.string    = \textcolor{string}{'\{\(\backslash\)\(\backslash\)cf6 \%s\}'};
0404     format.comment   = \textcolor{string}{'\{\(\backslash\)\(\backslash\)cf4 \%s\}'};
0405     format.code      = \textcolor{string}{'\{\%s\}'};
0406     format.keyword   = \textcolor{string}{'\{\(\backslash\)\(\backslash\)cf2 \%s\}'};
0407     format.cont      = \textcolor{string}{'\{\(\backslash\)\(\backslash\)cf2 \%s\}'};
0408     format.pre\_start = \textcolor{string}{'\{\(\backslash\)\(\backslash\)f0\(\backslash\)\(\backslash\)fs16\{'};
0409     format.pre\_end   = \textcolor{string}{'\}\}'};
0410     format.nb\_line   = \textcolor{string}{'\{\%04d \}'};
0411     format.line      = \textcolor{string}{'\%s\(\backslash\)n\(\backslash\)\(\backslash\)par '};
0412 
0413 \textcolor{comment}{%-------------------------------------------------------------------------------}
0414 \textcolor{keyword}{function} str = rtf\_special\_char(str)
0415     str = strrep(str,\textcolor{string}{'\(\backslash\)'},\textcolor{string}{'\(\backslash\)\(\backslash\)'});
0416     str = strrep(str,\textcolor{string}{'\{'},\textcolor{string}{'\(\backslash\)\{'});
0417     str = strrep(str,\textcolor{string}{'\}'},\textcolor{string}{'\(\backslash\)\}'});
0418 
0419 \textcolor{comment}{%===============================================================================}
0420 \textcolor{comment}{%                                 MATLAB KEYWORDS                              \%}
0421 \textcolor{comment}{%===============================================================================}
0422 \textcolor{keyword}{function} matlabKeywords = getMatlabKeywords
0423     \textcolor{comment}{%matlabKeywords = iskeyword; \% Matlab R13}
0424     matlabKeywords = \{\textcolor{string}{'break'}, \textcolor{string}{'case'}, \textcolor{string}{'catch'}, \textcolor{string}{'continue'}, \textcolor{string}{'elseif'}, \textcolor{string}{'else'},\textcolor{keyword}{\underline{...}}
0425                       \textcolor{string}{'end'}, \textcolor{string}{'for'}, \textcolor{string}{'function'}, \textcolor{string}{'global'}, \textcolor{string}{'if'}, \textcolor{string}{'otherwise'}, \textcolor{keyword}{\underline{...}}
0426                       \textcolor{string}{'persistent'}, \textcolor{string}{'return'}, \textcolor{string}{'switch'}, \textcolor{string}{'try'}, \textcolor{string}{'while'}\};
0427                       
0428 \textcolor{comment}{%-------------------------------------------------------------------------------}
0429 \textcolor{keyword}{function} mKeySort = getMatlabKeywordsSorted
0430     mKeySort.nextincr = \{\textcolor{string}{'for'}, \textcolor{string}{'while'}, \textcolor{string}{'if'}, \textcolor{string}{'else'}, \textcolor{string}{'elseif'}, \textcolor{keyword}{\underline{...}}
0431                          \textcolor{string}{'case'}, \textcolor{string}{'otherwise'}, \textcolor{string}{'try'}, \textcolor{string}{'catch'}\};
0432     mKeySort.nextincr2 = \{\textcolor{string}{'switch'}\};
0433     mKeySort.currdecr = \{\textcolor{string}{'else'}, \textcolor{string}{'elseif'}, \textcolor{string}{'case'}, \textcolor{string}{'otherwise'}, \textcolor{string}{'catch'}\};
0434     mKeySort.nextdecr = \{\textcolor{string}{'end'}\};
0435     mKeySort.other    = \{\textcolor{string}{'break'}, \textcolor{string}{'continue'}, \textcolor{string}{'function'}, \textcolor{string}{'global'}, \textcolor{keyword}{\underline{...}}
0436                          \textcolor{string}{'persistent'}, \textcolor{string}{'return'}\};
0437 
0438 \textcolor{comment}{%===============================================================================}
0439 \textcolor{comment}{%                               HANDLE TAB CHARACTER                           \%}
0440 \textcolor{comment}{%===============================================================================}
0441 \textcolor{keyword}{function} str = horztab(str,n)
0442     \textcolor{comment}{%- For browsers, the horizontal tab character is the smallest non-zero }
0443     \textcolor{comment}{%- number of spaces necessary to line characters up along tab stops that are}
0444     \textcolor{comment}{%- every 8 characters: behaviour obtained when n = 0.}
0445     \textcolor{keyword}{if} n > 0
0446         str = strrep(str,sprintf(\textcolor{string}{'\(\backslash\)t'}),blanks(n));
0447     \textcolor{keyword}{end}
0448 
0449 \textcolor{comment}{%===============================================================================}
0450 \textcolor{comment}{%                                MATLAB CODE PARSER                            \%}
0451 \textcolor{comment}{%===============================================================================}
0452 \textcolor{keyword}{function} splitc = splitcode(code)
0453     \textcolor{comment}{%Split a line of  Matlab code in string, comment and other}
0454 
0455     \textcolor{comment}{%- Label quotes in \{'transpose', 'beginstring', 'midstring', 'endstring'\}}
0456     iquote = findstr(code,\textcolor{string}{''''});
0457     quotetransp = [double(\textcolor{string}{'\_''.)\}]'}) \textcolor{keyword}{\underline{...}}
0458                    double(\textcolor{string}{'A'}):double(\textcolor{string}{'Z'}) \textcolor{keyword}{\underline{...}}
0459                    double(\textcolor{string}{'0'}):double(\textcolor{string}{'9'}) \textcolor{keyword}{\underline{...}}
0460                    double(\textcolor{string}{'a'}):double(\textcolor{string}{'z'})];
0461     flagstring = 0;
0462     flagdoublequote = 0;
0463     jquote = [];
0464     \textcolor{keyword}{for} i=1:length(iquote)
0465         \textcolor{keyword}{if} \~{}flagstring
0466             \textcolor{keyword}{if} iquote(i) > 1 \& any(quotetransp == double(code(iquote(i)-1)))
0467                 \textcolor{comment}{% => 'transpose';}
0468             \textcolor{keyword}{else}
0469                 \textcolor{comment}{% => 'beginstring';}
0470                 jquote(size(jquote,1)+1,:) = [iquote(i) length(code)];
0471                 flagstring = 1;
0472             \textcolor{keyword}{end}
0473         \textcolor{keyword}{else} \textcolor{comment}{% if flagstring}
0474             \textcolor{keyword}{if} flagdoublequote | \textcolor{keyword}{\underline{...}}
0475                (iquote(i) < length(code) \& strcmp(code(iquote(i)+1),\textcolor{string}{''''}))
0476                 \textcolor{comment}{% => 'midstring';}
0477                 flagdoublequote = \~{}flagdoublequote;
0478             \textcolor{keyword}{else}
0479                 \textcolor{comment}{% => 'endstring';}
0480                 jquote(size(jquote,1),2) = iquote(i);
0481                 flagstring = 0;
0482             \textcolor{keyword}{end}
0483         \textcolor{keyword}{end}
0484     \textcolor{keyword}{end}
0485 
0486     \textcolor{comment}{%- Find if a portion of code is a comment}
0487     ipercent = findstr(code,\textcolor{string}{'\%'});
0488     jpercent = [];
0489     \textcolor{keyword}{for} i=1:length(ipercent)
0490         \textcolor{keyword}{if} isempty(jquote) | \textcolor{keyword}{\underline{...}}
0491            \~{}any((ipercent(i) > jquote(:,1)) \& (ipercent(i) < jquote(:,2)))
0492             jpercent = [ipercent(i) length(code)];
0493             \textcolor{keyword}{break};
0494         \textcolor{keyword}{end}
0495     \textcolor{keyword}{end}
0496 
0497     \textcolor{comment}{%- Find continuation punctuation '...'}
0498     icont = findstr(code,\textcolor{string}{'...'});
0499     \textcolor{keyword}{for} i=1:length(icont)
0500         \textcolor{keyword}{if} (isempty(jquote) | \textcolor{keyword}{\underline{...}}
0501             \~{}any((icont(i) > jquote(:,1)) \& (icont(i) < jquote(:,2)))) \& \textcolor{keyword}{\underline{...}}
0502             (isempty(jpercent) | \textcolor{keyword}{\underline{...}}
0503             icont(i) < jpercent(1))
0504             jpercent = [icont(i) length(code)];
0505             \textcolor{keyword}{break};
0506         \textcolor{keyword}{end}
0507     \textcolor{keyword}{end}
0508 
0509     \textcolor{comment}{%- Remove strings inside comments}
0510     \textcolor{keyword}{if} \~{}isempty(jpercent) \& \~{}isempty(jquote)
0511         jquote(find(jquote(:,1) > jpercent(1)),:) = [];
0512     \textcolor{keyword}{end}
0513 
0514     \textcolor{comment}{%- Split code in a cell array of strings}
0515     icode = [jquote ; jpercent];
0516     splitc = \{\};
0517     \textcolor{keyword}{if} isempty(icode)
0518         splitc\{1\} = code;
0519     \textcolor{keyword}{elseif} icode(1,1) > 1
0520         splitc\{1\} = code(1:icode(1,1)-1);
0521     \textcolor{keyword}{end}
0522     \textcolor{keyword}{for} i=1:size(icode,1)
0523         splitc\{end+1\} = code(icode(i,1):icode(i,2));
0524         \textcolor{keyword}{if} i < size(icode,1) \& icode(i+1,1) > icode(i,2) + 1
0525             splitc\{end+1\} = code((icode(i,2)+1):(icode(i+1,1)-1));
0526         \textcolor{keyword}{elseif} i == size(icode,1) \& icode(i,2) < length(code)
0527             splitc\{end+1\} = code(icode(i,2)+1:end);
0528         \textcolor{keyword}{end}
0529     \textcolor{keyword}{end}
0530       
0531 \textcolor{comment}{%===============================================================================}
0532 \textcolor{comment}{%                           MODIFIED VERSION OF STRTOK                         \%}
0533 \textcolor{comment}{%===============================================================================}
0534 \textcolor{keyword}{function} [token, remainder, quotient] = strtok(string, delimiters)
0535 \textcolor{comment}{% Modified version of STRTOK to also return the quotient}
0536 \textcolor{comment}{% string = [quotient token remainder]}
0537 \textcolor{comment}{%STRTOK Find token in string.}
0538 \textcolor{comment}{%   STRTOK(S) returns the first token in the string S delimited}
0539 \textcolor{comment}{%   by "white space".   Any leading white space characters are ignored.}
0540 \textcolor{comment}{%}
0541 \textcolor{comment}{%   STRTOK(S,D) returns the first token delimited by one of the }
0542 \textcolor{comment}{%   characters in D.  Any leading delimiter characters are ignored.}
0543 \textcolor{comment}{%}
0544 \textcolor{comment}{%   [T,R] = STRTOK(...) also returns the remainder of the original}
0545 \textcolor{comment}{%   string.}
0546 \textcolor{comment}{%   If the token is not found in S then R is an empty string and T}
0547 \textcolor{comment}{%   is same as S. }
0548 \textcolor{comment}{%}
0549 \textcolor{comment}{%   Copyright 1984-2002 The MathWorks, Inc. }
0550 \textcolor{comment}{%   \$Revision: 5.14 \$  \$Date: 2002/04/09 00:33:38 \$}
0551 
0552 token = []; remainder = []; quotient = string;
0553 
0554 len = length(string);
0555 \textcolor{keyword}{if} len == 0
0556     \textcolor{keyword}{return}
0557 \textcolor{keyword}{end}
0558 
0559 \textcolor{keyword}{if} (nargin == 1)
0560     delimiters = [9:13 32]; \textcolor{comment}{% White space characters}
0561 \textcolor{keyword}{end}
0562 
0563 i = 1;
0564 \textcolor{keyword}{while} (any(string(i) == delimiters))
0565     i = i + 1;
0566     \textcolor{keyword}{if} (i > len), \textcolor{keyword}{return}, \textcolor{keyword}{end}
0567 \textcolor{keyword}{end}
0568 start = i;
0569 \textcolor{keyword}{while} (\~{}any(string(i) == delimiters))
0570     i = i + 1;
0571     \textcolor{keyword}{if} (i > len), \textcolor{keyword}{break}, \textcolor{keyword}{end}
0572 \textcolor{keyword}{end}
0573 finish = i - 1;
0574 
0575 token = string(start:finish);
0576 
0577 \textcolor{keyword}{if} (nargout >= 2)
0578     remainder = string(finish + 1:length(string));
0579 \textcolor{keyword}{end}
0580 
0581 \textcolor{keyword}{if} (nargout == 3 \& start > 1)
0582     quotient = string(1:start-1);
0583 \textcolor{keyword}{else}
0584     quotient = [];
0585 \textcolor{keyword}{end}
\end{alltt}
\end{document}
