LaTeX技巧57:使用mcode宏包在LATEX制作m文件效果

标签:
latexmcode插入matlab代码matlab |
分类: 宏包使用 |
QQ群:91940767/145316219/141877998/80300084/194770436
淘宝店:http://latexstudio.taobao.com
Email:latexstudio@hotmail.com
常见数学公式问题集下载
http://www.mathworks.com/matlabcentral/fileexchange/8015-m-code-latex-package,http://www.knorn.org/misc_files/mcode_demo.zip给出了一个示例。
2010年5月4日最新升级了该包。mcode实际基于listings开发的(支持多种编程语言的,http://en.wikibooks.org/wiki/LaTeX/Packages/Listings),大家可以也学习一下。此外还有"xcolor","textcomp"。mcode主要是为了用起来更简单方便。
示例:
\documentclass{article} % load package with ``framed'' and ``numbered'' option. \usepackage[framed,numbered]{mcode} % something NOT relevant to the usage of the package. \setlength{\parindent}{0pt} \setlength{\parskip}{18pt} \title{\texttt{mcode.sty} Demo} \author{Florian Knorn, \texttt{florian@knorn.org}} % ////////////////////////////////////////////////// \begin{document} \maketitle \textbf{Installation of the package:} As with any other package, just place the \verb|mcode.sty| file in the same folder as your document, or put it somewhere where \LaTeX{} can find it. 1) This inline demo \mcode{for i=1:3, disp('cool'); end;} uses the \verb|\mcode{}| command. 2) The following is a block using the \verb|lstlisting| environment. \begin{lstlisting} for i=1:3 end \end{lstlisting} Note: That package was loaded with the \verb|framed| and \verb|numbered| option. 3) Finally, you can also directly include an external m-file from somewhere on your hard drive (the very code you use in \textsc{Matlab}, if you want) using the \verb|\lstinputlisting{/SOME/PATH/FILENAME.M}| command. \textbf{Remkark:} As pointed out by ``turker'' in a comment at the \textsc{MatlabCentral} listing of the package, there can be a problem if you use the word \texttt{end} to access the last element in a vector (line 3 in the example above) --- this would normally be typeset in blue by default, as it will be considered as a keyword (just like in line 4 above). Florian (\texttt{florian@knorn.org}) \end{document} |
效果如下:
宏包下载地址:
http://cid-3cfe530319707374.office.live.com/self.aspx/ChinaTeX/mcode.zip
http://cid-3cfe530319707374.office.live.com/self.aspx/ChinaTeX/mcode^_demo.zip