Conversion Tools ⇒ Import Matlab Code to Latex File
Import Matlab Code to Latex File
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!
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
Re: Import Matlab Code to Latex File
Ignasi
Import Matlab Code to Latex File
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
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
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