i am new in all this Latex stuff, but i am trying to learn. Currently i am stuck in a problem: display a Matlab code.
This is my code in TexStudio:
\documentclass[12pt]{article}
\usepackage[margin = 2cm]{geometry}
\usepackage[brazil]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{setspace}
\onehalfspacing
\usepackage{lmodern}
\usepackage{listings}
\usepackage{xcolor}
\lstset{
basicstyle=\fontsize{10}{10}\selectfont\ttfamily,
inputencoding=utf8,
extendedchars=true,
frame=single,
breaklines=true,
postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},
}
\begin{document}
\begin{lstlisting}
x = 0:0.01:1e2; %Test Test Test Test Test %Test Test Test Test Test %Test Test Test Test Test %Test Test Test Test Test
y = sin(x);
for i = 1:1:100
fprintf('Hello World \n')
end
plot(x,y,'LineWidth',1.5)
title('Sin of x')
ylabel('f(x)')
xlabel('x')
grid on
\end{lstlisting}
\end{document}
In first, i would like to copy the script from Matlab to Latex's environment and then get the code indented in pdf. Currently i am getting it all in the same line.
I also would like to copy the code from the generated pdf back to matlab and be able to run the code, but it just appear messed up, with all the spacements out of place.
Does anyone know how can i do it ?
Ctrl+I
smart indenting in Matlab before copying your code into thelstlisting
environment. Maybe that helps your cause.