Hello everyone,
Does anyone know an efficient way of importing matlab code in a latex document? I mean that this should be a report and the comments need to be visible (i cannot make them visible with listings) and moreover i cannot find any simple way to use m2tex.
Thank you in advance for your reply.
Regards
George
Text Formatting ⇒ Import of Matlab Code
NEW: TikZ book now 40% off at Amazon.com for a short time.

Import of Matlab Code
I always display my Matlab codes with the fancyvrb package:
Code: Select all
\usepackage{fancyvrb}
...
\begin{document}
\begin{Verbatim}
... Matlab code here ...
\end{Verbatim}
\end{document}
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
Follow howtoTeX on twitter
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Import of Matlab Code
I'd be interested in the difficulties with the listings package that you mentioned. You could show your efforts in form of a minimal example along with a sample of Matlab code.
Thorsten
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Import of Matlab Code
Hello again,
I think verbatim is fine!
Thank you very much!
Regards
George
I think verbatim is fine!
Thank you very much!
Regards
George
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Import of Matlab Code
Still can't comprehend the problems with the listings package.
Code: Select all
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{listings}
\lstset{
language=Matlab,
basicstyle=\ttfamily,
backgroundcolor=\color{lightgray!25},
breaklines=true,
columns=fullflexible,
frame=single,
commentstyle=\color{teal},
identifierstyle=\textbf,
keywordstyle=\color{magenta},
numbers=left,
numberstyle=\footnotesize\sffamily,
showstringspaces=false
}
\begin{document}
\begin{lstlisting}[gobble=4]
% simultaneousEquations.m
% (c) 2001 g.m.dick
%
% solution of Ax = b using matrix methods
%
clear
A = [-1 1 2 ; 3 -1 1 ; -1 3 4]; % coefficients
b = [2 6 4]'; % constants - COLUMN vector!!!
% if singular system - bail out now!
if det(A) == 0
error('determinate of A = 0 - no solution exists')
end
% the solution
x = A\b;
% print results
format compact
fprintf('\n\nThe coefficient matrix\n\n');
A
fprintf('\nThe constants\n\n');
b
fprintf('\nThe solution\n');
x
% =====================================================
% alternate solution
fprintf('\nThe alternate solution\n');
xAlt = inv(A)*b
\end{lstlisting}
\end{document}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10