Hello
I've many Matlab files and I wanna import their code into my latex file. I know it exists the function matlab2latex in Matlab but then I've to copy-paste one by one all the file code what it's a lot of work. Does a latex command exist which imports the Matlab code from a file into the Latex file?
Thanks for your help!
Conversion Tools ⇒ Import Matlab Code to Latex File
Re: Import Matlab Code to Latex File
I think you need listings package, it has an option for Matlab code and can import code from external files.
Ignasi
Ignasi
Import Matlab Code to Latex File
Thank you for the advice. Now, it works. I solved my problem with the following code.
Settings in the header:
Command to import the Matlab text in the LaTeX document:
Settings in the header:
Code: Select all
\usepackage{listings}
\lstset{
language=Matlab, % choose the language of the code
% basicstyle=10pt, % the size of the fonts that are used for the code
numbers=left, % where to put the line-numbers
numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
stepnumber=1, % the step between two line-numbers. If it's 1 each line will be numbered
numbersep=5pt, % how far the line-numbers are from the code
% backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
% frame=single, % adds a frame around the code
% tabsize=2, % sets default tabsize to 2 spaces
% captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
escapeinside={\%*}{*)} % if you want to add a comment within your code
}
Code: Select all
\lstinputlisting[language=Matlab]{file_name.m}
Re: Import Matlab Code to Latex File
I am currently trying to display an .m file in my report. I use the code displayed above. The content is displayed accordingly but I get an annoying error message:
inputenc: Keyboard character used is undefined(inputenc) in inputencoding `utf8'
Does anybody have a solution for this problem.
inputenc: Keyboard character used is undefined(inputenc) in inputencoding `utf8'
Does anybody have a solution for this problem.
Re: Import Matlab Code to Latex File
You can change the encoding of your m-file.
Open it in an editor (e.g. Notepad++) and then save the file anew, with a different encoding. ANSI should work.
Potential warning: I don't know, how Matlab will react, when it tries to use that m-file and it is not utf8 encoded
Open it in an editor (e.g. Notepad++) and then save the file anew, with a different encoding. ANSI should work.
Potential warning: I don't know, how Matlab will react, when it tries to use that m-file and it is not utf8 encoded