m-code to LaTeX converter
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
Cite As
Uwe Lelke (2024). m-code to LaTeX converter (https://www.mathworks.com/matlabcentral/fileexchange/24515-m-code-to-latex-converter), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.10.0.0 | Updated to include an App file for R2012b |
||
1.9.0.0 | 1. New option 'bwc' for code in black and white
|
||
1.8.0.0 | I corrected all things in respect to the false strings.
|
||
1.7.0.0 | I upgraded the input options for specifying a source and target file, for example (instead of only a filename, you can write there the whole path):
I have also added a GUI (my first one). |
||
1.6.0.0 | "if else end" can be handled now in one line, which the program was already supposed to do.
|
||
1.5.0.0 | Corrected a minor error with respect to lines, which contain only space characters cause of a kindly tip from an user. |
||
1.4.0.0 | Upgraded the distinction between strings, e.g 'xyz' and apostrophs for transpose purpose, e.g. G=P*C'/(C*P*C'+R). |
||
1.3.0.0 | Corrected a minor error in respect of one single "second word" string.
|
||
1.2.0.0 | recognizes now a linebreak, but only with a leading space character, i.e. " ..." and only once in a line |
||
1.1.0.0 | (just minor things updated and a photo of the output)
|
||
1.0.0.0 |