Inserting Matlab code in Latex

Source: Internet
Author: User

This article will show you how to add Matlab code to the Latex typesetting process.

Functional effects

Mainly has the following typesetting function:

    • Syntax highlighting
    • Automatically add borders
    • Add line numbers automatically

First, let's feel the effect.

listingsPackage

First make sure you can use the listings package

Simple and quick way to use the following

\usepackage{listings}\lstset{ language=matlab}\begin{lstlisting}% Plot function  Span class= "Hljs-title" >f  (x ) = 2  *x  ^3 -x -2   ezplot ( ' 2*x^3-x-2 ' , [0 , 2 ]) hold on   plot ([0 , 2 ],[ 0 , 0 ], ' R ' ) \< Span class= "hljs-function" >end  {lstlisting } 

Let's take a look at the effect:

Next use mcode style

mcodePackage

Mcode

There are three main methods of use

  1. Inserting code blocks

    \usepackage{listings}\usepackage[framed,numbered, autolinebreaks,useliterate]{mcode}\begin{lstlisting}% Plot  function  f  (x ) = 2  *x  ^3 -x -2   Ezplot ( Span class= "hljs-string" > ' 2*x^3-x-2 ' , [0 , 2 ]) hold on   plot ([ 0 , 2 ],[0 , Span class= "Hljs-number" >0 ], ' R ' ) \end  {lstlisting }  

    Let's take a look at the effect:

    The comparison found just a simple addition to the following sentence code

    \usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
  2. Inserting Matlab statements in a paragraph

    Simply insert the following statement in the paragraph or footer edit

    \mcode{for i=1:3, disp(‘cool‘end;}in footnotes: \mcodefn{for i=1:3, disp(‘cool‘end;}}

    Even with \mcode{}
    The effect is as follows

  3. Embed .m files

See the references below for more details

Reference documents

Listings Help Documentation

Mcode Help Documentation

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Inserting Matlab code in Latex

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.