I am trying to include a .tex file in my thesis. The file is some MATLAB code formatted to appear correctly in LaTeX. The compiler throws a warning that the code is too long for the page, but it doesn't automatically split it across multiple pages. The code I am using is:
\begin{figure}
\input{SUB_GRID_FLAG_ML.tex}
\caption{SUB GRID FLAG ML, \hl{See APPENDIX FOR FULL CODE}}
\label{SUB_GRID_FLAG_ML_CODE}
\end{figure}
Is there a way to do this inside my main LaTeX file rather than any included .tex files?
The content of SUB_GRID_FLAG_ML.tex
% This file was automatically created from the m-file
% "m2tex.m" written by USL.
% The fontencoding in this file is UTF-8.
%
% You will need to include the following two packages in
% your LaTeX-Main-File.
%
% \usepackage{color}
% \usepackage{fancyvrb}
%
% It is advised to use the following option for Inputenc
% \usepackage[utf8]{inputenc}
%
% definition of matlab colors:
\definecolor{mblue}{rgb}{0,0,1}
\definecolor{mgreen}{rgb}{0.13333,0.5451,0.13333}
\definecolor{mred}{rgb}{0.62745,0.12549,0.94118}
\definecolor{mgrey}{rgb}{0.5,0.5,0.5}
\definecolor{mdarkgrey}{rgb}{0.25,0.25,0.25}
\DefineShortVerb[fontfamily=courier,fontseries=m]{\$}
\DefineShortVerb[fontfamily=courier,fontseries=b]{\#}
\noindent
\hspace*{-1.6em}{\scriptsize 1}$ $\color{mgreen}$%Set up a flag to alternate the nodes updated on different time steps.$\color{black}$$\\
\hspace*{-1.6em}{\scriptsize 2}$ subGridFlag = 0;$\\
\hspace*{-1.6em}{\scriptsize 3}$ $\\
\hspace*{-1.6em}{\scriptsize 4}$ $\color{mgreen}$%Set up a flag to alternate the nodes updated on different rows.$\color{black}$$\\
\hspace*{-1.6em}{\scriptsize 5}$ rowFlag = 0;$\\
\hspace*{-1.6em}{\scriptsize 6}$ $\\
\hspace*{-1.6em}{\scriptsize 7}$ $\color{mblue}$for$\color{black}$ t = 1:Ns$\\
\hspace*{-1.6em}{\scriptsize 8}$ $\color{mgreen}$%% RED NODES$\color{black}$$\\
\hspace*{-1.6em}{\scriptsize 9}$ if(subGridFlag == 0)$\\
\hspace*{-2em}{\scriptsize 10}$ $\color{mblue}$for$\color{black}$ l = 2:Nx-2$\\
\hspace*{-2em}{\scriptsize 11}$ $\color{mblue}$for$\color{black}$ m = 2:Ny-2$\\
\hspace*{-2em}{\scriptsize 12}$ if(rowFlag == 0)$\\
\hspace*{-2em}{\scriptsize 13}$ p(l,m) = (0.5*(p1(l-1,m)+p1(l+1,m)+p1(l,m-1)...$\\
\hspace*{-2em}{\scriptsize 14}$ +p1(l,m+1))-p2(l,m));$\\
\hspace*{-2em}{\scriptsize 15}$ rowFlag = 1;$\\
\hspace*{-2em}{\scriptsize 16}$ $\color{mblue}$else$\color{black}$$\\
\hspace*{-2em}{\scriptsize 17}$ p(l+1,m) = (0.5*(p1(l,m)+p1(l+2,m)+p1(l+1,m-1)...$\\
\hspace*{-2em}{\scriptsize 18}$ +p1(l+1,m+1))-p2(l+1,m));$\\
\hspace*{-2em}{\scriptsize 19}$ rowFlag = 0;$\\
\hspace*{-2em}{\scriptsize 20}$ $\color{mblue}$end$\color{black}$$\\
\hspace*{-2em}{\scriptsize 21}$ $\color{mblue}$end$\color{black}$$\\
\hspace*{-2em}{\scriptsize 22}$ $\\
\hspace*{-2em}{\scriptsize 23}$ $\color{mblue}$end$\color{black}$$\\
\hspace*{-2em}{\scriptsize 24}$ subGridFlag = 1;$\\
\hspace*{-2em}{\scriptsize 25}$ rowFlag = 0;$\\
\hspace*{-2em}{\scriptsize 26}$ $\\
\hspace*{-2em}{\scriptsize 27}$ $\color{mgreen}$% Get Output Value$\color{black}$$\\
\hspace*{-2em}{\scriptsize 28}$ out(t) = p(Outx,Outy);$\\
\hspace*{-2em}{\scriptsize 29}$ $\color{mgreen}$% Update mesh history$\color{black}$$\\
\hspace*{-2em}{\scriptsize 30}$ p2 = p1;$\\
\hspace*{-2em}{\scriptsize 31}$ p1 = p;$\\
\hspace*{-2em}{\scriptsize 32}$ $\color{mgreen}$%% BLUE NODES$\color{black}$$\\
\hspace*{-2em}{\scriptsize 33}$ $\color{mblue}$else$\color{black}$$\\
\hspace*{-2em}{\scriptsize 34}$ $\color{mblue}$for$\color{black}$ l = 2:Nx-2$\\
\hspace*{-2em}{\scriptsize 35}$ $\color{mblue}$for$\color{black}$ m = 2:Ny-2$\\
\hspace*{-2em}{\scriptsize 36}$ if(rowFlag == 0)$\\
\hspace*{-2em}{\scriptsize 37}$ p(l,m+1) = (0.5*(p1(l-1,m+1)+p1(l+1,m+1)+p1(l,m)...$\\
\hspace*{-2em}{\scriptsize 38}$ +p1(l,m+2))-p2(l,m+1));$\\
\hspace*{-2em}{\scriptsize 39}$ rowFlag = 1;$\\
\hspace*{-2em}{\scriptsize 40}$ $\color{mblue}$else$\color{black}$$\\
\hspace*{-2em}{\scriptsize 41}$ p(l+1,m+1) = (0.5*(p1(l,m+1)+p1(l+2,m+1)+p1(l+1,m)...$\\
\hspace*{-2em}{\scriptsize 42}$ +p1(l+1,m+2))-p2(l+1,m+1));$\\
\hspace*{-2em}{\scriptsize 43}$ rowFlag = 0;$\\
\hspace*{-2em}{\scriptsize 44}$ $\color{mblue}$end$\color{black}$$\\
\hspace*{-2em}{\scriptsize 45}$ $\color{mblue}$end$\color{black}$$\\
\hspace*{-2em}{\scriptsize 46}$ $\color{mblue}$end$\color{black}$$\\
\hspace*{-2em}{\scriptsize 47}$ subGridFlag = 0;$\\
\hspace*{-2em}{\scriptsize 48}$ rowFlag = 0;$\\
\hspace*{-2em}{\scriptsize 49}$ $\color{mgreen}$% Get Output Value$\color{black}$$\\
\hspace*{-2em}{\scriptsize 50}$ out(t) = p(Outx,Outy);$\\
\hspace*{-2em}{\scriptsize 51}$ $\color{mgreen}$% Update mesh history$\color{black}$$\\
\hspace*{-2em}{\scriptsize 52}$ p2 = p1;$\\
\hspace*{-2em}{\scriptsize 53}$ p1 = p;$\\
\hspace*{-2em}{\scriptsize 54}$ $\color{mblue}$end$\color{black}$$\\
\hspace*{-2em}{\scriptsize 55}$ $\color{mblue}$end$\color{black}$$\\
\UndefineShortVerb{\$}
\UndefineShortVerb{\#}
Update: I just had my flushleft
in the wrong place and have regained the formatting. Unfortunately LaTeX now splits all code no matter what, even small 10 line chunks are split when called near the bottom of the page, rather than being at the top of the next page, losing much of the layout qualities of the float environment. Are there any other techniques I could try?
SUB_GRID_FLAG_ML.tex
.\begin{flushleft}
does not rectify this either.flushleft
in the wrong place and have regained the formatting. Unfortunately LaTeX now splits all code no matter what, even small 10 line chunks are split when called near the bottom of the page, rather than being at the top of the next page, losing much of the layout qualities of the float environment. Are there any other techniques I could try?