I use this macro to include Matlab code in my document:
\newrobustcmd{\inputmatlabcode}[1]{\lstinputlisting[basicstyle={\scriptsize \ttfamily}, caption=#1, language = matlab]{#1}}
It fails when I try to include code files with underscores in their names. I saw this question but since I'm referring to the file name in both the caption and the argument to listings, and only need to escape the underscore in the caption.
The underscore
package will break the rest of my document, I think, so I'm trying to avoid using that.