├── prepare_submission_to_ctan.sh ├── .gitignore ├── README ├── makefile ├── matlab-prettifier.ins ├── matlab-prettifier.sty └── matlab-prettifier.dtx /prepare_submission_to_ctan.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | [ $# -eq 1 ] || exit 1 3 | 4 | PKGNAME="$1" 5 | rm -f ${PKGNAME}.tar.gz 6 | make all clean && \ 7 | ctanify ${PKGNAME}.ins ${PKGNAME}.pdf README makefile 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.fls 3 | *.fdb_latexmk 4 | *.glo 5 | *.gls 6 | *.idx 7 | *.ilg 8 | *.ind 9 | *.log 10 | *.m 11 | *.makefile.swp 12 | *.out 13 | *.swp 14 | *.tar.gz 15 | *.tmp 16 | *.toc 17 | *.zip 18 | 19 | matlab-prettifier.pdf 20 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | matlab-prettifier package 2 | 3 | Copyright 2014-- Julien Cretel 4 | 5 | Released under the LaTeX Project Public License 1.3 or later 6 | 7 | Built on top of the listings package, the matlab-prettifier package allows 8 | you to effortlessly prettyprint Matlab source code in documents typeset with 9 | LaTeX & friends. Three predefined styles, one of which closely mimicks that 10 | of the Matlab editor, are available and can be invoked by listings macros 11 | and environments in conjunction with (most) options provided by the listings 12 | package. The appearance of your Matlab listings can be further tweaked via a 13 | key-value interface extending that of listings'. Partial support for Octave 14 | syntax is provided. 15 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | TEXFLAGS = -e '$$pdflatex=q/pdflatex %O %S/' -pdf 2 | LATEXMK = latexmk 3 | RM = rm -f 4 | PKGNAME = matlab-prettifier 5 | PACKAGE = $(PKGNAME).dtx \ 6 | $(PKGNAME).ins \ 7 | $(PKGNAME).pdf \ 8 | README \ 9 | makefile 10 | 11 | all: doc 12 | 13 | doc: $(PKGNAME).pdf 14 | 15 | $(PKGNAME).pdf: $(PKGNAME).sty \ 16 | $(PKGNAME).gls \ 17 | $(PKGNAME).ind \ 18 | $(PKGNAME).dtx 19 | $(LATEXMK) $(TEXFLAGS) $(PKGNAME).dtx 20 | # open -a Preview $(PKGNAME).pdf 21 | 22 | $(PKGNAME).sty: $(PKGNAME).ins \ 23 | $(PKGNAME).dtx 24 | latex $(PKGNAME).ins 25 | 26 | $(PKGNAME).gls: $(PKGNAME).glo 27 | makeindex -s gglo.ist -o $(PKGNAME).gls $(PKGNAME).glo 28 | 29 | $(PKGNAME).ind: $(PKGNAME).idx 30 | makeindex -s gind.ist -o $(PKGNAME).ind $(PKGNAME).idx 31 | 32 | $(PKGNAME).glo: $(PKGNAME).dtx $(PKGNAME).sty 33 | $(LATEXMK) $(TEXFLAGS) $(PKGNAME).dtx 34 | 35 | dist: $(PACKAGE) 36 | $(RM) $(PKGNAME).zip 37 | zip $(PKGNAME).zip $(PACKAGE) 38 | 39 | clean: 40 | $(RM) *.aux *.fdb_latexmk *.fls *.glo *.gls *.ind *.idx *.ilg \ 41 | *.log *.lol *.m *.out *.tmp *.toc 42 | 43 | cleanall: clean 44 | $(RM) $(PKGNAME).pdf $(PKGNAME).zip 45 | 46 | .PHONY: all doc dist clean cleanall 47 | -------------------------------------------------------------------------------- /matlab-prettifier.ins: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (C) 2014 by Julien Cretel 3 | %% 4 | %% This work may be distributed and/or modified under the 5 | %% conditions of the LaTeX Project Public License, either version 1.3 6 | %% of this license or (at your option) any later version. 7 | %% The latest version of this license is in 8 | %% 9 | %% http://www.latex-project.org/lppl.txt 10 | %% 11 | %% and version 1.3 or later is part of all distributions of LaTeX 12 | %% version 2005/12/01 or later. 13 | %% 14 | %% 15 | % This file requires docstrip version 2.4 available from 16 | % ftp.dante.de tex-archive/macros/latex/unpacked/docstrip.tex 17 | \input docstrip 18 | \preamble 19 | 20 | This is a generated file. 21 | 22 | Copyright (C) 2014 by Julien Cretel 23 | 24 | This work may be distributed and/or modified under the 25 | conditions of the LaTeX Project Public License, either version 1.3 26 | of this license or (at your option) any later version. 27 | The latest version of this license is in 28 | 29 | http://www.latex-project.org/lppl.txt 30 | 31 | and version 1.3 or later is part of all distributions of LaTeX 32 | version 2005/12/01 or later. 33 | 34 | This work has the LPPL maintenance status `maintained'. 35 | 36 | The Current Maintainer of this work is Julien Cretel. 37 | 38 | This work currently consists of the files matlab-prettifier.dtx, 39 | matlab-prettifier.ins, and the derived file matlab-prettifier.sty. 40 | 41 | \endpreamble 42 | 43 | 44 | \keepsilent 45 | \askforoverwritefalse 46 | 47 | \usedir{tex/latex/matlab-prettifier} 48 | 49 | % the package 50 | \generate{\file{matlab-prettifier.sty}{\from{matlab-prettifier.dtx}{package}}} 51 | 52 | % message 53 | \obeyspaces 54 | \Msg{****************************************************} 55 | \Msg{* *} 56 | \Msg{* To finish the installation you have to move the *} 57 | \Msg{* following file into a directory searched by TeX: *} 58 | \Msg{* *} 59 | \Msg{* matlab-prettifier.sty *} 60 | \Msg{* *} 61 | \Msg{* To produce the documentation run the file *} 62 | \Msg{* matlab-prettifier.dtx through LaTeX. *} 63 | \Msg{* *} 64 | \Msg{****************************************************} 65 | 66 | \endbatchfile 67 | -------------------------------------------------------------------------------- /matlab-prettifier.sty: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `matlab-prettifier.sty', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% matlab-prettifier.dtx (with options: `package') 8 | %% 9 | %% This is a generated file. 10 | %% 11 | %% Copyright (C) 2014 by Julien Cretel 12 | %% 13 | %% This work may be distributed and/or modified under the 14 | %% conditions of the LaTeX Project Public License, either version 1.3 15 | %% of this license or (at your option) any later version. 16 | %% The latest version of this license is in 17 | %% 18 | %% http://www.latex-project.org/lppl.txt 19 | %% 20 | %% and version 1.3 or later is part of all distributions of LaTeX 21 | %% version 2005/12/01 or later. 22 | %% 23 | %% This work has the LPPL maintenance status `maintained'. 24 | %% 25 | %% The Current Maintainer of this work is Julien Cretel. 26 | %% 27 | %% This work currently consists of the files matlab-prettifier.dtx, 28 | %% matlab-prettifier.ins, and the derived file matlab-prettifier.sty. 29 | %% 30 | \NeedsTeXFormat{LaTeX2e}[2011/06/27] 31 | \ProvidesPackage{matlab-prettifier} 32 | [2014/06/19 v0.3 A package for prettyprinting Matlab source code] 33 | \newcommand\lstoptcheck@mlpr[1]{% 34 | \@ifpackagewith{listings}{#1}{% 35 | \PackageError{matlab-prettifier}% 36 | {incompatible listings' option #1}{% 37 | Make sure the `listings' package 38 | doesn't get loaded with option `#1'% 39 | } 40 | } 41 | {} 42 | } 43 | \lstoptcheck@mlpr{noaspects} 44 | \lstoptcheck@mlpr{0.21} 45 | \lstoptcheck@mlpr{savemem} 46 | \newif\ifframed@mlpr@ 47 | \DeclareOption{framed}{\framed@mlpr@true} 48 | \newif\ifnumbered@mlpr@ 49 | \DeclareOption{numbered}{\numbered@mlpr@true} 50 | \DeclareOption{draft}{\PassOptionsToPackage{\CurrentOption}{listings}} 51 | \DeclareOption{final}{\PassOptionsToPackage{\CurrentOption}{listings}} 52 | \DeclareOption*{% 53 | \OptionNotUsed 54 | \PackageWarning{matlab-prettifier}{Unknown `\CurrentOption' option} 55 | } 56 | \ProcessOptions\relax 57 | \RequirePackage{textcomp}[2005/09/27] 58 | \RequirePackage{xcolor}[2007/01/21] 59 | \RequirePackage{listings}[2013/08/26] 60 | \newcommand\language@mlpr{Matlab-pretty} 61 | \expandafter\lst@NormedDef\expandafter\languageNormedDefd@mlpr% 62 | \expandafter{\language@mlpr} 63 | \expandafter\expandafter\expandafter\lstdefinelanguage\expandafter% 64 | {\language@mlpr}{% 65 | sensitive=true, 66 | alsoother={\$@}, 67 | MoreSelectCharTable=\MoreSelectCharTable@mlpr, 68 | morekeywords=[1]{% 69 | for, 70 | if, 71 | otherwise, 72 | parfor, 73 | spmd, 74 | switch, 75 | try, 76 | while, 77 | }, 78 | keywordstyle=[1]\processOpRegKW@mlpr, 79 | morekeywords=[2]{% 80 | break, 81 | case, 82 | catch, 83 | continue, 84 | else, 85 | elseif, 86 | function, 87 | return, 88 | }, 89 | keywordstyle=[2]\processMidKW@mlpr, 90 | morekeywords=[3]{% 91 | global, 92 | persistent, 93 | }, 94 | keywordstyle=[3]\processStdaKW@mlpr, 95 | morekeywords=[4]{classdef}, 96 | keywordstyle=[4]\processClassdefKW@mlpr, 97 | morekeywords=[5]{% 98 | enumeration, 99 | events, 100 | methods, 101 | properties, 102 | }, 103 | keywordstyle=[5]\processMidClassdefKW@mlpr, 104 | morekeywords=[6]{end}, 105 | keywordstyle=[6]\processEndKW@mlpr, 106 | morestring=[m]', 107 | stringstyle=\processString@mlpr, 108 | morecomment=[l]\%, 109 | morecomment=[n]{\%\{\^^M}{\%\}\^^M}, 110 | commentstyle=\commentStyle@mlpr, 111 | moredelim=**[il][\processDotDotDot@mlpr]{...}, 112 | moredelim=[l][\processSectionTitle@mlpr]{\%\%\ }, 113 | moredelim=[l][\syscomStyle@mlpr]!, 114 | }[ 115 | keywords, 116 | strings, 117 | comments, 118 | ] 119 | \newcount\netBracketCount@mlpr 120 | \newcount\blkLvl@mlpr 121 | \newcount\blkLvlAtClassdef@mlpr 122 | \newif\ifClosingEndKW@mlpr@ \ClosingEndKW@mlpr@true 123 | \newif\ifInClassdef@mlpr@ \InClassdef@mlpr@false 124 | \newif\ifInStr@mlpr@ \InStr@mlpr@false 125 | \newif\ifVisCharOccured@mlpr@\VisCharOccured@mlpr@false 126 | \newif\ifInSecTitle@mlpr@ \InSecTitle@mlpr@false 127 | \newif\ifDroppingOutput@mlpr@\DroppingOutput@mlpr@false 128 | \newcommand\resetEndKW@mlpr{% 129 | \global\ClosingEndKW@mlpr@true% 130 | \global\netBracketCount@mlpr=0% 131 | } 132 | \newcommand\resetClassdefKW@mlpr{% 133 | \global\InClassdef@mlpr@false% 134 | \global\blkLvl@mlpr=0% 135 | \global\blkLvlAtClassdef@mlpr=0% 136 | } 137 | \newcommand\MoreSelectCharTable@mlpr{% 138 | \processOpenBracket@mlpr{`(}{\roundBktOp@mlpr}% 139 | \processOpenBracket@mlpr{`[}{\squareBktOp@mlpr}% 140 | \processOpenBracket@mlpr{`\{}{\curlyBktOp@mlpr}% 141 | \processCloseBracket@mlpr{`)}{\roundBktCl@mlpr}% 142 | \processCloseBracket@mlpr{`]}{\squareBktCl@mlpr}% 143 | \processCloseBracket@mlpr{`\}}{\curlyBktCl@mlpr}% 144 | \processSemicolon@mlpr{`;}{\semicolon@mlpr}% 145 | } 146 | \newcommand\processOpenBracket@mlpr[2]{% 147 | \lst@DefSaveDef{#1}#2{% 148 | #2% 149 | \ifnum\lst@mode=\lst@Pmode\relax% 150 | \global\ClosingEndKW@mlpr@false% 151 | \global\advance\netBracketCount@mlpr by \@ne% 152 | \fi 153 | }% 154 | } 155 | \newcommand\processCloseBracket@mlpr[2]{% 156 | \lst@DefSaveDef{#1}#2{% 157 | #2% 158 | \ifnum\lst@mode=\lst@Pmode\relax% 159 | \ifClosingEndKW@mlpr@% 160 | \netBracketCount@mlpr=0% 161 | \else 162 | \global\advance\netBracketCount@mlpr by \m@ne% 163 | \ifnum\netBracketCount@mlpr>0% 164 | \else 165 | \global\ClosingEndKW@mlpr@true% 166 | \fi 167 | \fi 168 | \fi 169 | }% 170 | } 171 | \newcommand\processSemicolon@mlpr[2]{% 172 | \lst@DefSaveDef{#1}#2{% 173 | #2% 174 | \ifnum\lst@mode=\lst@Pmode\relax% 175 | \resetEndKW@mlpr% 176 | \fi 177 | }% 178 | } 179 | \newcommand\processOpRegKW@mlpr{% 180 | \resetEndKW@mlpr% 181 | \global\advance\blkLvl@mlpr\@ne% 182 | \keywordStyle@mlpr% 183 | } 184 | \newcommand\processMidKW@mlpr{% 185 | \resetEndKW@mlpr% 186 | \keywordStyle@mlpr% 187 | } 188 | \newcommand\processStdaKW@mlpr\processMidKW@mlpr 189 | \newcommand\processClassdefKW@mlpr{% 190 | \resetEndKW@mlpr% 191 | \global\InClassdef@mlpr@true% 192 | \global\blkLvlAtClassdef@mlpr=\blkLvl@mlpr% 193 | \global\advance\blkLvl@mlpr\@ne% 194 | \keywordStyle@mlpr% 195 | } 196 | \newcommand\processMidClassdefKW@mlpr{% 197 | \ifOverridecontext@mlpr@% 198 | \keywordStyle@mlpr% 199 | \else 200 | \ifInClassdef@mlpr@% 201 | \resetEndKW@mlpr% 202 | \global\advance\blkLvl@mlpr\@ne% 203 | \keywordStyle@mlpr% 204 | \fi 205 | \fi 206 | } 207 | \newcommand\processEndKW@mlpr{% 208 | \ifOverridecontext@mlpr@% 209 | \lastElemStyle@mlpr% 210 | \else 211 | \ifClosingEndKW@mlpr@% 212 | \ifnum\blkLvl@mlpr>0% 213 | \global\advance\blkLvl@mlpr\m@ne% 214 | \fi 215 | \ifnum\blkLvl@mlpr=\blkLvlAtClassdef@mlpr% 216 | \global\InClassdef@mlpr@false% 217 | \fi 218 | \keywordStyle@mlpr% 219 | \else 220 | \lastElemStyle@mlpr% 221 | \fi 222 | \fi 223 | } 224 | \newcommand\processString@mlpr{% 225 | \global\InStr@mlpr@true% 226 | \stringStyle@mlpr% 227 | } 228 | \newcommand\processDotDotDot@mlpr{% 229 | \lst@CalcLostSpaceAndOutput% 230 | {\keywordStyle@mlpr...}% 231 | \lst@modetrue% 232 | \lst@Lmodetrue% 233 | \commentStyle@mlpr% 234 | } 235 | \newlength\emHeight@mlpr 236 | \newlength\jayDepth@mlpr 237 | \newlength\sectionRuleOffset@mlpr 238 | \newcommand\processSectionTitle@mlpr{% 239 | \ifInSecTitle@mlpr@% 240 | \sectionTitleStyle@mlpr% 241 | \else 242 | \ifVisCharOccured@mlpr@% 243 | \commentStyle@mlpr% 244 | \else % a section title is starting here 245 | \global\InSecTitle@mlpr@true% 246 | \resetEndKW@mlpr% 247 | \ifShowSectRules@mlpr@% 248 | \drawSectionRule@mlpr% 249 | \fi 250 | \sectionTitleStyle@mlpr% 251 | \fi 252 | \fi 253 | } 254 | \newcommand\drawSectionRule@mlpr{% 255 | \setlength\emHeight@mlpr{\fontcharht\font`M}% 256 | \setlength\jayDepth@mlpr{\fontchardp\font`j}% 257 | \setlength\sectionRuleOffset@mlpr{% 258 | \dimexpr.5\emHeight@mlpr% 259 | +.5\baselineskip% 260 | -.5\jayDepth@mlpr\relax% 261 | }% 262 | \bgroup% 263 | \color{\sectionRuleColor@mlpr}% 264 | \makebox[0em][l]{% 265 | \raisebox{\sectionRuleOffset@mlpr}[0pt][0pt]% 266 | {\rule{\lst@linewidth}{\sectionRuleRT@mlpr\baselineskip}}% 267 | }% 268 | \egroup% 269 | } 270 | \newcommand\localFontSize@mlpr{} 271 | \newcommand\localBaselineskip@mlpr{} 272 | \newcommand\scaleInlineCode@mlpr{% 273 | \lst@ifdisplaystyle% 274 | \else 275 | \ifScaleInline@mlpr@% 276 | \let\localFontSize@mlpr\f@size% 277 | \let\localBaselineskip@mlpr\f@baselineskip% 278 | \expandafter\def\expandafter\lst@basicstyle\expandafter{% 279 | \lst@basicstyle% 280 | \fontsize{\localFontSize@mlpr}{\localBaselineskip@mlpr}% 281 | \selectfont% 282 | }% 283 | \fi 284 | \fi 285 | } 286 | \newcommand\dropOutputAfterHeader@mlpr{% 287 | \ifonlyheader@mlpr@% 288 | \ifnum\lst@lineno>1% 289 | \lst@ifLmode% 290 | \else 291 | \ifDroppingOutput@mlpr@% 292 | \else 293 | \lst@EnterMode\lst@Pmode{}% 294 | \lst@BeginDropOutput\lst@Pmode% 295 | \fi 296 | \global\DroppingOutput@mlpr@true% 297 | \fi 298 | \fi 299 | \fi 300 | } 301 | \newcommand\addedToInitVarsEOL@mlpr{} 302 | \lst@AddToHook{InitVarsEOL}{\addedToInitVarsEOL@mlpr} 303 | \newcommand\@ddedToInitVarsEOL@mlpr{% 304 | \ifInStr@mlpr@% 305 | \global\InStr@mlpr@false% 306 | \lst@LeaveMode% 307 | \fi 308 | \global\InSecTitle@mlpr@false% 309 | \global\VisCharOccured@mlpr@false% 310 | } 311 | \newcommand\addedToEndGroup@mlpr{} 312 | \lst@AddToHook{EndGroup}{\addedToEndGroup@mlpr} 313 | \newcommand\@ddedToEndGroup@mlpr{\global\InStr@mlpr@false} 314 | \newcommand\addedToPostOutput@mlpr{} 315 | \lst@AddToHook{PostOutput}{\addedToPostOutput@mlpr} 316 | \newcommand\@ddedToPostOutput@mlpr{% 317 | \lst@ifwhitespace% 318 | \else 319 | \global\VisCharOccured@mlpr@true% 320 | \fi 321 | } 322 | \newcommand\addedToOutput@mlpr{} 323 | \lst@AddToHook{Output}{\addedToOutput@mlpr} 324 | \newcommand\@ddedToOutput@mlpr{\dropOutputAfterHeader@mlpr} 325 | \newcommand\addedToOutputOther@mlpr{} 326 | \lst@AddToHook{OutputOther}{\addedToOutputOther@mlpr} 327 | \newcommand\@ddedToOutputOther@mlpr{\dropOutputAfterHeader@mlpr} 328 | \newcommand\addedToPreInitHook@mlpr{% 329 | \ifx\lst@language\languageNormedDefd@mlpr% 330 | \scaleInlineCode@mlpr% 331 | \renewcommand\addedToInitVarsEOL@mlpr\@ddedToInitVarsEOL@mlpr% 332 | \renewcommand\addedToEndGroup@mlpr\@ddedToEndGroup@mlpr% 333 | \renewcommand\addedToPostOutput@mlpr\@ddedToPostOutput@mlpr% 334 | \renewcommand\addedToOutput@mlpr\@ddedToOutput@mlpr% 335 | \renewcommand\addedToOutputOther@mlpr\@ddedToOutputOther@mlpr% 336 | \DroppingOutput@mlpr@false% 337 | \fi 338 | } 339 | \lst@AddToHook{PreInit}{\addedToPreInitHook@mlpr} 340 | \newcommand\addedToDeInitHook@mlpr{% 341 | \ifx\lst@language\languageNormedDefd@mlpr% 342 | \resetEndKW@mlpr% 343 | \resetClassdefKW@mlpr% 344 | \global\InStr@mlpr@false% 345 | \global\VisCharOccured@mlpr@false% 346 | \global\InSecTitle@mlpr@false% 347 | \global\DroppingOutput@mlpr@false% 348 | \fi 349 | } 350 | \lst@AddToHook{DeInit}{\addedToDeInitHook@mlpr} 351 | \newcommand\keywordStyle@mlpr{} 352 | \lst@Key{mlkeywordstyle}\relax% 353 | {\renewcommand\keywordStyle@mlpr{#1}} 354 | \newcommand\lastElemStyle@mlpr{} 355 | \lst@Key{mllastelementstyle}\relax% 356 | {\renewcommand\lastElemStyle@mlpr{#1}} 357 | \lst@Key{mloverride}{false}[t]% 358 | {\lstKV@SetIf{#1}\ifOverridecontext@mlpr@} 359 | \newcommand\stringStyle@mlpr{} 360 | \lst@Key{mlstringstyle}\relax% 361 | {\renewcommand\stringStyle@mlpr{#1}} 362 | \newcommand\commentStyle@mlpr{} 363 | \lst@Key{mlcommentstyle}\relax% 364 | {\renewcommand\commentStyle@mlpr{#1}} 365 | \newcommand\sectionTitleStyle@mlpr{} 366 | \lst@Key{mlsectiontitlestyle}\relax 367 | {\renewcommand\sectionTitleStyle@mlpr{#1}} 368 | \lst@Key{mlshowsectionrules}{false}[t]% 369 | {\lstKV@SetIf{#1}\ifShowSectRules@mlpr@} 370 | \newcommand\sectionRuleRT@mlpr{.05} 371 | \lst@Key{mlsectionrulethickness}\relax% 372 | {\renewcommand\sectionRuleRT@mlpr{#1}} 373 | \newcommand\sectionRuleColor@mlpr{black!15} 374 | \lst@Key{mlsectionrulecolor}\relax% 375 | {\renewcommand\sectionRuleColor@mlpr{#1}} 376 | \newcommand\syscomStyle@mlpr{} 377 | \lst@Key{mlsyscomstyle}\relax% 378 | {\renewcommand\syscomStyle@mlpr{#1}} 379 | \gdef\InstallKeywords@mlpr#1#2#3#4#5{% 380 | \lst@Key{ml#2}\relax 381 | {\lst@UseFamily{#2}[\@ne]##1\relax\lst@MakeKeywords}% 382 | \lst@Key{mlmore#2}\relax 383 | {\lst@UseFamily{#2}[\@ne]##1\relax\lst@MakeMoreKeywords}% 384 | \lst@Key{mldelete#2}\relax 385 | {\lst@UseFamily{#2}[\@ne]##1\relax\lst@DeleteKeywords}% 386 | \ifx\@empty#3\@empty\else 387 | \lst@Key{#3}{#4}{\@namedef{lst@#3}{##1}}% 388 | \fi 389 | \expandafter\lst@InstallFamily@ 390 | \csname\@lst @#2@data\expandafter\endcsname 391 | \csname\@lst @#5\endcsname {#1}{#2}{#3} 392 | } 393 | \InstallKeywords@mlpr k{sharedvars}{mlsharedvarstyle}\relax% 394 | {mlsharedvarstyle}{}ld 395 | \lst@Key{mlunquotedstringdelim}\relax% 396 | {\lst@DelimKey\relax{[is][\stringStyle@mlpr]{#1}}} 397 | \newcommand\phStyle@mlpr{} 398 | \lst@Key{mlplaceholderstyle}\relax% 399 | {\renewcommand\phStyle@mlpr{#1}} 400 | \lst@Key{mlscaleinline}{true}[t]% 401 | {\lstKV@SetIf{#1}\ifScaleInline@mlpr@} 402 | \lst@Key{mlonlyheader}{false}[t]% 403 | {\lstKV@SetIf{#1}\ifonlyheader@mlpr@} 404 | \newcommand\mlttfamily{% 405 | \def\fvm@Scale{.85}% 406 | \fontfamily{fvm}\selectfont% 407 | } 408 | \newcommand\mlplaceholder[1]{% 409 | \bgroup% 410 | \phStyle@mlpr% 411 | \bgroup% 412 | \phDelimStyle@mlpr% 413 | \phOpDelim@mlpr% 414 | \egroup% 415 | #1\itcorr@mlpr% 416 | \bgroup% 417 | \phDelimStyle@mlpr% 418 | \phClDelim@mlpr% 419 | \egroup% 420 | \egroup% 421 | } 422 | \newcommand\phDelimStyle@mlpr{\rmfamily\upshape} 423 | \newcommand\phOpDelim@mlpr{\textlangle} 424 | \newcommand\phClDelim@mlpr{\textrangle} 425 | \newcommand\itcorr@mlpr{% 426 | \expandafter\newcommand\expandafter\long@f@shape@mlpr% 427 | \expandafter{\f@shape}% 428 | \ifx\long@f@shape@mlpr\itdefault% 429 | \/% 430 | \else 431 | \ifx\long@f@shape@mlpr\sldefault% 432 | \/% 433 | \fi 434 | \fi 435 | } 436 | \newtoks\toks@mlpr 437 | \toks@mlpr={% 438 | language = \languageNormedDefd@mlpr, 439 | basicstyle = \color{black}\ttfamily\normalsize, 440 | breaklines = true, 441 | showspaces = false, 442 | showstringspaces = false, 443 | upquote = true, 444 | rulecolor = \color{black!67}, 445 | numberstyle = \color{black!33}, 446 | mlscaleinline = true, 447 | mlonlyheader = false, 448 | } 449 | \ifframed@mlpr@ 450 | \toks@mlpr=\expandafter{\the\toks@mlpr frame=single,} 451 | \fi 452 | \ifnumbered@mlpr@ 453 | \toks@mlpr=\expandafter{\the\toks@mlpr numbers=left,} 454 | \fi 455 | \begingroup\edef\@tempa{\endgroup 456 | \noexpand\lstdefinestyle{MatlabBaseStyle@mlpr}{\the\toks@mlpr} 457 | }\@tempa 458 | \newcommand\mleditorphstyle{\color[RGB]{209,000,086}\rmfamily\itshape} 459 | \lstdefinestyle{Matlab-editor}{% 460 | style = MatlabBaseStyle@mlpr, 461 | mllastelementstyle = \color{black} , 462 | mlkeywordstyle = \color[RGB]{000,000,255} , 463 | mlcommentstyle = \color[RGB]{034,139,034} , 464 | mlstringstyle = \color[RGB]{160,032,240} , 465 | mlsyscomstyle = \color[RGB]{178,140,000} , 466 | mlsectiontitlestyle = \commentStyle@mlpr \bfseries, 467 | mlsharedvarstyle = \color[RGB]{000,163,163} , 468 | mlplaceholderstyle = \mleditorphstyle, 469 | } 470 | \newcommand\mlbwphstyle{\color[gray]{0}\rmfamily\itshape} 471 | \lstdefinestyle{Matlab-bw}{% 472 | style = MatlabBaseStyle@mlpr, 473 | mlkeywordstyle = \color[gray]{0} \bfseries , 474 | mlcommentstyle = \color[gray]{.75} \itshape, 475 | mlstringstyle = \color[gray]{.5} , 476 | mlsyscomstyle = \color[gray]{.25} , 477 | mlsectiontitlestyle = \color[gray]{.75}\bfseries\itshape, 478 | mlsharedvarstyle = \color[gray]{0} , 479 | mlplaceholderstyle = \mlbwphstyle, 480 | } 481 | \newcommand\mlpyglikephstyle{\color[RGB]{127,063,127}\rmfamily\itshape} 482 | \lstdefinestyle{Matlab-Pyglike}{% 483 | style = MatlabBaseStyle@mlpr, 484 | mllastelementstyle = \color[RGB]{127,000,000} , 485 | mlkeywordstyle = \color[RGB]{000,127,000}\bfseries , 486 | mlcommentstyle = \color[RGB]{063,127,127} \itshape, 487 | mlstringstyle = \color[RGB]{186,034,034} , 488 | mlsyscomstyle = \color[RGB]{000,127,000} , 489 | mlsectiontitlestyle = \color[RGB]{063,127,127} \itshape, 490 | mlsharedvarstyle = \color[RGB]{034,034,186} , 491 | mlplaceholderstyle = \mlpyglikephstyle, 492 | } 493 | \endinput 494 | %% 495 | %% End of file `matlab-prettifier.sty'. 496 | -------------------------------------------------------------------------------- /matlab-prettifier.dtx: -------------------------------------------------------------------------------- 1 | % \iffalse meta-comment 2 | % 3 | % Copyright (C) 2014 by Julien Cretel 4 | % 5 | % 6 | % This work may be distributed and/or modified under the 7 | % conditions of the LaTeX Project Public License, either version 1.3 8 | % of this license or (at your option) any later version. 9 | % The latest version of this license is in 10 | % 11 | % http://www.latex-project.org/lppl.txt 12 | % 13 | % and version 1.3 or later is part of all distributions of LaTeX 14 | % version 2005/12/01 or later. 15 | % 16 | % \fi 17 | % 18 | % \iffalse 19 | %\NeedsTeXFormat{LaTeX2e}[2011/06/27] 20 | %\ProvidesPackage{matlab-prettifier} 21 | % [2014/06/19 v0.3 A package for prettyprinting Matlab source code] 22 | % 23 | %<*driver> 24 | \documentclass[a4paper]{ltxdoc} 25 | \EnableCrossrefs 26 | \CodelineIndex 27 | \RecordChanges 28 | 29 | \usepackage[T1]{fontenc} 30 | \usepackage{lmodern} 31 | \usepackage{xcolor} 32 | \usepackage{lstdoc} 33 | \usepackage[framed,numbered]{matlab-prettifier} 34 | \usepackage{hyperref} 35 | \usepackage{url} 36 | \usepackage{cleveref} 37 | 38 | \DeclareUrlCommand\email{\urlstyle{tt}} 39 | \lstset{% 40 | style = Matlab-editor, 41 | basicstyle = \normalsize\mlttfamily, 42 | upquote = true, 43 | mlunquotedstringdelim = {/*}{*/}, 44 | mlmoresharedvars = {myglobalvar}, 45 | } 46 | \lstdefinestyle{nonbnoframe}{% 47 | frame = none, 48 | numbers = none, 49 | } 50 | \lstMakeShortInline" 51 | \newcommand\ph\mlplaceholder 52 | \newcommand*{\pkg}[1]{\textsf{#1}} 53 | \newcommand*{\opt}[1]{\texttt{#1}} 54 | \newcommand\lstpkg{\pkg{listings}} 55 | \newcommand*{\lststy}[1]{\texttt{#1}} 56 | \newcommand*{\lstlng}[1]{\texttt{#1}} 57 | \newcommand\matlab{\textsc{Matlab}} 58 | \newcommand\octave{\textsc{Octave}} 59 | \newcommand\matlabver{\matlab~(R2013a)} 60 | \newcommand\mathworks{MathWorks} 61 | \newcommand*\trademark[1]{#1\textsuperscript{\textregistered}} 62 | \newcommand\mlpkg{\pkg{matlab-prettifier}} 63 | \newcommand\mllng{\texttt{Matlab-pretty}} 64 | \newcommand*{\mlsty}[1]{\texttt{#1}} 65 | \newcommand\overrideEnd{\lstinline[mloverride]|end|} 66 | \newcommand\overrideEnumeration{\lstinline[mloverride]|enumeration|} 67 | \newcommand\overrideMethods{\lstinline[mloverride]|methods|} 68 | \newcommand\overrideProperties{\lstinline[mloverride]|properties|} 69 | \newcommand\overrideEvents{\lstinline[mloverride]|events|} 70 | \newcommand\itemp{\item[\(+\)]} 71 | \newcommand\itemm{\item[\(-\)]} 72 | 73 | \makeindex 74 | 75 | \begin{document} 76 | \DocInput{matlab-prettifier.dtx} 77 | \end{document} 78 | % 79 | % \fi 80 | % 81 | % \CheckSum{671} 82 | % 83 | % \CharacterTable 84 | % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z 85 | % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z 86 | % Digits \0\1\2\3\4\5\6\7\8\9 87 | % Exclamation \! Double quote \" Hash (number) \# 88 | % Dollar \$ Percent \% Ampersand \& 89 | % Acute accent \' Left paren \( Right paren \) 90 | % Asterisk \* Plus \+ Comma \, 91 | % Minus \- Point \. Solidus \/ 92 | % Colon \: Semicolon \; Less than \< 93 | % Equals \= Greater than \> Question mark \? 94 | % Commercial at \@ Left bracket \[ Backslash \\ 95 | % Right bracket \] Circumflex \^ Underscore \_ 96 | % Grave accent \` Left brace \{ Vertical bar \| 97 | % Right brace \} Tilde \~} 98 | % 99 | % \changes{v0.1}{2014/04/24}{Initial release.} 100 | % \changes{v0.2}{2014/04/25}{% 101 | % Refactor code extensively; 102 | % rewrite automatic scaling of inline code; 103 | % implement mlscaleinline key; 104 | % implement mlonlyheader. 105 | % } 106 | % \changes{v0.3}{2014/06/19}{% 107 | % Change default font from Bera Mono to Computer Modern typewriter 108 | % (for compatibility reasons); 109 | % fix bug (end keyword now gets reset by a semicolon); 110 | % rename placeholder user macro; 111 | % mention support for a subset of Octave's syntax. 112 | % } 113 | % 114 | % \GetFileInfo{matlab-prettifier.sty} 115 | % 116 | % ^^A see http://www.latex-project.org/cgi-bin/ltxbugs2html?pr=latex%2F3540 117 | % \begingroup 118 | % \def\x{\#,\$,\%,\^,\_,\~,\&,\{,\},\/}%^^A 119 | % \makeatletter 120 | % \@onelevel@sanitize\x 121 | % \expandafter\endgroup\expandafter\DoNotIndex\expandafter{\x} 122 | % 123 | % \begingroup 124 | % \makeatletter 125 | % \lccode`9=32\relax 126 | % \lowercase{%^^A 127 | % \edef\x{\noexpand\DoNotIndex{\@backslashchar9}}%^^A 128 | % }%^^A 129 | % \expandafter\endgroup\x 130 | % 131 | % \DoNotIndex{\@empty,\@ifpackagewith,\@lst,\@namedef,\@ne,\@tempa} 132 | % \DoNotIndex{\advance} 133 | % \DoNotIndex{\baselineskip,\begingroup,\bfseries,\bgroup} 134 | % \DoNotIndex{\ClosingEndKW@mlpr@false,\ClosingEndKW@mlpr@true,^^A 135 | % \color,\colorlet,\csname,\CurrentOption} 136 | % \DoNotIndex{\DeclareOption,\def,\definecolor,\dimexpr,^^A 137 | % \DroppingOutput@mlpr@false,\DroppingOutput@mlpr@true} 138 | % \DoNotIndex{\edef,\egroup,\else,\endcsname,\endgroup,\expandafter} 139 | % \DoNotIndex{\f@baselineskip,\f@shape,\f@size,\fi,\font,\fontsize,^^A 140 | % \fontchardp,\fontcharht,\fontfamily,\framed@mlpr@true,\fvm@Scale} 141 | % \DoNotIndex{\gdef,\global} 142 | % \DoNotIndex{\ifnum,\ifx,^^A 143 | % \InClassdef@mlpr@false,\InClassdef@mlpr@true,^^A 144 | % \InSecTitle@mlpr@false,\InSecTitle@mlpr@true,^^A 145 | % \InStr@mlpr@false,\InStr@mlpr@true,^^A 146 | % \itdefault,\itshape} 147 | % \DoNotIndex{\let,\lst@basicstyle,\lst@BeginDropOutput,\lst@AddToHook,^^A 148 | % \lst@CalcLostSpaceAndOutput,\lst@DefSaveDef,\lst@DelimKey,^^A 149 | % \lst@EnterMode,\lst@ifdisplaystyle,\lst@ifLmode,\lst@ifwhitespace,^^A 150 | % \lst@InstallKeywords,\lst@Key,\lst@language,\lst@LeaveMode,^^A 151 | % \lst@lineno,\lst@linewidth,\lst@Lmodetrue,\lst@mode,\lst@modetrue,^^A 152 | % \lst@NormedDef,\lst@Pmode,\lst@DeleteKeywords,\lst@InstallFamily@,^^A 153 | % \lst@MakeKeywords,\lst@MakeMoreKeywords,\lst@UseFamily,^^A 154 | % \lstdefinelanguage,\lstdefinestyle,\lstKV@SetIf} 155 | % \DoNotIndex{\m@ne,\makebox} 156 | % \DoNotIndex{\newcommand,\newcount,\newif,\newlength,\newtoks,\normalsize,^^A 157 | % \numbered@mlpr@true,\noexpand} 158 | % \DoNotIndex{\OptionNotUsed} 159 | % \DoNotIndex{\PackageError,\PackageWarning,\ProcessOptions} 160 | % \DoNotIndex{\raisebox,\relax,\renewcommand,\RequirePackage,\rule,\rmfamily} 161 | % \DoNotIndex{\selectfont,\setlength,\sldefault,\textlangle,\textrangle,^^A 162 | % \ttfamily} 163 | % \DoNotIndex{\the} 164 | % \DoNotIndex{\upshape} 165 | % \DoNotIndex{\VisCharOccured@mlpr@true,\VisCharOccured@mlpr@false} 166 | % 167 | % \title^^A 168 | % {^^A 169 | % The \mlpkg{} package^^A 170 | % \thanks^^A 171 | % {^^A 172 | % This document corresponds to \mlpkg~\fileversion, 173 | % dated~\filedate.^^A 174 | % }^^A 175 | % } 176 | % \author{Julien Cretel\\ \texttt{jubobs.tex at gmail.com}} 177 | % \date{\filedate} 178 | % \thispagestyle{empty} 179 | % \maketitle 180 | % 181 | % \begin{abstract} 182 | % Built on top of the \lstpkg{} package, the \mlpkg{} package allows you to 183 | % effortlessly prettyprint \matlab{} source code in documents typeset with 184 | % \LaTeX{} \& friends. Three predefined styles, one of which closely mimics 185 | % that of the \matlab{} editor, are available and can be invoked by 186 | % \lstpkg{} macros and environments in conjunction with (most) options 187 | % provided by the \lstpkg{} package. The appearance of your \matlab{} 188 | % listings can be further tweaked via a key-value interface extending that 189 | % of \lstpkg{}'. Partial support for Octave syntax is provided. 190 | % \end{abstract} 191 | % 192 | % \tableofcontents\newpage 193 | % 194 | % 195 | % \part{Introduction} 196 | % 197 | % \section{Why this package?} 198 | % 199 | % \trademark{\matlab} is a high-level language and interactive environment for 200 | % numerical computation, visualization, and programming.^^A 201 | % \footnote{Source: \url{http://www.mathworks.co.uk/products/matlab/}} 202 | % Despite being proprietary and occasionally frustrating, \matlab{} remains a 203 | % great tool for prototyping matrix-oriented, number-crunching programs. 204 | % As such, it enjoys widespread popularity, especially in academia, 205 | % where, in particular, it is often used for teaching numerical methods. 206 | % 207 | % Users of both \matlab{} and \LaTeX{} (and friends) often need to typeset 208 | % \matlab{} listings in \LaTeX{} documents, usually with some syntax 209 | % highlighting, for improved code readability; 210 | % the relatively large number of relevant questions posted on 211 | % \href{http://tex.stackexchange.com/search?q=matlab+code+is%3Aquestion}^^A 212 | % {tex.stackexchange.com} attests to that need. 213 | % 214 | % Recent versions of \matlab{} provide a built-in function, called "publish", 215 | % that can generate \LaTeX{} code for typesetting \matlab{} listings, but 216 | % that function uses a |verbatim| environment, which doesn't allow for any 217 | % fancy formatting. 218 | % Several \LaTeX{} packages^^A 219 | % ---vanilla \lstpkg{}, \pkg{mcode}, and \pkg{minted}, among others---^^A 220 | % allow for automatic syntax highlighting of \matlab{} listings in \LaTeX{} 221 | % documents. 222 | % However, none of those packages do a great job at replicating the very 223 | % specific syntax-highlighting style performed on the fly by the \matlab{} 224 | % editor.^^A 225 | % \footnote{see ... for a comparison.} 226 | % 227 | % The lack of tools for faithfully mimicking the style of the \matlab{} 228 | % editor is unfortunate, especially from an educational standpoint, for the 229 | % following reason. 230 | % Most newcomers to \matlab{} read and write code in the \matlab{} editor 231 | % and are, therefore, continually exposed to its highlighting style. 232 | % Visual cues^^A 233 | % ---such as those provided by syntax highlighting---^^A 234 | % play an important role for recognising patterns, 235 | % and students of a programming language are more likely to quickly and 236 | % effectively learn and recognize its syntax if they see it highlighted in a 237 | % consistent manner, whether it be in a text editor or in some course material 238 | % (lab handout, assignment paper, etc.). 239 | % 240 | % The \mlpkg{} package is intended to fill that gap. 241 | % Built on top of the feature-rich \lstpkg{} package, \mlpkg{} allows you to 242 | % beautifully and effortlessly typeset \matlab{} listings, as it configures 243 | % \lstpkg{} ``behind the scenes'' to replicate, as closely as possible, the 244 | % syntax-highlighting style of the \matlab{} editor. 245 | % 246 | % What about code written in \octave{} (a free alternative to \matlab{})? 247 | % Because \octave{}'s syntax and \matlab{}'s syntax 248 | % \href{http://wiki.octave.org/FAQ#How_is_Octave_different_from_Matlab.3F} 249 | % {overlap a lot}, 250 | % \mlpkg{} correctly highlights \octave{} listings that strictly adhere to 251 | % the subset of syntax that lies in this overlap. 252 | % More support for \octave{} is expected to ship with a future release. 253 | % 254 | % Furthermore, \mlpkg{} comes with a few additional features that should make 255 | % your life easier. Read on! 256 | % 257 | % 258 | % \section{Review of alternatives to \mlpkg{}} 259 | % 260 | % Here is a review of the different alternatives^^A 261 | % ---other than the \mlpkg{} package and \matlab{}'s "publish" function---^^A 262 | % available for typesetting \matlab{} listings in \LaTeX{} documents. 263 | % 264 | % \paragraph{\lstpkg{}' \lstlng{Matlab} language} 265 | %^^A 266 | % \begin{itemize} 267 | % \itemp A starting point! 268 | % \itemp \lstpkg{}' rich features are available. 269 | % \itemp Settings for \matlab{} listings are bundled into a \lstpkg{} 270 | % language, which can be invoked \emph{locally}. 271 | % \itemm Some \matlab{} keywords (e.g.\ "parfor") are not listed. 272 | % \itemm Built-in \matlab{} function names (e.g.\ "sum") get highlighted 273 | % like \matlab{} keywords do, which is very distracting. 274 | % \itemm Highlighting of keywords is not context-aware; 275 | % in particular, the |end| keyword gets typeset in the same style, 276 | % regardless of the context (closing keyword or last-element keyword) 277 | % in which it occurs. 278 | % \itemm No highlighting of block comments 279 | % \itemm No highlighting of line-continuation token and associated comment 280 | % \itemm Section titles are not highlighted in a style distinct from that of 281 | % comments. 282 | % \itemm No highlighting of unquoted strings 283 | % \end{itemize} 284 | % 285 | % \paragraph{\pkg{mcode}} 286 | %^^A 287 | % \begin{itemize} 288 | % \itemp An honest attempt at improving \lstpkg{}' \lstlng{Matlab} language 289 | % \itemp Package options for quickly effecting global changes to the look 290 | % of \matlab{} listings 291 | % \itemp Block comments are highlighted as such. 292 | % \itemp A line-continuation token activates comment style\ldots 293 | % \itemm \ldots but also gets highlighted in comment style. 294 | % \itemm Settings for \matlab{} listings are defined \emph{globally} 295 | % (using |\lstset|) rather than locally, 296 | % which means those settings can easily be overwritten/lost. 297 | % \itemm The \overrideEnumeration{} keyword is not listed. 298 | % \itemm Highlighting of the last-element keyword is handled by a series of 299 | % literate replacements; 300 | % this approach works well only in a limited number of cases in which 301 | % that keyword occurs. 302 | % \itemm Highlighting of the four context-sensitive class-definition 303 | % keywords is not context-aware; 304 | % in particular, |properties| gets typeset in the same style, 305 | % regardless of the context (function or class-definition keyword) 306 | % in which it occurs. 307 | % \itemm Undesirable literate replacements 308 | % ("<=" by~\(\leq\), "delta" by~\(\Delta\)) are forced upon the users, 309 | % and cannot be easily prevented without breaking other literate 310 | % replacements put in place for highlighting the last-element keyword. 311 | % \itemm Section titles are not highlighted in a style distinct from that of 312 | % comments. 313 | % \itemm No highlighting of unquoted strings 314 | % \itemm \pkg{mcode} is currently not available on 315 | % \href{http://ftp.heanet.ie/pub/CTAN/tex/support/ctanify/ctanify.pdf} 316 | % {CTAN}. 317 | % \end{itemize} 318 | % 319 | % \paragraph{Pygments-based packages 320 | % (\pkg{minted}, \pkg{verbments}, \pkg{pythontex})} 321 | %^^A 322 | % \begin{itemize} 323 | % \itemp Python! 324 | % \itemp Pygments! 325 | % \itemp Slick look 326 | % \itemp Block comments are highlighted as such. 327 | % \itemp A line-continuation token activates comment style\ldots 328 | % \itemm \ldots but also gets highlighted in comment style. 329 | % \itemm \lstpkg{}' features are not available. 330 | % \itemm Highlighting of keywords is not context-aware; 331 | % in particular, the last-element keyword gets highlighted like the 332 | % closing keyword does, which is very distracting. 333 | % \itemm \matlab{}'s transpose operator (".'") and "}'" are incorrectly 334 | % interpreted as starting a string literal. 335 | % \itemm No highlighting of unquoted strings 336 | % \itemm Escape to \LaTeX{} is only allowed in comments. 337 | % \itemm Slow compared to \lstpkg{} 338 | % \itemm Requires |--shell-escape| 339 | % \end{itemize} 340 | % 341 | % 342 | % \section{Syntactic elements automatically highlighted by \mlpkg{}} 343 | % 344 | % The \mlpkg{} package defines a \pkg{listings} language called 345 | % \mllng{}, which is designed to keep track of the context behind the scenes 346 | % and, therefore, facilitates context-sensitive highlighting of various 347 | % elements of \matlab{} syntax. 348 | % That language is used as a basis for three \lstpkg{} styles, 349 | % one of which, called \mlsty{Matlab-editor}, is showcased below. 350 | % 351 | % \paragraph{Context-insensitive keywords} 352 | % "while", "for", "break", etc. 353 | % 354 | % \paragraph{Context-sensitive keywords} 355 | % "end", 356 | % \overrideEvents{}, 357 | % \overrideProperties{}, 358 | % etc. 359 | % 360 | % \paragraph{Quoted strings} 361 | % \mbox{} 362 | % \iffalse 363 | %<*example> 364 | % \fi 365 | \begin{lstlisting}[numbers=none] 366 | 'The sleeper must awaken.' 367 | \end{lstlisting} 368 | % \iffalse 369 | % 370 | % \fi 371 | % 372 | % \paragraph{To-end-of-line and block comments} 373 | % \mbox{} 374 | % \iffalse 375 | %<*example> 376 | % \fi 377 | \begin{lstlisting}[numbers=none] 378 | % Now let's assign the value of pi to variable a 379 | a = pi 380 | %{ 381 | Now that a holds the value of pi, 382 | here is what we're going to do... 383 | blah blah blah 384 | %} 385 | \end{lstlisting} 386 | % \iffalse 387 | % 388 | % \fi 389 | % 390 | % \paragraph{Line-continuation token (and associated to-end-of-line comment)} 391 | % \mbox{} 392 | % \iffalse 393 | %<*example> 394 | % \fi 395 | \begin{lstlisting}[numbers=none] 396 | A = [ 1, 2, 3,... (second row defined on next line) 397 | 4, 5, 6]; 398 | \end{lstlisting} 399 | % \iffalse 400 | % 401 | % \fi 402 | % 403 | % \paragraph{Section titles} 404 | % \mbox{} 405 | % \iffalse 406 | %<*example> 407 | % \fi 408 | \begin{lstlisting}[numbers=none] 409 | %% Variable initialization 410 | \end{lstlisting} 411 | % \iffalse 412 | % 413 | % \fi 414 | % 415 | % \paragraph{System commands} 416 | % \mbox{} 417 | % \iffalse 418 | %<*example> 419 | % \fi 420 | \begin{lstlisting}[numbers=none] 421 | ! gzip sample.m 422 | \end{lstlisting} 423 | % \iffalse 424 | % 425 | % \fi 426 | % 427 | % 428 | % \section{Styles provided by \mlpkg{}} 429 | % 430 | % The package defines three \lstpkg{} \emph{styles} for \matlab{} code: 431 | % \mlsty{Matlab-editor}, \mlsty{Matlab-bw}, and 432 | % \mlsty{Matlab-Pyglike}. 433 | % Those styles differ in terms of color scheme but, for convenience, 434 | % all three activate automatic line breaking; 435 | % for more defails about automatic line breaking, see subsection~4.10 in 436 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation}. 437 | % 438 | % Here is a comparison of the three styles defined by \mlpkg{}. 439 | % 440 | % \paragraph{\mlsty{Matlab-editor}} 441 | % This style mimics the default style of the \matlab{} editor. 442 | % \iffalse 443 | %<*example> 444 | % \fi 445 | \begin{lstlisting}[style=Matlab-editor,basicstyle=\mlttfamily] 446 | %% Sample Matlab code 447 | !mv test.txt test2.txt 448 | A = [1, 2, 3;... foo 449 | 4, 5, 6]; 450 | s = 'abcd'; 451 | for k = 1:4 452 | disp(s(k)) % bar 453 | end 454 | %{ 455 | create row vector x, then reverse it 456 | %} 457 | x = linspace(0,1,101); 458 | y = x(end:-1:1); 459 | \end{lstlisting} 460 | % \iffalse 461 | % 462 | % \fi 463 | % 464 | % \paragraph{\mlsty{Matlab-bw}} 465 | % This style is mainly for black \& white printing. 466 | % \iffalse 467 | %<*example> 468 | % \fi 469 | \begin{lstlisting}[style=Matlab-bw,basicstyle=\mlttfamily] 470 | %% Sample Matlab code 471 | !mv test.txt test2.txt 472 | A = [1, 2, 3;... foo 473 | 4, 5, 6]; 474 | s = 'abcd'; 475 | for k = 1:4 476 | disp(s(k)) % bar 477 | end 478 | %{ 479 | create row vector x, then reverse it 480 | %} 481 | x = linspace(0,1,101); 482 | y = x(end:-1:1); 483 | \end{lstlisting} 484 | % \iffalse 485 | % 486 | % \fi 487 | % 488 | % \paragraph{\mlsty{Matlab-Pyglike}} 489 | % The \pkg{minted}, \pkg{verbments}, and \pkg{pythontex} packages all use 490 | % \href{http://pygments.org}{Pygments} lexers for syntax highlighting of 491 | % listings. 492 | % This \mlpkg{} style closely mimics the default style associated with 493 | % Pygments' `MatlabLexer'. 494 | % \iffalse 495 | %<*example> 496 | % \fi 497 | \begin{lstlisting}[style=Matlab-Pyglike,basicstyle=\mlttfamily] 498 | %% Sample Matlab code 499 | !mv test.txt test2.txt 500 | A = [1, 2, 3;... foo 501 | 4, 5, 6]; 502 | s = 'abcd'; 503 | for k = 1:4 504 | disp(s(k)) % bar 505 | end 506 | %{ 507 | create row vector x, then reverse it 508 | %} 509 | x = linspace(0,1,101); 510 | y = x(end:-1:1); 511 | \end{lstlisting} 512 | % \iffalse 513 | % 514 | % \fi 515 | % 516 | % 517 | % \section{Other features} 518 | % 519 | % Additional features include 520 | % 521 | % \begin{itemize} 522 | % \item a key-value interface extending that of the \lstpkg{} package, 523 | % \item manual highlighting of variables with shared scope 524 | % (e.g.\ "myglobalvar"), 525 | % \item manual highlighting of unquoted strings 526 | % (e.g.\ ``on'' in ``"hold /*on*/"''), 527 | % \item a macro for easily typesetting placeholders 528 | % (e.g.\ \ph{initial-value}), 529 | % \item automatic scaling of inline code according to its surroundings, 530 | % \item an option to only print the header of a \matlab{} function. 531 | % \end{itemize} 532 | % 533 | % 534 | % \part{User's guide} 535 | % 536 | % \section{Installation} 537 | % 538 | % \subsection{Package dependencies} 539 | % 540 | % \mlpkg{} requires relatively up-to-date versions of packages \pkg{textcomp}, 541 | % \pkg{xcolor}, and \lstpkg{}, all three of which ship with popular \TeX{} 542 | % distributions. It loads those three packages without any options. 543 | % 544 | % 545 | % \subsection{Installing \mlpkg{}} 546 | % 547 | % Since the package has been officially released on 548 | % \href{http://www.ctan.org/pkg/matlab-prettifier}{CTAN}, 549 | % you should be able to install it directly through your package manager. 550 | % 551 | % However, if you need to install \mlpkg{} manually, you should run 552 | %^^A 553 | % \begin{verbatim} 554 | % latex matlab-prettifier.ins\end{verbatim} 555 | %^^A 556 | % and copy the file called |matlab-prettifier.sty| to a path 557 | % where \LaTeX{} (or your preferred typesetting engine) can find it. 558 | % To generate the documentation, run 559 | %^^A 560 | % \begin{verbatim} 561 | % pdflatex matlab-prettifier.dtx 562 | % makeindex -s gglo.ist -o matlab-prettifier.gls matlab-prettifier.glo 563 | % makeindex -s gind.ist -o matlab-prettifier.ind matlab-prettifier.idx 564 | % pdflatex matlab-prettifier.dtx 565 | % pdflatex matlab-prettifier.dtx\end{verbatim} 566 | %^^A 567 | % 568 | % 569 | % \section{Getting started} 570 | % 571 | % As stated above, the \mlpkg{} package is built on top of the \lstpkg{} 572 | % package. 573 | % If you already are a seasoned \lstpkg{} user, you should feel right at home. 574 | % If you're not, be aware that this user's guide makes use of some \lstpkg{} 575 | % functionalities (such as key-value options) without describing their usage. 576 | % For more details on those functionalities, you should consult the 577 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation}. 578 | % 579 | % 580 | % \subsection{Loading \texorpdfstring{\mlpkg{}}{matlab-prettifier}} 581 | % 582 | % Simply write 583 | %^^A 584 | % \begin{verbatim} 585 | % \usepackage{matlab-prettifier}\end{verbatim} 586 | %^^A 587 | % somewhere in your preamble. 588 | % 589 | % You may want to load the \lstpkg{} and 590 | % \pkg{xcolor} packages with some options; in that case, make sure those 591 | % options are passed to those two packages \emph{before} loading the \mlpkg{} 592 | % package. 593 | % 594 | % The \mlpkg{} package currently offers four options. 595 | % The first two are inspired from the \pkg{mcode} package. 596 | % The last two are simply \lstpkg{} options that \mlpkg{} passes to \lstpkg{} 597 | % behind the scenes; 598 | % I chose to define those two options as \mlpkg{} options to save you 599 | % the hassle of loading them with \lstpkg{} separately, 600 | % should you wish to use them. 601 | %^^A 602 | % \begin{description} 603 | % \item[\opt{framed}]\leavevmode 604 | % 605 | % Draws (by default) a dark gray frame around each listing that uses 606 | % one of the three styles defined by \mlpkg{}. 607 | % 608 | % \item[\opt{numbered}]\leavevmode 609 | % 610 | % Prints (by default) line numbers in light gray to the left of each 611 | % listing that uses one of the three styles defined by \mlpkg{}. 612 | % 613 | % \item[\opt{draft}]\leavevmode 614 | % 615 | % This is simply \lstpkg{}' \opt{draft} option. 616 | % For more details, see subsection~2.2 of the 617 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation}. 618 | % 619 | % \item[\opt{final}]\leavevmode 620 | % 621 | % This is simply \lstpkg{}' \opt{final} option. 622 | % For more details, see subsection~2.2 of the 623 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation}. 624 | % \end{description} 625 | % 626 | % 627 | % \subsection{Displayed listings} 628 | % 629 | % To typeset a \matlab{} listing embedded in your |tex| file, simply enclose 630 | % it in an |lstlisting| environment, and load some style in the environment's 631 | % optional argument, using \lstpkg{}' \keyname{style} key. 632 | %^^A 633 | % \begin{verbatim} 634 | % \begin{lstlisting}[style=Matlab-editor] 635 | % ... 636 | % \end{lstlisting}\end{verbatim} 637 | % 638 | % 639 | % \subsection{Standalone listings} 640 | % 641 | % In practice, though, keeping your \matlab{} listings in external files^^A 642 | % ---rather than embedding them in a |tex|~file---^^A 643 | % is preferable, for maintainability reasons. 644 | % To typeset a \matlab{} listing residing in an m-file, simply invoke the 645 | % |\lstinputlisting| macro; load some style in the environment's 646 | % optional argument, and specify the path to the m-file in question in the 647 | % mandatory argument. 648 | %^^A 649 | % \begin{verbatim} 650 | % \lstinputlisting[style=Matlab-editor]{sample.m}\end{verbatim} 651 | %^^A 652 | % 653 | % 654 | % \subsection{Inline listings} 655 | % 656 | % You may want to typeset fragments of \matlab{} code within the main text of 657 | % your document. For instance, you may want to typeset the "break" keyword in 658 | % a sentence, in order to explain its usage. 659 | % The |\lstinline| macro can be used for typesetting such inline code. 660 | %^^A 661 | % \begin{verbatim} 662 | % \lstinline[style=Matlab-style]!break!\end{verbatim} 663 | %^^A 664 | % Well, that's quite a mouthful for such a simple \matlab{} keyword! 665 | % Writing |\lstinline| for each instance of inline \matlab{} code in your 666 | % document can rapidly become tedious. 667 | % Fortunately, \lstpkg{} allows its users to define a character as a shorthand 668 | % for inline code via the |\lstMakeShortInline| macro. 669 | % For instance, you could define the double-quote character~(|"|) as a 670 | % shorthand for inline \matlab{} code with 671 | %^^A 672 | % \begin{verbatim} 673 | % \lstMakeShortInline[style=Matlab-editor]"\end{verbatim} 674 | %^^A 675 | % and you would then be able to typeset this "break" keyword simply by writing 676 | %^^A 677 | % \begin{verbatim} 678 | % "break"\end{verbatim} 679 | %^^A 680 | % in your |tex| file (but outside displayed listings, of course). 681 | % 682 | % You should choose a character that does not otherwise occur in your 683 | % |tex| file, especially in the inline \matlab{} code itself, 684 | % or you run the risk of confusing \TeX{}. 685 | % I find that, in general, the double-quote character~(|"|) offers a good 686 | % compromise. 687 | % If necessary, you can undefine a character as a shorthand for inline code, 688 | % via \lstpkg{}' |\lstDeleteShortInline| macro. 689 | % For more details, see subsection~4.17 in the \lstpkg{} manual. 690 | % 691 | % 692 | % \subsection{Placeholders} 693 | % 694 | % Code-snippet placeholders, such as \ph{initial-value}, are particularly 695 | % useful for educational purposes, e.g.\ to describe the syntax of a 696 | % programming language to students. 697 | % The following macro allows you to typeset such placeholders, both 698 | % inside and outside listings: 699 | %^^A 700 | % \begin{syntax} 701 | % 702 | % \item[0.1] \rcmdname\mlplaceholder|{|\meta{placeholder content}|}| 703 | % 704 | % typesets a code-snippet placeholder. 705 | % You can use this macro both inside and outside listings. 706 | % When used inside listings, it must be invoked within an 707 | % \emph{escape to \LaTeX{}}; see subsection~4.14 of the \lstpkg{} manual. 708 | % 709 | % \end{syntax} 710 | % 711 | % If you choose to define a single character for escaping to \LaTeX{} (via 712 | % \lstpkg{}' \keyname{escapechar} key), I recommend you define 713 | % either the double-quote character~(|"|) 714 | % or the backtick character~(\texttt{\`{}}) 715 | % as escape character; 716 | % doing so should be relatively safe 717 | % because neither character is allowed in \matlab{} statements and 718 | % expressions^^A 719 | % ---although they may occur in \matlab{} string literals and system commands. 720 | % Note that using~|"| both as shorthand for inline code \emph{and} as an 721 | % escape-to-\LaTeX{} character inside listings is perfectly allowed. 722 | % 723 | % The following example illustrates how placeholders may be used to describe 724 | % the syntax of the \matlab{} while loop. 725 | %^^A 726 | % \begin{lstsample}{}{\lstset{style=nonbnoframe}} 727 | % \begin{lstlisting}[ 728 | % style=Matlab-editor, 729 | % basicstyle=\mlttfamily, 730 | % escapechar=`, 731 | % ] 732 | % while `\mlplaceholder{condition}` 733 | % if `\mlplaceholder{something-bad-happens}` 734 | % break 735 | % else 736 | % % do something useful 737 | % end 738 | % end 739 | % \end{lstlisting} 740 | % \end{lstsample} 741 | % 742 | % For convenience, you can of course define a custom macro with a shorter 743 | % name for typesetting placeholders, e.g.~|\ph|: 744 | %^^A 745 | % \begin{verbatim} 746 | % \newcommand\ph\mlplaceholder\end{verbatim} 747 | % 748 | % 749 | % \section{Advanced customization} 750 | % 751 | % The \lstpkg{} package provides a large number of options accessible via a 752 | % nifty key-value interface, which is described in its excellent 753 | % \href{http://www.ctan.org/pkg/listings}{documentation}. 754 | % The \mlpkg{} package extends \lstpkg{}' key-value interface interface by 755 | % defining several additional keys that allow you to customize the style of 756 | % your \matlab{} listings, should you wish to do so. 757 | % All the keys provided by \mlpkg{} are prefixed by ``|ml|'', 758 | % to help you distinguish them from native \lstpkg{} keys. 759 | % 760 | % 761 | % \subsection{Keys from \lstpkg{} that you should not use} 762 | % 763 | % The great majority of keys provided by \lstpkg{} can be used in conjunction 764 | % with keys provided by \mlpkg{} without any detrimental side effects, 765 | % but there are a few exceptions that you should keep in mind. 766 | % 767 | % Some \mlpkg{} keys rely on \lstpkg{} keys ``under the hood'', 768 | % and using those \mlpkg{} and \lstpkg{} keys in conjunction is 769 | % \emph{strongly discouraged}, 770 | % because doing so has the potential to wreak havok on the syntax highlighting 771 | % of \matlab{} listings. 772 | % It would be like \emph{crossing the streams}: it would be \emph{bad}! 773 | % 774 | % For instance, if you want to change the way \matlab{} keywords are typeset, 775 | % you should use the dedicated \mlpkg{} key called \rkeyname{mlkeywordstyle} 776 | % and eschew the \lstpkg{} key called \keyname{keywordstyle}. 777 | % More generally, if \lstpkg{} provides a key called \meta{something} and 778 | % \mlpkg{} provides a key called |ml|\meta{something}, 779 | % customization of your \matlab{} listings should be done with the latter, not 780 | % the former. 781 | % 782 | % 783 | % \subsection{Changing the font of Matlab listings} 784 | % 785 | % For compatibility reasons, the \mlpkg{} package uses the Computer Modern 786 | % typewriter font by default. 787 | % However, this font is far from ideal, 788 | % because it doesn't come with a boldface version, 789 | % and the \matlab{} editor does display some elements of \matlab{} syntax 790 | % (section titles) in boldface. 791 | % Therefore, I encourage you to switch to your preferred ``programmer font'' 792 | % instead; how to do that depends on which typesetting engine you use. 793 | % 794 | % For |pdflatex| users, 795 | % \mlpkg{} conveniently provides a macro for easily selecting the Bera Mono 796 | % font---which is a popular monospaced font for listings, 797 | % and the one I used for all listings in this manual. 798 | %^^A 799 | % \begin{syntax} 800 | % 801 | % \item[0.1] \rcmdname\mlttfamily 802 | % 803 | % selects the Bera Mono font (somewhat scaled down). 804 | % 805 | % \end{syntax} 806 | %^^A 807 | % To use Bera Mono in your \matlab{} listings, you must pass |\mlttfamily| to 808 | % \lstpkg{}' \keyname{basicstyle} key (\emph{after} loading one of the three 809 | % styles defined by \mlpkg{}) and also---this is important---^^A 810 | % load the \pkg{fontenc} package with option \opt{T1}: 811 | %^^A 812 | % \begin{verbatim} 813 | % \usepackage[T1]{fontenc}\end{verbatim} 814 | %^^A 815 | % 816 | % 817 | % \subsection{\mlpkg{}'s key-value interface} 818 | % 819 | % For each of the \mlpkg{} keys described below, 820 | % the value assigned to it in the \mlsty{Matlab-editor} style is indicated 821 | % on the right-hand side. 822 | %^^A 823 | % \begin{syntax} 824 | % 825 | % \item[0.1,\color{blue}] 826 | % \rkeyname{mlkeywordstyle}|=|\meta{style} 827 | % 828 | % This key determines the style applied to \matlab{} keywords. 829 | % The last token can be a one-parameter command, 830 | % such as |\textbf| or |\underbar|. 831 | % 832 | % \item[0.1,\color{black}] 833 | % \rkeyname{mllastelementstyle}|=|\meta{style} 834 | % 835 | % The |end| keyword has different meanings depending on the context in 836 | % which it occurs: 837 | % it may be used to close a code block (e.g.\ a while loop), 838 | % or it may stand for the last element of an array. 839 | % In the first case, it gets highlighted in the same style as the other 840 | % \matlab{} keywords, like so: "end". 841 | % In the other case, it gets highlighted like ``normal text'', like so: 842 | % \overrideEnd. 843 | % This key determines the style of this keyword in cases where it means 844 | % ``last element''. 845 | % The last token can be a one-parameter command, 846 | % such as |\textbf| or |\underbar|. 847 | % 848 | % \item[0.1,false] 849 | % \rkeyname{mloverride}|=|\meta{\alternative{true,false}} 850 | % \syntaxor\rkeyname{mloverride} 851 | % 852 | % By default, in inline code, \mlpkg{} highlights the |end| keyword as 853 | % the closing keyword (\emph{not} as the last-element keyword) 854 | % and highlights the four class-definition identifiers as \matlab{} 855 | % functions (\emph{not} as keywords), like so: 856 | % "end", "events", "enumeration", "methods", and "properties". 857 | % This key allows you to override the current context, so that those 858 | % five context-sensitive keywords be typeset in the style of the 859 | % alternative context, like so: 860 | % \overrideEnd{}, 861 | % \overrideEvents{}, 862 | % \overrideEnumeration{}, 863 | % \overrideMethods{}, 864 | % \overrideProperties{}. 865 | % 866 | % \item[0.1,{\color[RGB]{160,32,240}}] 867 | % \rkeyname{mlstringstyle}|=|\meta{style} 868 | % 869 | % This key determines the style applied to \matlab{} quoted and unquoted 870 | % strings. 871 | % The last token can be a one-parameter command, 872 | % such as |\textbf| or |\underbar|. 873 | % 874 | % \item[0.1,{\color[RGB]{34,139,34}}] 875 | % \rkeyname{mlcommentstyle}|=|\meta{style} 876 | % 877 | % This key determines the style applied to \matlab{} to-end-of-line and 878 | % block comments. 879 | % The last token can be a one-parameter command, 880 | % such as |\textbf| or |\underbar|. 881 | % 882 | % \item[0.1,{\bfseries\color[RGB]{34,139,34}}] 883 | % \rkeyname{mlsectiontitlestyle}|=|\meta{style} 884 | % 885 | % This key determines the style applied to \matlab{} section titles. 886 | % The last token can be a one-parameter command, 887 | % such as |\textbf| or |\underbar|. 888 | % 889 | % \item[0.1,false] 890 | % \rkeyname{mlshowsectionrules}|=|\meta{\alternative{true,false}} 891 | % \syntaxor\rkeyname{mlshowsectionrules} 892 | % 893 | % This key determines whether an horizontal rule gets printed above each 894 | % \matlab{} section title. 895 | % 896 | % \item[0.1,.05] 897 | % \rkeyname{mlsectionrulethickness}|=|\meta{number} 898 | % 899 | % This key determines the thickness of the horizontal rule above each 900 | % \matlab{} section title. 901 | % The resulting thickness corresponds to the product of the value passed 902 | % to this key and the length value of |\baselineskip|. 903 | % 904 | % \item[0.1,black!15] 905 | % \rkeyname{mlsectionrulecolor}|=|\meta{color} 906 | % 907 | % This key determines the color of the horizontal rule shown above each 908 | % \matlab{} section title. 909 | % 910 | % \item[0.1,{\color[RGB]{178,140,0}}] 911 | % \rkeyname{mlsyscomstyle}|=|\meta{style} 912 | % 913 | % This key determines the style applied to \matlab{} system commands. 914 | % The last token can be a one-parameter command, 915 | % such as |\textbf| or |\underbar|. 916 | % 917 | % \item[0.1] 918 | % \rkeyname{mlsharedvars}|=|\meta{list of variables} 919 | % \item[0.1] 920 | % \rkeyname{mlmoresharedvars}|=|\meta{list of variables} 921 | % \item[0.1] 922 | % \rkeyname{mldeletesharedvars}|=|\meta{list of variables} 923 | % \item[0.1,{\color[RGB]{0,163,163}}] 924 | % \rkeyname{mlsharedvarstyle}|=|\meta{style} 925 | % 926 | % The first three of these four keys allow you to define, add, or remove 927 | % (respectively) \matlab{} variables with shared scope. 928 | % The last one determines the style applied to such variables; 929 | % the last token can be a one-parameter command, 930 | % such as |\textbf| or |\underbar|. 931 | % 932 | % \item[0.1] 933 | % \rkeyname{mlunquotedstringdelim}|={|^^A 934 | % \meta{opening delimiter}|}{|\meta{closing delimiter}|}| 935 | % 936 | % This key allows you to define delimiters 937 | % (possibly composed of multiple characters) 938 | % for highlighting unquoted strings; 939 | % the delimiters themselves do not get printed in the output. 940 | % Be aware that the special characters |{}#%\| must be escaped with a 941 | % backslash (see item~5 in subsection~4.1 of the 942 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation}). 943 | % Note that this key is only a tentative solution; 944 | % automatic highlighting of unquoted strings is a planned feature for the 945 | % next release of \mlpkg{}, which should make this key obsolete. 946 | % 947 | % \item[0.1,{\rmfamily\itshape\color[RGB]{209,0,86}}] 948 | % \rkeyname{mlplaceholderstyle}|=|\meta{style} 949 | % 950 | % This key determines the style applied to placeholders in code snippets. 951 | % The last token can be a one-parameter command, 952 | % such as |\textbf| or |\underbar|. 953 | % 954 | % \item[0.2,true] 955 | % \rkeyname{mlscaleinline}|=|\meta{\alternative{true,false}} 956 | % \syntaxor\rkeyname{mlscaleinline} 957 | % 958 | % If this key is set, any font-size specification in the basic style is 959 | % overriden, and inline \matlab{} code is scaled to it surroundings; 960 | % in other words, the font size of inline \matlab{} code is made to match 961 | % the local font size. 962 | % 963 | % \item[0.2,false] 964 | % \rkeyname{mlonlyheader}|=|\meta{\alternative{true,false}} 965 | % \syntaxor\rkeyname{mlonlyheader} 966 | % 967 | % If this key is set, output is dropped after the first block of 968 | % line comments (possibly interspersed with blank lines), 969 | % which normally corresponds to the function's header, if any. 970 | % 971 | % \end{syntax} 972 | % 973 | % 974 | % \section{Tips and tricks} 975 | % 976 | % Here is a list of recommendations^^A 977 | % ---some more opinionated than others. 978 | % \paragraph{Stick with the \mllng{} language.} 979 | % Defining a \lstpkg{} language based on \mllng{} is discouraged, 980 | % for the following reason: 981 | % \mlpkg{} performs some necessary housekeeping tasks at the beginning and 982 | % end of each listing, but only under the condition that the name of the 983 | % language used by the listing be \mllng{}; 984 | % therefore, \matlab{} listings are unlikely to get correctly highlighted if 985 | % the language name differs from \mllng{}. 986 | % 987 | % \paragraph{Define your own style.} 988 | % For maintainability reasons, if you're not completely satisfied with any of 989 | % the predefined styles, you should define your own \lstpkg{} style. 990 | % You can even base your custom style on one of the predefined styles and 991 | % tweak it (see subsection~4.5 in the 992 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation}). 993 | % 994 | % \paragraph{Load the base language/style first; customize later.} 995 | % If you want to customize the appearance of your \matlab{} listings, 996 | % you should use \lstpkg{}' \keyname{language} key or \keyname{style} key 997 | % before using any other (\lstpkg{} or \mlpkg{}) key, 998 | % because loading a language or a style ``too late'' has the potential to 999 | % wipe out most of the current settings. 1000 | % 1001 | % \paragraph{Define macros for recurring placeholders.} 1002 | % For maintainability reasons, you should define macros for oft-used 1003 | % placeholders, e.g. 1004 | %^^A 1005 | % \begin{verbatim} 1006 | % \newcommand\phcond{\mlplaceholder{condition}}\end{verbatim} 1007 | % 1008 | % \paragraph{For more highlights, use \lstpkg{}' \keyname{emph} key} 1009 | % If you want to highlight some identifiers in \matlab{} listings, use 1010 | % \lstpkg{}' \keyname{emph} key. Do \emph{not} use \lstpkg{}' 1011 | % \keyname{keywords} or \keyname{morekeywords} keys. 1012 | % 1013 | % \paragraph{Don't copy \& paste!} 1014 | % Do not encourage your readers to copy listings from their PDF viewer and 1015 | % then paste them in the \matlab{} editor. 1016 | % Unfortunately, it simply is \emph{not} a reliable way of distributing code, 1017 | % for at least three reasons: 1018 | %^^A 1019 | % \begin{itemize} 1020 | % \item copying listings that span multiple pages of a PDF document is 1021 | % tedious and error-prone; 1022 | % \item the results of copying content from a PDF for 1023 | % subsequent pasting vary widely from one PDF viewer to another; 1024 | % \item line breaks introduced by \lstpkg{} for typesetting a \matlab{} 1025 | % listing may translate to invalid \matlab{} syntax, if copied and pasted 1026 | % \emph{verbatim}. 1027 | % \end{itemize} 1028 | % 1029 | % \paragraph{Typesetting a vertically centered tilde} 1030 | % Unfortunately, not all fonts typeset the tilde character ("~") vertically 1031 | % centered---as it is in the \matlab{} editor. 1032 | % Be aware that, if you set a font for your \matlab{} listings 1033 | % (via \lstpkg{}' \keyname{basicstyle} key) that is different from \mlpkg{}'s 1034 | % default (a scaled-down version of Bera Mono), tilde characters occuring in 1035 | % your listings may get typeset vertically off-center. 1036 | % Because a good, font-independent workaround seems out of reach, 1037 | % I refer you to \url{http://tex.stackexchange.com/q/312/21891}, 1038 | % where you will find a list of ad-hoc solutions. 1039 | % 1040 | % \paragraph{Avoid literate replacements like the plague!} 1041 | % The \pkg{mcode} package predefines so-called ``literate replacements'' 1042 | % (see subsection~5.4 in the 1043 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation}), 1044 | % e.g.\ for printing~``\(\leq\)'' in place of each instance of~``"<="''. 1045 | % I deliberately chose not to define any such literate replacements in 1046 | % \mlpkg{} because I think that, rather than improving code readability, 1047 | % they have a potential to confuse and mislead your readers. 1048 | % In particular, newcomers to the programming language may not immediately 1049 | % realize that those symbols are not part of the language's syntax; 1050 | % they may ascribe literal meaning to them and attempt to reproduce them in 1051 | % their editor or IDE. 1052 | % How counterproductive! 1053 | % Of course, if you insist, you can still define your own literate 1054 | % replacements. 1055 | % 1056 | % 1057 | % \part{Miscellaneous} 1058 | % 1059 | % \section{To-do list} 1060 | % 1061 | % \paragraph{Automatic highlighting of unquoted strings} 1062 | % In the current version of \mlpkg{}, unquoted strings will only be 1063 | % highlighted as strings if you delimit them with custom delimiters 1064 | % (defined via the \rkeyname{mlunquotedstringdelim} key). 1065 | % However, I have plans to implement an automatic approach in a future 1066 | % release. 1067 | % Note that this feature will make the \rkeyname{mlunquotedstringdelim} key 1068 | % obsolete. 1069 | % 1070 | % \paragraph{Increased support for \octave{}'s syntax} 1071 | % Support for \octave{}'s idiosyncratic syntax---^^A 1072 | % e.g.\ |endif| and |endwhile| keywords---^^A 1073 | % will be added in a future release of \mlpkg{}. 1074 | % 1075 | % 1076 | % \section{Missing features and known issues} 1077 | % 1078 | % Although \mlpkg{} does a reasonably good job at replicating the syntax 1079 | % highlighting performed by the \matlab{} editor, some problems remain. 1080 | % Here is a list of known, currently unresolved problems. 1081 | % 1082 | % \paragraph{No automatic highlighting of variables with shared scope} 1083 | % Unfortunately, automatic highlighting of variables with shared scope 1084 | % would require multiple passes, which the \lstpkg{} package cannot do. 1085 | % However, I believe that the number of variables in your \matlab{} code 1086 | % should be small enough^^A 1087 | % ---otherwise, your \matlab{} code is probably not sound!---^^A 1088 | % that you can afford to highlight those variables manually, if you insist on 1089 | % highlighting them at all. 1090 | % 1091 | % \paragraph{No highlighting of unterminated strings} 1092 | % Because \lstpkg{} cannot look very far ahead, I haven't found an easy way of 1093 | % checking whether an opening string delimiter is missing a matching (closing) 1094 | % string delimiter on the same line. 1095 | % 1096 | % \paragraph{Illegal syntax tends to yield incorrect syntax highlighting} 1097 | % For example, the \matlab{} editor would highlight the |end| keyword in the 1098 | % listing below, not as closing keyword ("end"), but as last-element keyword 1099 | % (\overrideEnd{}). 1100 | %^^A 1101 | % \begin{lstsample}{}{\lstset{style=nonbnoframe}} 1102 | % \begin{lstlisting}[ 1103 | % style=Matlab-editor, 1104 | % basicstyle=\mlttfamily, 1105 | % numbers=none] 1106 | % if=end 1107 | % \end{lstlisting} 1108 | % \end{lstsample} 1109 | % 1110 | % \paragraph{Some section titles fail to be highlighted as such} 1111 | % In \matlab{}, a line containing only ``\texttt{\%\%}'' and blank 1112 | % characters is a section title. 1113 | % \mlpkg{} incorrectly highlights such a line in comment style. 1114 | %^^A 1115 | % \begin{lstsample}{}{\lstset{style=nonbnoframe}} 1116 | % \begin{lstlisting}[ 1117 | % style=Matlab-editor, 1118 | % numbers=none, 1119 | % basicstyle=\mlttfamily, 1120 | % numbers=none] 1121 | % %% This is a section title 1122 | % % and so is the next line 1123 | % %% 1124 | % % but it gets highlighted 1125 | % % like a comment. 1126 | % \end{lstlisting} 1127 | % \end{lstsample} 1128 | % 1129 | % \paragraph{\lstpkg{}' \keyname{keespaces} key messes up section-title rules} 1130 | % If both \lstpkg{}' \keyname{keepspaces} and \mlpkg{}'s 1131 | % \rkeyname{mlshowsectionrules} are set, section titles that start by some 1132 | % white space get pushed to the right. 1133 | %^^A 1134 | % \begin{lstsample}{}{\lstset{style=nonbnoframe}} 1135 | % \begin{lstlisting}[ 1136 | % style=Matlab-editor, 1137 | % basicstyle=\mlttfamily, 1138 | % numbers=none, 1139 | % keepspaces, 1140 | % mlshowsectionrules] 1141 | % %% the rule gets pushed to the right... 1142 | % \end{lstlisting} 1143 | % \end{lstsample} 1144 | % 1145 | % \paragraph{``Runaway'' block comments end prematurely (in some cases)} 1146 | % \matlab{} requires opening and closing delimiters of block comments to each 1147 | % be on a line on its own, without any visible character, but \mlpkg{} 1148 | % incorrectly considers block comments closed even in some cases where this 1149 | % rule is infringed. 1150 | % For example, in the listing below, the \matlab{} editor would typeset 1151 | % "a = 1" in comment style. 1152 | %^^A 1153 | % \begin{lstsample}{}{\lstset{style=nonbnoframe}} 1154 | % \begin{lstlisting}[ 1155 | % style=Matlab-editor, 1156 | % basicstyle=\mlttfamily, 1157 | % numbers=none] 1158 | % %{ 1159 | % "runaway" 1160 | % block 1161 | % comment %} 1162 | % a = 1 1163 | % \end{lstlisting} 1164 | % \end{lstsample} 1165 | % 1166 | % 1167 | % \section{Bug reports and feature suggestions} 1168 | % 1169 | % The development version of \mlpkg{} is currently hosted on GitHub at 1170 | % \href{https://github.com/Jubobs/matlab-prettifier} 1171 | % {Jubobs/matlab-prettifier}. 1172 | % If you find an issue in \mlpkg{} that this manual does not mention, 1173 | % if you would like to see a feature implemented in the package, 1174 | % or if you can think of ways in which the \mlpkg{} documentation could be 1175 | % improved, please open a ticket in the GitHub repository's issue tracker; 1176 | % alternatively, you can send me an email at 1177 | % \email{jubobs.tex@gmail.com} 1178 | % 1179 | % 1180 | % \section{Acknowledgments} 1181 | % Thanks to the developers of the \lstpkg{} package, 1182 | % without which \mlpkg{} would never have existed. 1183 | % I'm also in debt to many 1184 | % \href{http://tex.stackexchange.com}{TeX.SX} users for their help, 1185 | % encouragements, and suggestions. 1186 | % Thanks in particular to David Carlisle, Marco Daniel, 1187 | % Enrico Gregorio (egreg), Harish Kumar, Heiko Oberdiek, and Robert Schlicht. 1188 | % Thanks also to the good people at \href{http://www.ctan.org}{CTAN} 1189 | % for hosting the package. 1190 | % 1191 | % 1192 | % \makeatletter 1193 | % \def\index@prologue{\part{Index}\markboth{Index}{Index}} 1194 | % \makeatother 1195 | % \StopEventually{^^A 1196 | % \clearpage^^A 1197 | % \PrintChanges^^A 1198 | % \setcounter{IndexColumns}{2}^^A 1199 | % \PrintIndex^^A 1200 | % } 1201 | % 1202 | % 1203 | % \part{Implementation} 1204 | % 1205 | % Be aware that, for ``namespacing'', the \mlpkg{} package uses, not a prefix, 1206 | % but the ``|mlpr|''~suffix (preceded by an |@| character) throughout. 1207 | % 1208 | % 1209 | % \section{Preliminary checks} 1210 | % 1211 | % \begin{macro}{\lstoptcheck@mlpr} 1212 | % Because the \lstpkg{} options \opt{noaspects}, \opt{0.21}, and 1213 | % \opt{savemem} are incompatible with \pkg{matlab-prettifier}, checking 1214 | % whether the \lstpkg{} package has been loaded with any of those options is 1215 | % a good idea; if so, we should issue an error. 1216 | % This macro checks whether \lstpkg{} was loaded with a given option 1217 | % and, if so, throws an error. 1218 | % \begin{macrocode} 1219 | \newcommand\lstoptcheck@mlpr[1]{% 1220 | \@ifpackagewith{listings}{#1}{% 1221 | \PackageError{matlab-prettifier}% 1222 | {incompatible listings' option #1}{% 1223 | Make sure the `listings' package 1224 | doesn't get loaded with option `#1'% 1225 | } 1226 | } 1227 | {} 1228 | } 1229 | % \end{macrocode} 1230 | % \end{macro} 1231 | % We now use this macro to make sure that none of the problematic \lstpkg{} 1232 | % options has been passed to \lstpkg{} during an earlier loading of that 1233 | % package. 1234 | % \begin{macrocode} 1235 | \lstoptcheck@mlpr{noaspects} 1236 | \lstoptcheck@mlpr{0.21} 1237 | \lstoptcheck@mlpr{savemem} 1238 | % \end{macrocode} 1239 | % 1240 | % 1241 | % \section{Package options} 1242 | % 1243 | % \paragraph{Framed listings} 1244 | % \begin{macro}{\ifframed@mlpr@} 1245 | % This option draws a frame around each listing by default. 1246 | % \begin{macrocode} 1247 | \newif\ifframed@mlpr@ 1248 | \DeclareOption{framed}{\framed@mlpr@true} 1249 | % \end{macrocode} 1250 | % \end{macro} 1251 | % 1252 | % \paragraph{Numbered lines} 1253 | % \begin{macro}{\ifnumbered@mlpr@} 1254 | % This option prints line numbers to the left of each listing by default. 1255 | % \begin{macrocode} 1256 | \newif\ifnumbered@mlpr@ 1257 | \DeclareOption{numbered}{\numbered@mlpr@true} 1258 | % \end{macrocode} 1259 | % \end{macro} 1260 | % 1261 | % \paragraph{Draft} 1262 | % This option is simply passed to \lstpkg{}. 1263 | % \begin{macrocode} 1264 | \DeclareOption{draft}{\PassOptionsToPackage{\CurrentOption}{listings}} 1265 | % \end{macrocode} 1266 | % 1267 | % \paragraph{Final} 1268 | % This option is simply passed to \lstpkg{}. 1269 | % \begin{macrocode} 1270 | \DeclareOption{final}{\PassOptionsToPackage{\CurrentOption}{listings}} 1271 | % \end{macrocode} 1272 | % 1273 | % \paragraph{Discard undefined options} 1274 | % We discard any other option passed to \mlpkg{} by the user 1275 | % and issue a warning. 1276 | % \begin{macrocode} 1277 | \DeclareOption*{% 1278 | \OptionNotUsed 1279 | \PackageWarning{matlab-prettifier}{Unknown `\CurrentOption' option} 1280 | } 1281 | % \end{macrocode} 1282 | % \paragraph{Process options} 1283 | % \begin{macrocode} 1284 | \ProcessOptions\relax 1285 | % \end{macrocode} 1286 | % 1287 | % 1288 | % \section{Required packages} 1289 | % 1290 | % The \mlpkg{} package require three packages without any package option: 1291 | % the \pkg{textcomp} package, in order to use \lstpkg{}' \keyname{upquote} 1292 | % key; 1293 | % the \pkg{xcolor} package, in order to color our \matlab{} code; 1294 | % and, of course, the \lstpkg{} package. 1295 | % \begin{macrocode} 1296 | \RequirePackage{textcomp}[2005/09/27] 1297 | \RequirePackage{xcolor}[2007/01/21] 1298 | \RequirePackage{listings}[2013/08/26] 1299 | % \end{macrocode} 1300 | % 1301 | % 1302 | % \section{Definition of the \texorpdfstring{\mllng}{Matlab-pretty} language} 1303 | % 1304 | % \paragraph{Language name} 1305 | % \begin{macro}{\language@mlpr} 1306 | % To avoid code duplication in this package file, we define a macro that 1307 | % expands to the name of our new language, \mllng{}. 1308 | % \begin{macrocode} 1309 | \newcommand\language@mlpr{Matlab-pretty} 1310 | % \end{macrocode} 1311 | % \end{macro} 1312 | % \begin{macro}{\languageNormedDefd@mlpr} 1313 | % However, because \lstpkg{} ``normalizes'' language names internally, 1314 | % we will also need to define a macro that expands to the normalized name of 1315 | % the new language. 1316 | % \begin{macrocode} 1317 | \expandafter\lst@NormedDef\expandafter\languageNormedDefd@mlpr% 1318 | \expandafter{\language@mlpr} 1319 | % \end{macrocode} 1320 | % \end{macro} 1321 | % 1322 | % \paragraph{Language definition} 1323 | % We can now define our new \lstpkg{} language, using some |\expandafter| 1324 | % trickery on |\lstdefinelanguage|. 1325 | % \begin{macrocode} 1326 | \expandafter\expandafter\expandafter\lstdefinelanguage\expandafter% 1327 | {\language@mlpr}{% 1328 | % \end{macrocode} 1329 | % 1330 | % \paragraph{Case sensitivity} 1331 | % \matlab{} is a case-sensitive language. 1332 | % \begin{macrocode} 1333 | sensitive=true, 1334 | % \end{macrocode} 1335 | % 1336 | % \paragraph{Forbidden characters in identifiers} 1337 | % By default, \lstpkg{} allows ``\$'' and ``@'' to occur in identifiers, 1338 | % but those characters are not valid in \matlab{} identifiers. 1339 | % \begin{macrocode} 1340 | alsoother={\$@}, 1341 | % \end{macrocode} 1342 | % 1343 | % \paragraph{Character-table adjustments} 1344 | % In order to keep track of the context, we need to modify the character 1345 | % table a bit. 1346 | % \begin{macrocode} 1347 | MoreSelectCharTable=\MoreSelectCharTable@mlpr, 1348 | % \end{macrocode} 1349 | % 1350 | % \paragraph{Keywords} 1351 | % 1352 | % The keywords defined below are based on the list returned by the 1353 | % \matlabver{} "iskeyword" function and the four class-definition keywords^^A 1354 | % ---which are omitted by the "iskeyword" function. 1355 | % Because different \matlab{} keywords affect the context in different ways, 1356 | % we use several classes of \pkg{listings} keywords to handle them. 1357 | % 1358 | % The following keywords open a block unrelated to class definition. 1359 | % \begin{macrocode} 1360 | morekeywords=[1]{% 1361 | for, 1362 | if, 1363 | otherwise, 1364 | parfor, 1365 | spmd, 1366 | switch, 1367 | try, 1368 | while, 1369 | }, 1370 | keywordstyle=[1]\processOpRegKW@mlpr, 1371 | % \end{macrocode} 1372 | % Most of the following keywords (nicknamed ``middle'' keywords herein) can 1373 | % only occur within a block opened by the keywords listed above^^A 1374 | % ---"function" and "return" are exceptions, but, as far as I can tell, 1375 | % seem to have the same effects on syntax highlighting as the others---^^A 1376 | % and are unrelated to class definition. 1377 | % \begin{macrocode} 1378 | morekeywords=[2]{% 1379 | break, 1380 | case, 1381 | catch, 1382 | continue, 1383 | else, 1384 | elseif, 1385 | function, 1386 | return, 1387 | }, 1388 | keywordstyle=[2]\processMidKW@mlpr, 1389 | % \end{macrocode} 1390 | % The following two keywords are ``standalone''; 1391 | % they don't open or close any block. 1392 | % \begin{macrocode} 1393 | morekeywords=[3]{% 1394 | global, 1395 | persistent, 1396 | }, 1397 | keywordstyle=[3]\processStdaKW@mlpr, 1398 | % \end{macrocode} 1399 | % The "classdef" keyword interacts with other keywords in a unique fashion; 1400 | % therefore, we dedicate a whole class of \lstpkg{} keywords to it. 1401 | % \begin{macrocode} 1402 | morekeywords=[4]{classdef}, 1403 | keywordstyle=[4]\processClassdefKW@mlpr, 1404 | % \end{macrocode} 1405 | % We dedicate a class of \lstpkg{} keywords to the four \matlab{} keywords 1406 | % that only occur within a class-definition block, 1407 | % namely \overrideEvents{}, \overrideEnumeration{}, \overrideMethods{}, 1408 | % and \overrideProperties{}. 1409 | % \begin{macrocode} 1410 | morekeywords=[5]{% 1411 | enumeration, 1412 | events, 1413 | methods, 1414 | properties, 1415 | }, 1416 | keywordstyle=[5]\processMidClassdefKW@mlpr, 1417 | % \end{macrocode} 1418 | % The |end| keyword has a very peculiar behavior and deserves its own keyword 1419 | % class. 1420 | % \begin{macrocode} 1421 | morekeywords=[6]{end}, 1422 | keywordstyle=[6]\processEndKW@mlpr, 1423 | % \end{macrocode} 1424 | % 1425 | % \paragraph{Strings} 1426 | % We simply use \lstpkg{}' built-in mechanism for highlighting \matlab{} 1427 | % quoted string\ldots with a twist; more details follow. 1428 | % \begin{macrocode} 1429 | morestring=[m]', 1430 | stringstyle=\processString@mlpr, 1431 | % \end{macrocode} 1432 | % 1433 | % \paragraph{Comments \& section titles} 1434 | % Delimiters for to-end-of-line and block comments are defined below. 1435 | % \begin{macrocode} 1436 | morecomment=[l]\%, 1437 | morecomment=[n]{\%\{\^^M}{\%\}\^^M}, 1438 | commentstyle=\commentStyle@mlpr, 1439 | % \end{macrocode} 1440 | % The line-continuation token ("..."), which starts a to-end-of-line comment, 1441 | % is treated separately. 1442 | % \begin{macrocode} 1443 | moredelim=**[il][\processDotDotDot@mlpr]{...}, 1444 | % \end{macrocode} 1445 | % Section titles, as special comments that get highlighted in a style 1446 | % different to that of regular comments, must also be treated separately. 1447 | % \begin{macrocode} 1448 | moredelim=[l][\processSectionTitle@mlpr]{\%\%\ }, 1449 | % \end{macrocode} 1450 | % 1451 | % \paragraph{System commands} 1452 | % System commands are handled in a straightforward manner by an |l|-type 1453 | % delimiter. 1454 | % \begin{macrocode} 1455 | moredelim=[l][\syscomStyle@mlpr]!, 1456 | % \end{macrocode} 1457 | % 1458 | % \paragraph{Required \lstpkg{} aspects} 1459 | % We now only need to specify the required \lstpkg{} ``aspects''. 1460 | % \begin{macrocode} 1461 | }[ 1462 | keywords, 1463 | strings, 1464 | comments, 1465 | ] 1466 | % \end{macrocode} 1467 | % 1468 | % 1469 | % \section{State variables} 1470 | % We define a number of \TeX{} counters and switches that will be used as 1471 | % ``state variables'', to keep track of the context. 1472 | % 1473 | % \paragraph{Counters} 1474 | % \begin{macro}{\netBracketCount@mlpr} 1475 | % This counter is used to keep a net running count of opening and closing 1476 | % brackets---roughly speaking. 1477 | % When an opening bracket---be it round, square or curly---is encountered, 1478 | % the counter is incremented; 1479 | % conversely, when a closing bracket is encountered, the counter is 1480 | % decremented. 1481 | % I write ``roughly speaking'', because that counter gets reset on some 1482 | % occasions; more details follow. 1483 | % \begin{macrocode} 1484 | \newcount\netBracketCount@mlpr 1485 | % \end{macrocode} 1486 | % \end{macro} 1487 | % \begin{macro}{\blkLvl@mlpr} 1488 | % This counter counter is used to keep track of the block nesting level. 1489 | % \begin{macrocode} 1490 | \newcount\blkLvl@mlpr 1491 | % \end{macrocode} 1492 | % \end{macro} 1493 | % \begin{macro}{\blkLvlAtClassdef@mlpr} 1494 | % This counter is used to keep track of the block nesting level at which the 1495 | % last "classdef" keyword occured. 1496 | % \begin{macrocode} 1497 | \newcount\blkLvlAtClassdef@mlpr 1498 | % \end{macrocode} 1499 | % \end{macro} 1500 | % 1501 | % \paragraph{Switches} 1502 | % \begin{macro}{\ifClosingEndKW@mlpr@} 1503 | % This switch determines whether the |end| keyword acts as a closing keyword 1504 | % or as last-element keyword in the current context. 1505 | % \begin{macrocode} 1506 | \newif\ifClosingEndKW@mlpr@ \ClosingEndKW@mlpr@true 1507 | % \end{macrocode} 1508 | % \end{macro} 1509 | % \begin{macro}{\ifInClassdef@mlpr@} 1510 | % This switch determines whether we're within a class-definition block or not. 1511 | % \begin{macrocode} 1512 | \newif\ifInClassdef@mlpr@ \InClassdef@mlpr@false 1513 | % \end{macrocode} 1514 | % \end{macro} 1515 | % \begin{macro}{\ifInStr@mlpr@} 1516 | % This switch determines whether we're inside a string or not. 1517 | % \begin{macrocode} 1518 | \newif\ifInStr@mlpr@ \InStr@mlpr@false 1519 | % \end{macrocode} 1520 | % \end{macro} 1521 | % \begin{macro}{\ifVisCharOccured@mlpr@} 1522 | % This switch is used to keep track of whether visible characters have 1523 | % occured on the current line. 1524 | % \begin{macrocode} 1525 | \newif\ifVisCharOccured@mlpr@\VisCharOccured@mlpr@false 1526 | % \end{macrocode} 1527 | % \end{macro} 1528 | % \begin{macro}{\ifInSecTitle@mlpr@} 1529 | % This switch determines whether we're inside a section title or not. 1530 | % \begin{macrocode} 1531 | \newif\ifInSecTitle@mlpr@ \InSecTitle@mlpr@false 1532 | % \end{macrocode} 1533 | % \end{macro} 1534 | % \begin{macro}{\ifDroppingOutput@mlpr@} 1535 | % This switch determines whether we're passed the first contiguous block of 1536 | % line comments (function header). 1537 | % \begin{macrocode} 1538 | \newif\ifDroppingOutput@mlpr@\DroppingOutput@mlpr@false 1539 | % \end{macrocode} 1540 | % \end{macro} 1541 | % 1542 | % \paragraph{Helper macros for resetting state variables} 1543 | % The following macros are used to reset counters and switches. 1544 | % \begin{macro}{\resetEndKW@mlpr} 1545 | % This macro restores the |end| keyword as a closing keyword. 1546 | % \begin{macrocode} 1547 | \newcommand\resetEndKW@mlpr{% 1548 | \global\ClosingEndKW@mlpr@true% 1549 | \global\netBracketCount@mlpr=0% 1550 | } 1551 | % \end{macrocode} 1552 | % \end{macro} 1553 | % \begin{macro}{\resetClassdefKW@mlpr} 1554 | % This macro reinitializes state variables related to class definition. 1555 | % \begin{macrocode} 1556 | \newcommand\resetClassdefKW@mlpr{% 1557 | \global\InClassdef@mlpr@false% 1558 | \global\blkLvl@mlpr=0% 1559 | \global\blkLvlAtClassdef@mlpr=0% 1560 | } 1561 | % \end{macrocode} 1562 | % \end{macro} 1563 | % 1564 | % 1565 | % \section{Processing of syntactic elements} 1566 | % 1567 | % (The overarching algorithm is not documented here; 1568 | % in a future release, perhaps.) 1569 | % 1570 | % \paragraph{Processing of brackets} 1571 | % An opening and or a closing brackets occuring in a \matlab{} listing affects 1572 | % the context; 1573 | % for instance, an |end| keyword is always interpreted as a closing keyword if 1574 | % it is immediately preceded by a closing bracket, no matter what comes 1575 | % before that. 1576 | % To keep track of the context, we must update our state variables every time 1577 | % a bracket is encountered. 1578 | % 1579 | % \begin{macro}{\MoreSelectCharTable@mlpr} 1580 | % This macro, which is passed to \lstpkg{}' \keyname{MoreSelectCharTable} key 1581 | % in the definition of \mllng{}, allows us to dictate what happens when a 1582 | % bracket or a semicolon is encountered. 1583 | % \begin{macrocode} 1584 | \newcommand\MoreSelectCharTable@mlpr{% 1585 | % \end{macrocode} 1586 | % 1587 | % \begin{macro}{\roundBktOp@mlpr} 1588 | % We store the original definition of ``|(|'' from the default character 1589 | % table in a dedicated macro and modify the behavior of that character. 1590 | % \begin{macrocode} 1591 | \processOpenBracket@mlpr{`(}{\roundBktOp@mlpr}% 1592 | % \end{macrocode} 1593 | % \end{macro} 1594 | % 1595 | % \begin{macro}{\squareBktOp@mlpr} 1596 | % We store the original definition of ``|[|'' from the default character 1597 | % table in a dedicated macro and modify the behavior of that character. 1598 | % \begin{macrocode} 1599 | \processOpenBracket@mlpr{`[}{\squareBktOp@mlpr}% 1600 | % \end{macrocode} 1601 | % \end{macro} 1602 | % 1603 | % \begin{macro}{\curlyBktOp@mlpr} 1604 | % We store the original definition of ``|{|'' from the default character 1605 | % table in a dedicated macro and modify the behavior of that character. 1606 | % \begin{macrocode} 1607 | \processOpenBracket@mlpr{`\{}{\curlyBktOp@mlpr}% 1608 | % \end{macrocode} 1609 | % \end{macro} 1610 | % 1611 | % \begin{macro}{\roundBktCl@mlpr} 1612 | % We store the original definition of ``|)|'' from the default character 1613 | % table in a dedicated macro and modify the behavior of that character. 1614 | % \begin{macrocode} 1615 | \processCloseBracket@mlpr{`)}{\roundBktCl@mlpr}% 1616 | % \end{macrocode} 1617 | % \end{macro} 1618 | % 1619 | % \begin{macro}{\squareBktCl@mlpr} 1620 | % We store the original definition of ``|]|'' from the default character 1621 | % table in a dedicated macro and modify the behavior of that character. 1622 | % \begin{macrocode} 1623 | \processCloseBracket@mlpr{`]}{\squareBktCl@mlpr}% 1624 | % \end{macrocode} 1625 | % \end{macro} 1626 | % 1627 | % \begin{macro}{\curlyBktCl@mlpr} 1628 | % We store the original definition of ``|}|'' from the default character 1629 | % table in a dedicated macro and modify the behavior of that character. 1630 | % \begin{macrocode} 1631 | \processCloseBracket@mlpr{`\}}{\curlyBktCl@mlpr}% 1632 | % \end{macrocode} 1633 | % \end{macro} 1634 | % 1635 | % \begin{macro}{\semicolon@mlpr} 1636 | % We store the original definition of ``|;|'' from the default character 1637 | % table in a dedicated macro and modify the behavior of that character. 1638 | % \begin{macrocode} 1639 | \processSemicolon@mlpr{`;}{\semicolon@mlpr}% 1640 | % \end{macrocode} 1641 | % \end{macro} 1642 | % \begin{macrocode} 1643 | } 1644 | % \end{macrocode} 1645 | % \end{macro} 1646 | % 1647 | % \begin{macro}{\processOpenBracket@mlpr} 1648 | % This macro is used to ``hook into'' opening-bracket characters and update 1649 | % state variables every time such a character is encountered in \lstpkg{}' 1650 | % ``processing mode''. 1651 | % \begin{macrocode} 1652 | \newcommand\processOpenBracket@mlpr[2]{% 1653 | \lst@DefSaveDef{#1}#2{% 1654 | #2% 1655 | \ifnum\lst@mode=\lst@Pmode\relax% 1656 | \global\ClosingEndKW@mlpr@false% 1657 | \global\advance\netBracketCount@mlpr by \@ne% 1658 | \fi 1659 | }% 1660 | } 1661 | % \end{macrocode} 1662 | % \end{macro} 1663 | % 1664 | % \begin{macro}{\processCloseBracket@mlpr} 1665 | % This macro is used to ``hook into'' closing-bracket characters and update 1666 | % state variables every time such a character is encountered in \lstpkg{}' 1667 | % ``processing mode''. 1668 | % \begin{macrocode} 1669 | \newcommand\processCloseBracket@mlpr[2]{% 1670 | \lst@DefSaveDef{#1}#2{% 1671 | #2% 1672 | \ifnum\lst@mode=\lst@Pmode\relax% 1673 | \ifClosingEndKW@mlpr@% 1674 | \netBracketCount@mlpr=0% 1675 | \else 1676 | \global\advance\netBracketCount@mlpr by \m@ne% 1677 | \ifnum\netBracketCount@mlpr>0% 1678 | \else 1679 | \global\ClosingEndKW@mlpr@true% 1680 | \fi 1681 | \fi 1682 | \fi 1683 | }% 1684 | } 1685 | % \end{macrocode} 1686 | % \end{macro} 1687 | % 1688 | % \begin{macro}{\processSemicolon@mlpr} 1689 | % This macro is used to ``hook into'' the semicolon character and update 1690 | % state variables every time such a character is encountered in \lstpkg{}' 1691 | % ``processing mode''. 1692 | % \begin{macrocode} 1693 | \newcommand\processSemicolon@mlpr[2]{% 1694 | \lst@DefSaveDef{#1}#2{% 1695 | #2% 1696 | \ifnum\lst@mode=\lst@Pmode\relax% 1697 | \resetEndKW@mlpr% 1698 | \fi 1699 | }% 1700 | } 1701 | % \end{macrocode} 1702 | % \end{macro} 1703 | % 1704 | % \paragraph{Processing of keywords} 1705 | % The following macros are used for updating state variables every time a 1706 | % keyword is encountered in \lstpkg{} ``processing mode''. 1707 | % 1708 | % \begin{macro}{\processOpRegKW@mlpr} 1709 | % This macro updates state variables every time an opening keyword is 1710 | % processed, and applies keyword style. 1711 | % \begin{macrocode} 1712 | \newcommand\processOpRegKW@mlpr{% 1713 | \resetEndKW@mlpr% 1714 | \global\advance\blkLvl@mlpr\@ne% 1715 | \keywordStyle@mlpr% 1716 | } 1717 | % \end{macrocode} 1718 | % \end{macro} 1719 | % 1720 | % \begin{macro}{\processMidKW@mlpr} 1721 | % This macro updates state variables every time a ``middle'' keyword is 1722 | % processed, and applies keyword style. 1723 | % \begin{macrocode} 1724 | \newcommand\processMidKW@mlpr{% 1725 | \resetEndKW@mlpr% 1726 | \keywordStyle@mlpr% 1727 | } 1728 | % \end{macrocode} 1729 | % \end{macro} 1730 | % \begin{macro}{\processStdaKW@mlpr} 1731 | % As far as I can tell, ``standalone'' keywords and ``middle'' keywords 1732 | % affect the context in the same way; 1733 | % therefore, we simply reuse |\processMidKW@mlpr| here. 1734 | % \begin{macrocode} 1735 | \newcommand\processStdaKW@mlpr\processMidKW@mlpr 1736 | % \end{macrocode} 1737 | % \end{macro} 1738 | % \begin{macro}{\processClassdefKW@mlpr} 1739 | % This macro updates state variables every time the "classdef" keyword is 1740 | % processed, and applies keyword style. 1741 | % \begin{macrocode} 1742 | \newcommand\processClassdefKW@mlpr{% 1743 | \resetEndKW@mlpr% 1744 | \global\InClassdef@mlpr@true% 1745 | \global\blkLvlAtClassdef@mlpr=\blkLvl@mlpr% 1746 | \global\advance\blkLvl@mlpr\@ne% 1747 | \keywordStyle@mlpr% 1748 | } 1749 | % \end{macrocode} 1750 | % \end{macro} 1751 | % \begin{macro}{\processMidClassdefKW@mlpr} 1752 | % This macro updates state variables every time one of the four keywords 1753 | % that only occur within a class-definition block is processed, and applies 1754 | % the appropriate style. 1755 | % \begin{macrocode} 1756 | \newcommand\processMidClassdefKW@mlpr{% 1757 | \ifOverridecontext@mlpr@% 1758 | \keywordStyle@mlpr% 1759 | \else 1760 | \ifInClassdef@mlpr@% 1761 | \resetEndKW@mlpr% 1762 | \global\advance\blkLvl@mlpr\@ne% 1763 | \keywordStyle@mlpr% 1764 | \fi 1765 | \fi 1766 | } 1767 | % \end{macrocode} 1768 | % \end{macro} 1769 | % \begin{macro}{\processEndKW@mlpr} 1770 | % This macro updates state variables every time the |end| keyword is 1771 | % processed, and applies the appropriate style. 1772 | % \begin{macrocode} 1773 | \newcommand\processEndKW@mlpr{% 1774 | \ifOverridecontext@mlpr@% 1775 | \lastElemStyle@mlpr% 1776 | \else 1777 | \ifClosingEndKW@mlpr@% 1778 | \ifnum\blkLvl@mlpr>0% 1779 | \global\advance\blkLvl@mlpr\m@ne% 1780 | \fi 1781 | \ifnum\blkLvl@mlpr=\blkLvlAtClassdef@mlpr% 1782 | \global\InClassdef@mlpr@false% 1783 | \fi 1784 | \keywordStyle@mlpr% 1785 | \else 1786 | \lastElemStyle@mlpr% 1787 | \fi 1788 | \fi 1789 | } 1790 | % \end{macrocode} 1791 | % \end{macro} 1792 | % 1793 | % \paragraph{Processing of strings} 1794 | % \begin{macro}{\processString@mlpr} 1795 | % This macro records that a string has just started by setting the appropriate 1796 | % switch, and applies string style. 1797 | % \begin{macrocode} 1798 | \newcommand\processString@mlpr{% 1799 | \global\InStr@mlpr@true% 1800 | \stringStyle@mlpr% 1801 | } 1802 | % \end{macrocode} 1803 | % \end{macro} 1804 | % 1805 | % \paragraph{Processing of line-continuation tokens} 1806 | % \begin{macro}{\processDotDotDot@mlpr} 1807 | % This macro typesets the line-continuation token in the style of our 1808 | % \matlab{} keywords, 1809 | % prohibits any mode changes on the rest of the current line, 1810 | % and applies comment style to the rest of the current line. 1811 | % \begin{macrocode} 1812 | \newcommand\processDotDotDot@mlpr{% 1813 | \lst@CalcLostSpaceAndOutput% 1814 | {\keywordStyle@mlpr...}% 1815 | \lst@modetrue% 1816 | \lst@Lmodetrue% 1817 | \commentStyle@mlpr% 1818 | } 1819 | % \end{macrocode} 1820 | % \end{macro} 1821 | % 1822 | % \paragraph{Processing of section titles} 1823 | % First, we need to define a few length macros in order to draw the horizontal 1824 | % rule that \matlab{} shows (by default) above each section title. 1825 | % \begin{macro}{\emHeight@mlpr} 1826 | % We will use this length to store the height of the ``M'' character in the 1827 | % current font. 1828 | % \begin{macrocode} 1829 | \newlength\emHeight@mlpr 1830 | % \end{macrocode} 1831 | % \end{macro} 1832 | % \begin{macro}{\jayDepth@mlpr} 1833 | % We will use this length to store the depth of letter ``j'' in the current 1834 | % font. 1835 | % \begin{macrocode} 1836 | \newlength\jayDepth@mlpr 1837 | % \end{macrocode} 1838 | % \end{macro} 1839 | % \begin{macro}{\sectionRuleOffset@mlpr} 1840 | % We will use this length to store the result of our calculations for the 1841 | % vertical offset required. 1842 | % \begin{macrocode} 1843 | \newlength\sectionRuleOffset@mlpr 1844 | % \end{macrocode} 1845 | % \end{macro} 1846 | % Let's proceed\ldots 1847 | % \begin{macro}{\processSectionTitle@mlpr} 1848 | % This macro is invoked when a |%%| delimiter is encountered. 1849 | % \begin{macrocode} 1850 | \newcommand\processSectionTitle@mlpr{% 1851 | \ifInSecTitle@mlpr@% 1852 | \sectionTitleStyle@mlpr% 1853 | \else 1854 | % \end{macrocode} 1855 | % If visible characters have already been encountered before the |%%| on the 1856 | % current line, this line is simply typeset as a to-end-of-line comment. 1857 | % \begin{macrocode} 1858 | \ifVisCharOccured@mlpr@% 1859 | \commentStyle@mlpr% 1860 | % \end{macrocode} 1861 | % Otherwise, a section title starts here; 1862 | % we update the relevant state variables and, if the 1863 | % \rkeyname{mlshowsectionrules} key has been set, we draw a horizontal rule. 1864 | % \begin{macrocode} 1865 | \else % a section title is starting here 1866 | \global\InSecTitle@mlpr@true% 1867 | \resetEndKW@mlpr% 1868 | \ifShowSectRules@mlpr@% 1869 | \drawSectionRule@mlpr% 1870 | \fi 1871 | \sectionTitleStyle@mlpr% 1872 | \fi 1873 | \fi 1874 | } 1875 | % \end{macrocode} 1876 | % \end{macro} 1877 | % \begin{macro}{\drawSectionRule@mlpr} 1878 | % This helper macro is used for drawing a horizontal rule just above the 1879 | % current line. 1880 | % \begin{macrocode} 1881 | \newcommand\drawSectionRule@mlpr{% 1882 | % \end{macrocode} 1883 | % We measure the height of the ``M'' character and the depth of the ``j'' 1884 | % character, which we then use to calculate the required vertical offset. 1885 | % \begin{macrocode} 1886 | \setlength\emHeight@mlpr{\fontcharht\font`M}% 1887 | \setlength\jayDepth@mlpr{\fontchardp\font`j}% 1888 | \setlength\sectionRuleOffset@mlpr{% 1889 | \dimexpr.5\emHeight@mlpr% 1890 | +.5\baselineskip% 1891 | -.5\jayDepth@mlpr\relax% 1892 | }% 1893 | % \end{macrocode} 1894 | % We now draw a rule as required (color and dimensions). 1895 | % \begin{macrocode} 1896 | \bgroup% 1897 | \color{\sectionRuleColor@mlpr}% 1898 | \makebox[0em][l]{% 1899 | \raisebox{\sectionRuleOffset@mlpr}[0pt][0pt]% 1900 | {\rule{\lst@linewidth}{\sectionRuleRT@mlpr\baselineskip}}% 1901 | }% 1902 | \egroup% 1903 | } 1904 | % \end{macrocode} 1905 | % \end{macro} 1906 | % 1907 | % \section{Hooking into \lstpkg{}' hooks} 1908 | % 1909 | % We apply some necessary patches in a number of \lstpkg{}' hooks; 1910 | % but first, we define a few helper macros. 1911 | % 1912 | % \paragraph{Helper macros related to hooks} 1913 | % \begin{macro}{\localFontSize@mlpr} 1914 | % This macro will be used to save the current font size. 1915 | % \begin{macrocode} 1916 | \newcommand\localFontSize@mlpr{} 1917 | % \end{macrocode} 1918 | % \end{macro} 1919 | % \begin{macro}{\localBaselineskip@mlpr} 1920 | % This macro will be used to save the current value of |\baselineskip|. 1921 | % \begin{macrocode} 1922 | \newcommand\localBaselineskip@mlpr{} 1923 | % \end{macrocode} 1924 | % \end{macro} 1925 | % \begin{macro}{\scaleInlineCode@mlpr} 1926 | % This helper macro is for setting the font size of inline code to the local 1927 | % font size (only if the \rkeyname{mlscaleinline} key is set). 1928 | % \begin{macrocode} 1929 | \newcommand\scaleInlineCode@mlpr{% 1930 | \lst@ifdisplaystyle% 1931 | \else 1932 | \ifScaleInline@mlpr@% 1933 | % \end{macrocode} 1934 | % We save the values of the current font size and of |\baselineskip| into our 1935 | % dedicated macros\ldots 1936 | % \begin{macrocode} 1937 | \let\localFontSize@mlpr\f@size% 1938 | \let\localBaselineskip@mlpr\f@baselineskip% 1939 | % \end{macrocode} 1940 | % \ldots and we use the basic style but we update the font size. 1941 | % \begin{macrocode} 1942 | \expandafter\def\expandafter\lst@basicstyle\expandafter{% 1943 | \lst@basicstyle% 1944 | \fontsize{\localFontSize@mlpr}{\localBaselineskip@mlpr}% 1945 | \selectfont% 1946 | }% 1947 | \fi 1948 | \fi 1949 | } 1950 | % \end{macrocode} 1951 | % \end{macro} 1952 | % \begin{macro}{\dropOutputAfterHeader@mlpr} 1953 | % This macro detects when the first block (if any) of contiguous of line 1954 | % comments (function header) ends and drops output thereafter. 1955 | % \begin{macrocode} 1956 | \newcommand\dropOutputAfterHeader@mlpr{% 1957 | \ifonlyheader@mlpr@% 1958 | \ifnum\lst@lineno>1% 1959 | \lst@ifLmode% 1960 | \else 1961 | % \end{macrocode} 1962 | % At this stage, the header has definitely ended. 1963 | % If we've already begun dropping output, we don't do anything. 1964 | % \begin{macrocode} 1965 | \ifDroppingOutput@mlpr@% 1966 | % \end{macrocode} 1967 | % Otherwise, we begin dropping output now and we set the switch accordingly. 1968 | % \begin{macrocode} 1969 | \else 1970 | \lst@EnterMode\lst@Pmode{}% 1971 | \lst@BeginDropOutput\lst@Pmode% 1972 | \fi 1973 | \global\DroppingOutput@mlpr@true% 1974 | % \end{macrocode} 1975 | % \begin{macrocode} 1976 | \fi 1977 | \fi 1978 | \fi 1979 | } 1980 | % \end{macrocode} 1981 | % \end{macro} 1982 | % 1983 | % \paragraph{\hookname{InitVarsEOL}} 1984 | % (See the 1985 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation} 1986 | % for more details on this hook.) 1987 | % \begin{macro}{\addedToInitVarsEOL@mlpr} 1988 | % We add this macro (initially empty) to \lstpkg{}' 1989 | % \hookname{InitVarsEOL} hook. 1990 | % \begin{macrocode} 1991 | \newcommand\addedToInitVarsEOL@mlpr{} 1992 | \lst@AddToHook{InitVarsEOL}{\addedToInitVarsEOL@mlpr} 1993 | % \end{macrocode} 1994 | % \end{macro} 1995 | % \begin{macro}{\@ddedToInitVarsEOL@mlpr} 1996 | % The |\addedToInitVarsEOL@mlpr| macro is let to this one under certain 1997 | % conditions (more details follow). 1998 | % \begin{macrocode} 1999 | \newcommand\@ddedToInitVarsEOL@mlpr{% 2000 | % \end{macrocode} 2001 | % \lstpkg{}' built-in mechanism for handling \matlab{} string does not cover 2002 | % the illegal case in which an opening string delimiter is not followed by 2003 | % any matching (closing) string delimiter on the same line. 2004 | % More specifically, \lstpkg{} incorrectly highlights such a broken string 2005 | % literal as a bona-fide \matlab{} string. 2006 | % We improve the situation somewhat, by only highlighting as a string the line 2007 | % containing the unmatched opening delimiter, not the lines that follow it: 2008 | % \begin{macrocode} 2009 | \ifInStr@mlpr@% 2010 | \global\InStr@mlpr@false% 2011 | \lst@LeaveMode% 2012 | \fi 2013 | % \end{macrocode} 2014 | % Clearly, at the very beginning of a line, we're not (not yet, anyway) 2015 | % within a section title, and no visible character has yet occured on that 2016 | % line. 2017 | % \begin{macrocode} 2018 | \global\InSecTitle@mlpr@false% 2019 | \global\VisCharOccured@mlpr@false% 2020 | } 2021 | % \end{macrocode} 2022 | % \end{macro} 2023 | % 2024 | % \paragraph{\hookname{EndGroup}} 2025 | % (See the 2026 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation} 2027 | % for more details on this hook.) 2028 | % \begin{macro}{\addedToEndGroup@mlpr} 2029 | % We add this macro (initially empty) to \lstpkg{}' 2030 | % \hookname{EndGroup} hook. 2031 | % \begin{macrocode} 2032 | \newcommand\addedToEndGroup@mlpr{} 2033 | \lst@AddToHook{EndGroup}{\addedToEndGroup@mlpr} 2034 | % \end{macrocode} 2035 | % \end{macro} 2036 | % \begin{macro}{\@ddedToEndGroup@mlpr} 2037 | % The |\addedToEndGroup@mlpr| macro is let to this one under certain 2038 | % conditions (more details follow). 2039 | % If we were in a string before when \hookname{EndGroup} hook was called, 2040 | % we're now exiting it; 2041 | % therefore, the relevant switch must be reset. 2042 | % \begin{macrocode} 2043 | \newcommand\@ddedToEndGroup@mlpr{\global\InStr@mlpr@false} 2044 | % \end{macrocode} 2045 | % \end{macro} 2046 | % 2047 | % \paragraph{\hookname{PostOutput}} 2048 | % (See the 2049 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation} 2050 | % for more details on this hook.) 2051 | % \begin{macro}{\addedToPostOutput@mlpr} 2052 | % We add this macro (initially empty) to \lstpkg{}' 2053 | % \hookname{PostOutput} hook. 2054 | % \begin{macrocode} 2055 | \newcommand\addedToPostOutput@mlpr{} 2056 | \lst@AddToHook{PostOutput}{\addedToPostOutput@mlpr} 2057 | % \end{macrocode} 2058 | % \end{macro} 2059 | % \begin{macro}{\@ddedToPostOutput@mlpr} 2060 | % The |\addedToPostOutput@mlpr| macro is let to this one under certain 2061 | % conditions (more details follow). 2062 | % If the last processed character was not white space 2063 | % (this check is necessary if \lstpkg{}' \keyname{keepspaces} key is set), 2064 | % we set the relevant switch. 2065 | % \begin{macrocode} 2066 | \newcommand\@ddedToPostOutput@mlpr{% 2067 | \lst@ifwhitespace% 2068 | \else 2069 | \global\VisCharOccured@mlpr@true% 2070 | \fi 2071 | } 2072 | % \end{macrocode} 2073 | % \end{macro} 2074 | % 2075 | % \paragraph{\hookname{Output}} 2076 | % (See the 2077 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation} 2078 | % for more details on this hook.) 2079 | % \begin{macro}{\addedToOutput@mlpr} 2080 | % We add this macro (initially empty) to \lstpkg{}' 2081 | % \hookname{Output} hook. 2082 | % \begin{macrocode} 2083 | \newcommand\addedToOutput@mlpr{} 2084 | \lst@AddToHook{Output}{\addedToOutput@mlpr} 2085 | % \end{macrocode} 2086 | % \end{macro} 2087 | % \begin{macro}{\@ddedToOutput@mlpr} 2088 | % The |\addedToOutput@mlpr| macro is let to this one under certain 2089 | % conditions (more details follow). 2090 | % If the \rkeyname{mlonlyheader} is set, we begin dropping output as soon as 2091 | % we detect that the first contiguous block of line comments has been passed. 2092 | % \begin{macrocode} 2093 | \newcommand\@ddedToOutput@mlpr{\dropOutputAfterHeader@mlpr} 2094 | % \end{macrocode} 2095 | % \end{macro} 2096 | % 2097 | % \paragraph{\hookname{OutputOther}} 2098 | % (See the 2099 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation} 2100 | % for more details on this hook.) 2101 | % \begin{macro}{\addedToOutputOther@mlpr} 2102 | % We add this macro (initially empty) to \lstpkg{}' 2103 | % \hookname{OutputOther} hook. 2104 | % \begin{macrocode} 2105 | \newcommand\addedToOutputOther@mlpr{} 2106 | \lst@AddToHook{OutputOther}{\addedToOutputOther@mlpr} 2107 | % \end{macrocode} 2108 | % \end{macro} 2109 | % \begin{macro}{\@ddedToOutputOther@mlpr} 2110 | % The |\addedToOutputOther@mlpr| macro is let to this one under certain 2111 | % conditions (more details follow). 2112 | % If the \rkeyname{mlonlyheader} is set, we begin dropping output as soon as 2113 | % we detect that the first contiguous block of line comments has been passed. 2114 | % \begin{macrocode} 2115 | \newcommand\@ddedToOutputOther@mlpr{\dropOutputAfterHeader@mlpr} 2116 | % \end{macrocode} 2117 | % \end{macro} 2118 | % 2119 | % \paragraph{\hookname{PreInit}} 2120 | % (See the 2121 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation} 2122 | % for more details on this hook.) 2123 | % Because the |\lst@AddToHook| affects hooks globally 2124 | % (i.e.\ for all listings), 2125 | % we must apply our patches only when required, i.e.\ 2126 | % in listings that use \mllng{}, and not in others. 2127 | % The \hookname{PreInit}, which is called at the very beginning of each 2128 | % listing, is where we do that. 2129 | % \begin{macro}{\addedToPreInitHook@mlpr} 2130 | % In this macro, which we add to \lstpkg{}' \hookname{PreInit} hook, we check 2131 | % whether |\lst@language| and |\languageNormedDefd@mlpr| expand (once) to the 2132 | % same replacement text and only apply our patches under that condition. 2133 | % \begin{macrocode} 2134 | \newcommand\addedToPreInitHook@mlpr{% 2135 | \ifx\lst@language\languageNormedDefd@mlpr% 2136 | \scaleInlineCode@mlpr% 2137 | \renewcommand\addedToInitVarsEOL@mlpr\@ddedToInitVarsEOL@mlpr% 2138 | \renewcommand\addedToEndGroup@mlpr\@ddedToEndGroup@mlpr% 2139 | \renewcommand\addedToPostOutput@mlpr\@ddedToPostOutput@mlpr% 2140 | \renewcommand\addedToOutput@mlpr\@ddedToOutput@mlpr% 2141 | \renewcommand\addedToOutputOther@mlpr\@ddedToOutputOther@mlpr% 2142 | \DroppingOutput@mlpr@false% 2143 | \fi 2144 | } 2145 | \lst@AddToHook{PreInit}{\addedToPreInitHook@mlpr} 2146 | % \end{macrocode} 2147 | % \end{macro} 2148 | % 2149 | % \paragraph{\hookname{DeInit}} 2150 | % (See the 2151 | % \href{http://www.ctan.org/pkg/listings}{\lstpkg{} documentation} 2152 | % for more details on this hook.) 2153 | % In the \hookname{DeInit} hook, which is called at the very end of each 2154 | % listing, we carry out some housekeeping tasks if the current listing uses 2155 | % \mllng{}. 2156 | % \begin{macro}{\addedToDeInitHook@mlpr} 2157 | % In this macro, which we add to \lstpkg{}' \hookname{DeInit} hook, we check 2158 | % whether |\lst@language| and |\languageNormedDefd@mlpr| expand (once) to the 2159 | % same replacement text and, under that condition, we reset all state 2160 | % variables. 2161 | % \begin{macrocode} 2162 | \newcommand\addedToDeInitHook@mlpr{% 2163 | \ifx\lst@language\languageNormedDefd@mlpr% 2164 | \resetEndKW@mlpr% 2165 | \resetClassdefKW@mlpr% 2166 | \global\InStr@mlpr@false% 2167 | \global\VisCharOccured@mlpr@false% 2168 | \global\InSecTitle@mlpr@false% 2169 | \global\DroppingOutput@mlpr@false% 2170 | \fi 2171 | } 2172 | \lst@AddToHook{DeInit}{\addedToDeInitHook@mlpr} 2173 | % \end{macrocode} 2174 | % \end{macro} 2175 | % 2176 | % 2177 | % \section{Key-value interface} 2178 | % 2179 | % We extend \lstpkg{}' key-value interface by defining several additional 2180 | % keys, which we will use to define three \lstpkg{} styles, and which will 2181 | % allow the user to customize the style of their \matlab{} listings, 2182 | % should they which to do so. 2183 | % All \mlpkg{} keys are prefixed by~``|ml|'', so that the user can easily 2184 | % distinguish them from ``native'' \lstpkg{} keys. 2185 | % 2186 | % \paragraph{Keywords} 2187 | % \begin{lstkey}{mlkeywordstyle} 2188 | % \begin{macro}{\keywordStyle@mlpr} 2189 | % In the definition of \mllng{}, we used several classes of \lstpkg{} 2190 | % keywords to handle the different \matlab{} keywords; 2191 | % here is a style key to ``rule them all''. 2192 | % \begin{macrocode} 2193 | \newcommand\keywordStyle@mlpr{} 2194 | \lst@Key{mlkeywordstyle}\relax% 2195 | {\renewcommand\keywordStyle@mlpr{#1}} 2196 | % \end{macrocode} 2197 | % \end{macro} 2198 | % \end{lstkey} 2199 | % 2200 | % \begin{lstkey}{mllastelementstyle} 2201 | % \begin{macro}{\lastElemStyle@mlpr} 2202 | % This key determines the style applied to the last-element keyword. 2203 | % \begin{macrocode} 2204 | \newcommand\lastElemStyle@mlpr{} 2205 | \lst@Key{mllastelementstyle}\relax% 2206 | {\renewcommand\lastElemStyle@mlpr{#1}} 2207 | % \end{macrocode} 2208 | % \end{macro} 2209 | % \end{lstkey} 2210 | % 2211 | % \begin{lstkey}{mloverride} 2212 | % \begin{macro}{\ifOverridecontext@mlpr@} 2213 | % This key overrides the current context, so that context-sensitive 2214 | % keywords be typeset in the style associated with the alternative context. 2215 | % \begin{macrocode} 2216 | \lst@Key{mloverride}{false}[t]% 2217 | {\lstKV@SetIf{#1}\ifOverridecontext@mlpr@} 2218 | % \end{macrocode} 2219 | % \end{macro} 2220 | % \end{lstkey} 2221 | % 2222 | % \paragraph{Strings} 2223 | % \begin{lstkey}{mlstringstyle} 2224 | % \begin{macro}{\stringStyle@mlpr} 2225 | % This key determines the style applied to \matlab{} (quoted and unquoted) 2226 | % strings. 2227 | % \begin{macrocode} 2228 | \newcommand\stringStyle@mlpr{} 2229 | \lst@Key{mlstringstyle}\relax% 2230 | {\renewcommand\stringStyle@mlpr{#1}} 2231 | % \end{macrocode} 2232 | % \end{macro} 2233 | % \end{lstkey} 2234 | % 2235 | % \paragraph{Comments} 2236 | % \begin{lstkey}{mlcommentstyle} 2237 | % \begin{macro}{\commentStyle@mlpr} 2238 | % This key determines the style applied to \matlab{} 2239 | % (to-end-of-line and block) comments. 2240 | % \begin{macrocode} 2241 | \newcommand\commentStyle@mlpr{} 2242 | \lst@Key{mlcommentstyle}\relax% 2243 | {\renewcommand\commentStyle@mlpr{#1}} 2244 | % \end{macrocode} 2245 | % \end{macro} 2246 | % \end{lstkey} 2247 | % 2248 | % \paragraph{Section titles} 2249 | % \begin{lstkey}{mlsectiontitlestyle} 2250 | % \begin{macro}{\sectionTitleStyle@mlpr} 2251 | % This key determines the style applied to \matlab{} section titles. 2252 | % \begin{macrocode} 2253 | \newcommand\sectionTitleStyle@mlpr{} 2254 | \lst@Key{mlsectiontitlestyle}\relax 2255 | {\renewcommand\sectionTitleStyle@mlpr{#1}} 2256 | % \end{macrocode} 2257 | % \end{macro} 2258 | % \end{lstkey} 2259 | % 2260 | % \begin{lstkey}{mlshowsectionrules} 2261 | % \begin{macro}{\ifShowSectRules@mlpr@} 2262 | % This key determines whether an horizontal rule gets printed above each 2263 | % section title. 2264 | % \begin{macrocode} 2265 | \lst@Key{mlshowsectionrules}{false}[t]% 2266 | {\lstKV@SetIf{#1}\ifShowSectRules@mlpr@} 2267 | % \end{macrocode} 2268 | % \end{macro} 2269 | % \end{lstkey} 2270 | % 2271 | % \begin{lstkey}{mlsectionrulethickness} 2272 | % \begin{macro}{\sectionRuleRT@mlpr} 2273 | % This key determines the relative thickness of the horizontal rule that 2274 | % gets printed above each section title. 2275 | % \begin{macrocode} 2276 | \newcommand\sectionRuleRT@mlpr{.05} 2277 | \lst@Key{mlsectionrulethickness}\relax% 2278 | {\renewcommand\sectionRuleRT@mlpr{#1}} 2279 | % \end{macrocode} 2280 | % \end{macro} 2281 | % \end{lstkey} 2282 | % 2283 | % \begin{lstkey}{mlsectionrulecolor} 2284 | % \begin{macro}{\sectionRuleColor@mlpr} 2285 | % This key determines the color of the horizontal rule that gets printed 2286 | % above each section title. 2287 | % \begin{macrocode} 2288 | \newcommand\sectionRuleColor@mlpr{black!15} 2289 | \lst@Key{mlsectionrulecolor}\relax% 2290 | {\renewcommand\sectionRuleColor@mlpr{#1}} 2291 | % \end{macrocode} 2292 | % \end{macro} 2293 | % \end{lstkey} 2294 | % 2295 | % \paragraph{System commands} 2296 | % \begin{lstkey}{mlsyscomstyle} 2297 | % \begin{macro}{\syscomStyle@mlpr} 2298 | % This key determines the style applied to system commands. 2299 | % \begin{macrocode} 2300 | \newcommand\syscomStyle@mlpr{} 2301 | \lst@Key{mlsyscomstyle}\relax% 2302 | {\renewcommand\syscomStyle@mlpr{#1}} 2303 | % \end{macrocode} 2304 | % \end{macro} 2305 | % \end{lstkey} 2306 | % 2307 | % \paragraph{Variables with shared scope} 2308 | % For convenience, we create a brand new class of \lstpkg{} keywords for 2309 | % allowing the user to define \matlab{} variables with shared scope. 2310 | % 2311 | % \begin{macro}{\InstallKeywords@mlpr} 2312 | % This helper macro (which is based on \lstpkg{}' |\lst@InstallKeywords|), 2313 | % will let us defines four keys in one go, all prefixed by |ml|. 2314 | % \begin{macrocode} 2315 | \gdef\InstallKeywords@mlpr#1#2#3#4#5{% 2316 | \lst@Key{ml#2}\relax 2317 | {\lst@UseFamily{#2}[\@ne]##1\relax\lst@MakeKeywords}% 2318 | \lst@Key{mlmore#2}\relax 2319 | {\lst@UseFamily{#2}[\@ne]##1\relax\lst@MakeMoreKeywords}% 2320 | \lst@Key{mldelete#2}\relax 2321 | {\lst@UseFamily{#2}[\@ne]##1\relax\lst@DeleteKeywords}% 2322 | \ifx\@empty#3\@empty\else 2323 | \lst@Key{#3}{#4}{\@namedef{lst@#3}{##1}}% 2324 | \fi 2325 | \expandafter\lst@InstallFamily@ 2326 | \csname\@lst @#2@data\expandafter\endcsname 2327 | \csname\@lst @#5\endcsname {#1}{#2}{#3} 2328 | } 2329 | % \end{macrocode} 2330 | % \end{macro} 2331 | % 2332 | % \begin{lstkey}{mlsharedvars} 2333 | % \begin{lstkey}{mlmoresharedvars} 2334 | % \begin{lstkey}{mldeletesharedvars} 2335 | % \begin{lstkey}{mlsharedvarstyle} 2336 | % We now use |\InstallKeywords@mlpr| to define the four keys in question: 2337 | % \rkeyname{mlsharedvars}, which can be used to define a list of \matlab{} 2338 | % variables with shared scope; 2339 | % \rkeyname{mlmoresharedvars}, which can be used to add elements to the 2340 | % current list of such variables; 2341 | % \rkeyname{mldeletesharedvars}, which can be used to remove elements 2342 | % from that list; 2343 | % and \rkeyname{mlsharedvarstyle}, which determines the style applied to 2344 | % variables with shared scope. 2345 | % \begin{macrocode} 2346 | \InstallKeywords@mlpr k{sharedvars}{mlsharedvarstyle}\relax% 2347 | {mlsharedvarstyle}{}ld 2348 | % \end{macrocode} 2349 | % \end{lstkey} 2350 | % \end{lstkey} 2351 | % \end{lstkey} 2352 | % \end{lstkey} 2353 | % 2354 | % \paragraph{Delimiters for unquoted strings} 2355 | % \begin{lstkey}{mlunquotedstringdelim} 2356 | % This key allows the user to define custom delimiters^^A 2357 | % ---which do not get printed in the output---^^A 2358 | % for unquoted strings. 2359 | % \begin{macrocode} 2360 | \lst@Key{mlunquotedstringdelim}\relax% 2361 | {\lst@DelimKey\relax{[is][\stringStyle@mlpr]{#1}}} 2362 | % \end{macrocode} 2363 | % \end{lstkey} 2364 | % 2365 | % \paragraph{Placeholders} 2366 | % \begin{lstkey}{mlplaceholderstyle} 2367 | % \begin{macro}{\phStyle@mlpr} 2368 | % This key determines the style applied to placeholder content; 2369 | % the color of placeholder delimiters is designed to match that of 2370 | % placeholder content. 2371 | % \begin{macrocode} 2372 | \newcommand\phStyle@mlpr{} 2373 | \lst@Key{mlplaceholderstyle}\relax% 2374 | {\renewcommand\phStyle@mlpr{#1}} 2375 | % \end{macrocode} 2376 | % \end{macro} 2377 | % \end{lstkey} 2378 | % 2379 | % \mlpkg{} currently does not offer a nice interface for customizing 2380 | % code-snippet placeholder delimiters; in a future release, perhaps. 2381 | % 2382 | % \paragraph{Automatic scaling of inline code} 2383 | % \begin{lstkey}{mlscaleinline} 2384 | % \begin{macro}{\ifScaleInline@mlpr@} 2385 | % This key determines whether the font size of inline \matlab{} code should 2386 | % match the local font size. 2387 | % \begin{macrocode} 2388 | \lst@Key{mlscaleinline}{true}[t]% 2389 | {\lstKV@SetIf{#1}\ifScaleInline@mlpr@} 2390 | % \end{macrocode} 2391 | % \end{macro} 2392 | % \end{lstkey} 2393 | % 2394 | % \paragraph{Printing only a function's signature and header} 2395 | % \begin{lstkey}{mlonlyheader} 2396 | % \begin{macro}{\ifonlyheader@mlpr@} 2397 | % This key determines whether output is dropped after the first block of 2398 | % contiguous line comments. 2399 | % \begin{macrocode} 2400 | \lst@Key{mlonlyheader}{false}[t]% 2401 | {\lstKV@SetIf{#1}\ifonlyheader@mlpr@} 2402 | % \end{macrocode} 2403 | % \end{macro} 2404 | % \end{lstkey} 2405 | % 2406 | % 2407 | % \section{Two user-level macros} 2408 | % 2409 | % \begin{macro}{\mlttfamily} 2410 | % This user-level macro can be used for selecting a scaled version of the 2411 | % Bera Mono font, a typewriter font family which, contrary to typewriter 2412 | % \TeX{} fonts, conveniently comes with a boldface version. 2413 | % \begin{macrocode} 2414 | \newcommand\mlttfamily{% 2415 | \def\fvm@Scale{.85}% 2416 | \fontfamily{fvm}\selectfont% 2417 | } 2418 | % \end{macrocode} 2419 | % \end{macro} 2420 | % 2421 | % \paragraph{Code-snippet placeholders} 2422 | % \begin{macro}{\mlplaceholder} 2423 | % This user-level macro can be used to typeset placeholders in code snippets. 2424 | % \begin{macrocode} 2425 | \newcommand\mlplaceholder[1]{% 2426 | \bgroup% 2427 | \phStyle@mlpr% 2428 | \bgroup% 2429 | \phDelimStyle@mlpr% 2430 | \phOpDelim@mlpr% 2431 | \egroup% 2432 | #1\itcorr@mlpr% 2433 | \bgroup% 2434 | \phDelimStyle@mlpr% 2435 | \phClDelim@mlpr% 2436 | \egroup% 2437 | \egroup% 2438 | } 2439 | % \end{macrocode} 2440 | % \end{macro} 2441 | % 2442 | % 2443 | % \section{Other helper macros} 2444 | % 2445 | % \begin{macrocode} 2446 | \newcommand\phDelimStyle@mlpr{\rmfamily\upshape} 2447 | % \end{macrocode} 2448 | % \begin{macrocode} 2449 | \newcommand\phOpDelim@mlpr{\textlangle} 2450 | % \end{macrocode} 2451 | % \begin{macrocode} 2452 | \newcommand\phClDelim@mlpr{\textrangle} 2453 | % \end{macrocode} 2454 | % 2455 | % \begin{macro}{\itcorr@mlpr} 2456 | % This macro is used for applying italic correction in case the current font 2457 | % shape is either italic or slanted. 2458 | % \begin{macrocode} 2459 | \newcommand\itcorr@mlpr{% 2460 | % \end{macrocode} 2461 | % We define a (long) macro that expands (once) to the current font shape, 2462 | % for comparison purposes. 2463 | % \begin{macrocode} 2464 | \expandafter\newcommand\expandafter\long@f@shape@mlpr% 2465 | \expandafter{\f@shape}% 2466 | % \end{macrocode} 2467 | % If the current font shape is either italic or slanted, we apply italic 2468 | % correction. 2469 | % \begin{macrocode} 2470 | \ifx\long@f@shape@mlpr\itdefault% 2471 | \/% 2472 | \else 2473 | \ifx\long@f@shape@mlpr\sldefault% 2474 | \/% 2475 | \fi 2476 | \fi 2477 | } 2478 | % \end{macrocode} 2479 | % \end{macro} 2480 | % 2481 | % 2482 | % \section{\texorpdfstring{\mlpkg{}}{matlab-prettifier} styles} 2483 | % 2484 | % We now define three \lstpkg{} styles for \matlab{} listings. 2485 | % 2486 | % \paragraph{Base style} 2487 | % 2488 | % This style is used internally to define the three user-level styles. 2489 | % It's not meant to be used outside this package file. 2490 | % \begin{macro}{\toks@mlpr} 2491 | % We allocate a token list register in which we store settings that we'll use 2492 | % to define the style. 2493 | % \begin{macrocode} 2494 | \newtoks\toks@mlpr 2495 | \toks@mlpr={% 2496 | language = \languageNormedDefd@mlpr, 2497 | basicstyle = \color{black}\ttfamily\normalsize, 2498 | breaklines = true, 2499 | showspaces = false, 2500 | showstringspaces = false, 2501 | upquote = true, 2502 | rulecolor = \color{black!67}, 2503 | numberstyle = \color{black!33}, 2504 | mlscaleinline = true, 2505 | mlonlyheader = false, 2506 | } 2507 | % \end{macrocode} 2508 | % \end{macro} 2509 | % \begin{macrocode} 2510 | \ifframed@mlpr@ 2511 | \toks@mlpr=\expandafter{\the\toks@mlpr frame=single,} 2512 | \fi 2513 | \ifnumbered@mlpr@ 2514 | \toks@mlpr=\expandafter{\the\toks@mlpr numbers=left,} 2515 | \fi 2516 | \begingroup\edef\@tempa{\endgroup 2517 | \noexpand\lstdefinestyle{MatlabBaseStyle@mlpr}{\the\toks@mlpr} 2518 | }\@tempa 2519 | % \end{macrocode} 2520 | % 2521 | % \paragraph{Standard style} 2522 | % Standard style of the \matlab{} editor. 2523 | % \begin{macro}{\mlbwphstyle}^^A FIXME: to be documented 2524 | % This user macro holds the placeholder style used in the 2525 | % \mlsty{Matlab-editor} style. 2526 | % \begin{macrocode} 2527 | \newcommand\mleditorphstyle{\color[RGB]{209,000,086}\rmfamily\itshape} 2528 | % \end{macrocode} 2529 | % \end{macro} 2530 | % \begin{macrocode} 2531 | \lstdefinestyle{Matlab-editor}{% 2532 | style = MatlabBaseStyle@mlpr, 2533 | mllastelementstyle = \color{black} , 2534 | mlkeywordstyle = \color[RGB]{000,000,255} , 2535 | mlcommentstyle = \color[RGB]{034,139,034} , 2536 | mlstringstyle = \color[RGB]{160,032,240} , 2537 | mlsyscomstyle = \color[RGB]{178,140,000} , 2538 | mlsectiontitlestyle = \commentStyle@mlpr \bfseries, 2539 | mlsharedvarstyle = \color[RGB]{000,163,163} , 2540 | mlplaceholderstyle = \mleditorphstyle, 2541 | } 2542 | % \end{macrocode} 2543 | % 2544 | % \paragraph{Black \& white style} 2545 | % Black \& white, printer-friendly style. 2546 | % \begin{macro}{\mlbwphstyle}^^A FIXME: to be documented 2547 | % This user macro holds the placeholder style used in the 2548 | % \mlsty{Matlab-bw} style. 2549 | % \begin{macrocode} 2550 | \newcommand\mlbwphstyle{\color[gray]{0}\rmfamily\itshape} 2551 | % \end{macrocode} 2552 | % \end{macro} 2553 | % \begin{macrocode} 2554 | \lstdefinestyle{Matlab-bw}{% 2555 | style = MatlabBaseStyle@mlpr, 2556 | mlkeywordstyle = \color[gray]{0} \bfseries , 2557 | mlcommentstyle = \color[gray]{.75} \itshape, 2558 | mlstringstyle = \color[gray]{.5} , 2559 | mlsyscomstyle = \color[gray]{.25} , 2560 | mlsectiontitlestyle = \color[gray]{.75}\bfseries\itshape, 2561 | mlsharedvarstyle = \color[gray]{0} , 2562 | mlplaceholderstyle = \mlbwphstyle, 2563 | } 2564 | % \end{macrocode} 2565 | % 2566 | % \paragraph{Style of Pygments' MatlabLexer} 2567 | % Style that closely mimics that of Pygments' `MatlabLexer'. 2568 | % \begin{macro}{\mlpyglikephstyle}^^A FIXME: to be documented 2569 | % This user macro holds the placeholder style used in the 2570 | % \mlsty{Matlab-Pyglike} style. 2571 | % \begin{macrocode} 2572 | \newcommand\mlpyglikephstyle{\color[RGB]{127,063,127}\rmfamily\itshape} 2573 | % \end{macrocode} 2574 | % \end{macro} 2575 | % \begin{macrocode} 2576 | \lstdefinestyle{Matlab-Pyglike}{% 2577 | style = MatlabBaseStyle@mlpr, 2578 | mllastelementstyle = \color[RGB]{127,000,000} , 2579 | mlkeywordstyle = \color[RGB]{000,127,000}\bfseries , 2580 | mlcommentstyle = \color[RGB]{063,127,127} \itshape, 2581 | mlstringstyle = \color[RGB]{186,034,034} , 2582 | mlsyscomstyle = \color[RGB]{000,127,000} , 2583 | mlsectiontitlestyle = \color[RGB]{063,127,127} \itshape, 2584 | mlsharedvarstyle = \color[RGB]{034,034,186} , 2585 | mlplaceholderstyle = \mlpyglikephstyle, 2586 | } 2587 | % \end{macrocode} 2588 | % 2589 | % \Finale 2590 | \endinput 2591 | --------------------------------------------------------------------------------