Code covered by the BSD License  

Highlights from
m-code to LaTeX converter

image thumbnail

m-code to LaTeX converter

by

 

22 Jun 2009 (Updated )

This m-file (with GUI) converts m-code into a tex-file for including in a LaTeX-document.

m-code to LaTeX converter

This m-file (with GUI) converts m-code into a tex-file for including in a LaTeX-document.

This file lets you very easy INCLUDE COLORED M-CODE in your LaTeX-file.
After you run this m-file "m2tex.m" and inlcude the output tex-file in your LaTeX document, you will experience NO DIFFERENCE IN THE APPEARANCE to the look of the m-code in the Matlab Editor. (except for the apostrophs)
There are SEVERAL WAYS TO EXECUTE the program.
1. Run the file by pressing F5 oder click the "Run" button in the Matlab Editor, while the m2tex.m file is open or type "m2tex" in the Command Window.
==> The program will open the GUI and the rest goes from there.
2. Call the program from the Command Window or another m-file with at least one option. The order of the options is not important. For example:
m2tex('num','C:\Programme\MATLAB\work\testfile.m','C:\latex_documents\testfile.tex')
m2tex('testfile.m','testoutputfile.tex', 'no_num','bwc')
There are ONLY TWO STEPS necessary to do to include your code:
1. Run "m2tex.m" (with the desired m-file to include).
2. Insert the code into your main LaTeX-document by adding the whole "filename.tex"-file with \include{filename} or \input{filename}.
For Example:
\usepackage{fancyvrb}
\usepackage{color}
...
\begin{singlespace} % only optional % you need \usepackage{setspace}
\footnotesize
\input{outputfile} % output from "m2tex.m", but without the extension ".tex"
\end{singlespace} % for changing your linespacing
\normalsize
Features:
 - recognizes all keywords, strings and comments
 - recognizes all indents and tabs
 - recognizes cell titles
 - writes all recognized objects correct in a tex-file
 - uses original Matlab colors
 - the font looks almost the same as in Matlab Editor
 - tex-file is saved using fontencoding "UTF-8", so that German Umlauts will be written correct
 - option for numbered code lines ('num' or 'no_num')
 - recognizes a linebreak, but only with a leading space character, i.e. " ..." and only once in a line
 - option for input- and output-file (*.m respectively *.tex-file)
 - execution via GUI or command line
-----------------------------------------------------------------
The conversion of the linebreak works only, if it is once in a line, because the command "regexprep" (code line: 1385) won't work, if you are looking for a string with three dots: '...'
--> If anyone knows why or a solution around the problem, please tell me! thx

Contact us