[Tex/LaTex] Package Listings Error: File (.m) not found

listings

So I'm trying to add a Matlab script to my latex document using the mcode and listings packages. The way I use it is \lstinputlisting{/Users/Username/Documents/MATLAB/exampleintegral.m}
I then get the error "Package Listings Error: File /Users/Username/Documents/MATLAB/exampleintegral(.m) not found"
If I have the .m file in the same folder as the latex file it will retrieve it, but some of the lines will continue over the edge of the page even if I use \lstinputlisting[breaklines=true]{exampleintegral.m}.
The weird thing is that I used this method when writing my thesis and it worked like a charm. Now, all of a sudden, the program is unable to find any files.

Has anyone encountered this before? Any solutions?

MWE:

\documentclass[12pt]{article} 
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
\usepackage{listings} 
\begin{document} 
\lstinputlisting{/Users/User name/Documents/MATLAB/cosmology/exampleintegral.m} 
\end{document} 

What I use to get around this (by having the code in the same folder as the tex file), although the code will look nasty (some lines break some don't).

\lstinputlisting[breaklines=true]{exampleintegral.m}

Best Answer

The problem is the space in the absolute file path. There are several ways to avoid this problem, e.g.:

  • using a relative file path instead of a total one, i.e. using \lstinputlisting{./MATLAB/cosmology/exampleintegral.m} instead of \lstinputlisting{/Users/User name/Documents/MATLAB/cosmology/exampleintegral.m}

  • using the grffile package

Related Question