LaTeX In Matlab - Auburn University

Transcription

Figure AnnotationM-File PublishingMatricesLATEX in MatlabAaron BiddingsElectrical and Computer EngineeringAuburn UniversityJuly 26, 20101 / 22

Figure AnnotationM-File PublishingMatricesOutline1Figure AnnotationMatlab Function SyntaxExample2M-File PublishingWhat is it?Output Format3Matrices2 / 22

Figure AnnotationM-File PublishingMatricesMatlab Function SyntaxExampleOutline1Figure AnnotationMatlab Function SyntaxExample2M-File PublishingWhat is it?Output Format3Matrices3 / 22

Figure AnnotationM-File PublishingMatricesMatlab Function SyntaxExampleFigure AnnotationLATEX in MatlabThe manipulation of figure annotation is very simple andstraightforward. One only needs to utilize the basic Matlabfunctions such as title, xlabel, ylabel, and text. In addition,Matlab’s text interpreter must be set to handle LATEX coding. Thisis done by simply supplying the necessary properties to the aforementioned functions.4 / 22

Figure AnnotationM-File PublishingMatricesMatlab Function SyntaxExampleFigure AnnotationHere are examples showing the syntax for each function. All arethe same with the exception that coordinates must also bespecified for the figure text PropertyValue1’, tyValue1’, tyValue1’, .)text(X, 1’, .)5 / 22

Figure AnnotationM-File PublishingMatricesMatlab Function SyntaxExampleFigure AnnotationHere is shown some simple coding for a Matlab plot exemplifyingone possible application of each function:closex -pi:.1:pi;y sin(x);plot(x,y)title([’Sine x’],’interpreter’,’latex’, ’FontSize’, 15)ylabel([’y ’],’interpreter’,’latex’, ’FontSize’, 15)text(-3.5, 0.8,’y sin(x)’, ’interpreter’, ’latex’, ’FontSize’, 15)6 / 22

Figure AnnotationM-File PublishingMatricesMatlab Function SyntaxExampleFigure AnnotationResults:Note the mathematical variables and equation within the labelsand text generated by LATEX syntax.7 / 22

Figure AnnotationM-File PublishingMatricesWhat is it?Output FormatOutline1Figure AnnotationMatlab Function SyntaxExample2M-File PublishingWhat is it?Output Format3Matrices8 / 22

Figure AnnotationM-File PublishingMatricesWhat is it?Output FormatM-File PublishingThe MATLAB product allows you to quickly publish your M-filecode to enable you to describe and share your code with otherswho may or may not have MATLAB software. Acceptable formatsfor publishing are: HTML, XML, LATEX, Microsoft Word R , andMicrosoft PowerPoint R .9 / 22

Figure AnnotationM-File PublishingMatricesWhat is it?Output FormatM-File PublishingThe benefit of publishing an M-File is that the generateddocument appears polished rather than as a mere text file of code.There are two ways to format an M-File in order to specify how thepublished results will appear:1Use drop-down menu options to automatically inserts the textmarkup symbolsCell Insert Text Markup LATEX Markup2Type the markup symbols directly in the commentsNote: Using the drop-down menu will produce a defaultcommented text which can then be edited using LATEX syntax.10 / 22

Figure AnnotationM-File PublishingMatricesWhat is it?Output FormatM-File PublishingAfter creating the M-File, but before publishing it, the outputformat must be set to handle LATEX code. In the M-File editor,click the little black arrow which is adjacent the publish button inorder to display it’s drop down menu.Then select Edit Publish Configuration for filename.m. This willopen the ”Edit M-File Configurations” window.11 / 22

Figure AnnotationM-File PublishingMatricesWhat is it?Output FormatM-File PublishingNext, double-click the Output file format property in the ”Publishsettings” properties table and select latex from the drop-downmenu.12 / 22

Figure AnnotationM-File PublishingMatricesWhat is it?Output FormatM-File PublishingNext, select User Default in the Publish Settings drop-down menuand click ”Save As.”.Finally, click Publish and Close.13 / 22

Figure AnnotationM-File PublishingMatricesWhat is it?Output FormatM-File PublishingBy default, MATLAB publishes the M-file to an /html subdirectoryof the directory containing the M-file. This is where it stores thegenerated .tex file (which has the same name as the .m file) whichnow opens in the Matlab M-File editor. This file can now becompiled from a LATEX editor to generate a LATEX document.14 / 22

Figure AnnotationM-File PublishingMatricesOutline1Figure AnnotationMatlab Function SyntaxExample2M-File PublishingWhat is it?Output Format3Matrices15 / 22

Figure AnnotationM-File PublishingMatricesMatricesThe following is an example of using LATEX code in Matlab togenerate a published document showing a formatted matrix.16 / 22

Figure AnnotationM-File PublishingMatricesMatricesCommented text was first inserted into an M-File using thedrop-down menus (i.e. Cell Insert Text Markup LATEX Markup). Then the inserted text was edited to produce amatrix using LATEX syntax.%%%% latex % \[ \left[% \begin{array}{ c c c }% 1 & 2 & 3% 4 & 5 & 6% 7 & 8 & 9% \end{array} \right]% \]% /latex 17 / 22

Figure AnnotationM-File PublishingMatricesMatricesNext, publish the M-File to generate a .tex file which willautomatically be saved in the newly created /html subdirectory.18 / 22

Figure AnnotationM-File PublishingMatricesMatrices% This LaTeX was auto-generated from an M-file by MATLAB.% To make changes, update the M-file and republish this begin{par}\[ \left[ \begin{array}{ c c c } 1 & 2 & 3\\ 4 & 5 & 6\\7 & 8 & 9 \end{array} \right] \]\end{par} \vspace{1em}19 / 22\end{document}

Figure AnnotationM-File PublishingMatricesMatricesFinally, compiling the .tex file produced the following output in a.pdf document:20 / 22

Figure AnnotationM-File PublishingMatricesReferences1Matlab Help Menu (Help Product s/2/2d/LaTeX.pdf3www.google.com21 / 22

Figure AnnotationM-File PublishingMatricesThank You22 / 22

By default, MATLAB publishes the M- le to an /html subdirectory of the directory containing the M- le. This is where it stores the generated .tex le (which has the same name as the .m le) which now opens in the Matlab M-File editor. This le can now be compiled from a LATEX editor to generate a LATEX document. 14/22