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?


\lstinputlisting{/Users/User name/Documents/MATLAB/cosmology/exampleintegral.m} 

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).


  • 2
    Welcome to TeX.SE! Can you please show us a short compilable code you have tried so far?
    – Mensch
    Oct 28, 2017 at 15:43
  • 2
    Does your username contain any special characters or spaces? But as Kurt says it would be easier for us to help you if you could add a MWE (minimal, compilable code example).
    – TeXnician
    Oct 28, 2017 at 16:23
  • Edit your question instead of posting code in comments. There is an edit link right above the comments. After pasting the code into the question, select it and hit Ctrl + K (or click the button marked {}). Oct 28, 2017 at 18:24
  • Is the space in user name also in your real user name? Oct 28, 2017 at 18:45
  • In which folder is your tex file? Oct 28, 2017 at 18:46

1 Answer 1


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .