image
Physics Forums Logo
image
image
* Register * Upgrade Blogs Library Staff Rules Mark Forums Read
image
image   image
image

image attach matlab code in latex Share It Thread Tools Search this Thread image
Old Jun7-09, 06:16 AM                  #1
ladil123

ladil123 is Offline:
Posts: 45
attach matlab code in latex

Hello!

Im writing a technical report with "article" as documentclass in Latex.

I want to attach my matlab code in the appendix.
If I copy and paste the text it wont look like the matlab code but it will look like a report..

What command should I use so the text just looks like it is ?

Danne
  Reply With Quote
Old Jun7-09, 06:18 AM                  #2
cristo

PF Mentor

cristo is Offline:
Posts: 7,240
Re: attach matlab code in latex

Enter the matlab code in a "verbatim" environment. (I.e. \begin{verbatim}..code..\end{verbatim})
  Reply With Quote
Old Jun7-09, 08:03 AM                  #3
robphy
 
robphy's Avatar

robphy is Offline:
Posts: 3,690
Blog Entries: 47
Recognitions:
PF Contributor PF Contributor
Homework Helper Homework Helper
Science Advisor Science Advisor
Re: attach matlab code in latex

If you want something fancier, you can try the listings package

http://www.google.com/search?q=listings+latex
  Reply With Quote
Old Jun17-09, 09:29 AM                  #4
las3rjock

las3rjock is Offline:
Posts: 223
Re: attach matlab code in latex

I second the use of the listings package. I put the following in my document preamble whenever I need to include MATLAB code in a LaTeX document:
Code:
\usepackage{listings}
\usepackage[usenames,dvipsnames]{color}
% This is the color used for MATLAB comments below
\definecolor{MyDarkGreen}{rgb}{0.0,0.4,0.0}

% For faster processing, load Matlab syntax for listings
\lstloadlanguages{Matlab}%
\lstset{language=Matlab,                        % Use MATLAB
        frame=single,                           % Single frame around code
        basicstyle=\small\ttfamily,             % Use small true type font
        keywordstyle=[1]\color{Blue}\bf,        % MATLAB functions bold and blue
        keywordstyle=[2]\color{Purple},         % MATLAB function arguments purple
        keywordstyle=[3]\color{Blue}\underbar,  % User functions underlined and blue
        identifierstyle=,                       % Nothing special about identifiers
                                                % Comments small dark green courier
        commentstyle=\usefont{T1}{pcr}{m}{sl}\color{MyDarkGreen}\small,
        stringstyle=\color{Purple},             % Strings are purple
        showstringspaces=false,                 % Don't put marks in string spaces
        tabsize=5,                              % 5 spaces per tab
        %
        %%% Put standard MATLAB functions not included in the default
        %%% language here
        morekeywords={xlim,ylim,var,alpha,factorial,poissrnd,normpdf,normcdf},
        %
        %%% Put MATLAB function parameters here
        morekeywords=[2]{on, off, interp},
        %
        %%% Put user defined functions here
        morekeywords=[3]{FindESS, homework_example},
        %
        morecomment=[l][\color{Blue}]{...},     % Line continuation (...) like blue comment
        numbers=left,                           % Line numbers on left
        firstnumber=1,                          % Line numbers start with line 1
        numberstyle=\tiny\color{Blue},          % Line numbers are blue
        stepnumber=5                            % Line numbers go in steps of 5
        }

% Includes a MATLAB script.
% The first parameter is the label, which also is the name of the script
%   without the .m.
% The second parameter is the optional caption.
\newcommand{\matlabscript}[2]
  {\begin{itemize}\item[]\lstinputlisting[caption=#2,label=#1]{#1.m}\end{itemize}}
These settings are based on those used in a LaTeX homework template by Ted Pavlic.
  Reply With Quote
Old Jun24-09, 03:49 AM                  #5
maverick280857

maverick280857 is Offline:
Posts: 1,489
Re: attach matlab code in latex

I used mcode.sty for this, and it did a fine job for me.
  Reply With Quote
image image
Reply
Thread Tools


Similar Threads for: attach matlab code in latex
Thread Thread Starter Forum Replies Last Post
LaTeX code for Quantum dsr39 Quantum Physics 1 Mar4-09 10:52 PM
another way to input latex code here using LYX zyh Math & Science Learning Materials 0 Sep29-08 08:53 AM
Convert latex code to fortran code? nancy2fancy1 Programming & Comp Sci 1 Dec9-07 05:20 PM
DELETE THREAD need the latex code Phymath General Engineering 0 Apr27-05 04:29 PM
LaTeX Code IooqXpooI General Discussion 1 May21-04 12:18 AM

Powered by vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd. © 2009 Physics Forums
Sciam | physorgPhysorg.com Science News Partner
image
image   image