# percentage sign and space in image filename

In my application I (by means of a latex generation) create a table filled with figures. Now since those figures can have difficult names I need to make sure the generator makes each legal windows name a legal latex filepath.

I started with the percentage sign, as I know for sure that is in some of the files. (It's a left-over from a name that contained a "/" sign which is converted by another part to "%2F").

Now this broke quite a few things, as I obviously use % a lot for code readibility, the latex file right now:

\documentclass{article}
\usepackage[a4paper, portrait]{geometry}
\usepackage{graphicx}
\usepackage{tabu}

\catcode\%=12
\begin{document}
\begin{table}
\centering
\begin{tabu}{c}
\includegraphics{{"testing %"}}
\\%
\includegraphics{test2}
\end{tabu}
\end{table}

\end{document}


Now (as one can expect) the problem is that the percentage sign is no longer considered a "continu line here" sign, but instead a simple character, and is printed as such. I tried including the \catcode inside the table cell:

\begin{tabu}{c}
\catcode\%=12
\includegraphics{{"testing %"}}
\catcode\%=14
\\%
\includegraphics{test2}
\end{tabu}


But this breaks the latex compiler with "file ended scanning use of \tabu@collectbody". So how to make this work?

You can make a command that expands to a safe percent

\documentclass{article}
\usepackage[a4paper, portrait]{geometry}
\usepackage{graphicx}
\usepackage{tabu}

\catcode\%=12
\newcommand\pcnt{%}
\catcode\%=14

\begin{document}
\begin{table}
\centering
\begin{tabu}{c}
\includegraphics{"testing \pcnt"}\\% this is a comment
\includegraphics{test2}
\end{tabu}
\end{table}

\end{document}
`