I have been trying to pass a file name that contains underscores to a couple of nested commands. Since escaping each and every _ isn't really an option, I thought a group \catcode_=12 (had to remove the back tick there because I couldn't escape it in this question text) adjustment would help but interestingly and in a completely unexpected result, the compiler error results are telling me the file doesn't exist. Why? Because the filename it's looking for has no underscores anymore... I didn't think this is what it did. Because I have used this approach previously to escape # signs in file names being passed as arguments.
I have tried to reduce the number of nested commands to produce a simpler MWE. I will update if this ends up being too oversimplified and just coincidentally causing the same error messages.
\documentclass{article}
\usepackage{todonotes}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{expl3}
\usepackage{xparse}
\usepackage{xpatch}
\usepackage{caption}
\usepackage[export]{adjustbox}
\usepackage[format=hang,singlelinecheck=0,font={sf,small},labelfont=bf]{subfig}
%http://tex.stackexchange.com/questions/75014/is-it-possible-to-make-a-reference-to-a-subfigure-to-appear-figure-2a-with-cle
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple,listofformat=subsimple}
\renewcommand\thesubfigure{\Alph{subfigure}}
\newcommand{\cmd}{\begingroup
\catcode`_=12 \cmdint}
\newcommand{\cmdint}[1]{%
\texttt{\scantokens{#1\noexpand}}%
\endgroup}
\DeclareDocumentCommand{\MyIncludeGraphics}{ O{} +m }
{
\IfFileExists{#2}
{
\includegraphics[#1]{#2}%
}
{
\missingfigure[figwidth=7.0cm]{Missing #2}%
}
}
\begin{document}
\begingroup
% \catcode`_=12 % can't use this because it essentially changes the file name so the file can't be found ... I didn't think this is what it did..
\begin{figure}[ht!]
\subfloat{\label{fig:A}\MyIncludeGraphics[width=0.5\textwidth]{First_File_Does_Not_Exist.png}}%
\subfloat{\label{fig:B}\MyIncludeGraphics{Second_File_Does_Not_Exist.jpg}}%
\caption[CAPTION UNDER DEVELOPMENT Grin lens design and performance]{%
FIGURE NOT FINAL - CAPTION UNDER DEVELOPMENT \\
}
\end{figure}
\endgroup
\end{document}

\detokenizewhat you are looking for? – Manuel Apr 27 '16 at 21:56I did try that, no effect. Happy to vote for a working implementation of that. Perhaps I just put it in the wrong spot. – EngBIRD Apr 27 '16 at 22:15
\pathcomnand from the url package, perhaps with an expandafter in front – daleif Apr 27 '16 at 23:33