# Get \jobname with normal catcodes

I would like to create a macro \myjob that has the same value as \jobname, but with letters having catcode 11 instead of 12. The goal is to be able to do something like

\documentclass{article}
\edef\myjob{\jobname}
\makeatletter
\newcommand{\mytest}[1]{\begingroup%
\def\@tempa{#1}%
%  \expandafter\def\expandafter\@tempa\expandafter{\detokenize{#1}}%
\meaning\@tempa\par%
\meaning\myjob\par%
\ifx\@tempa\myjob%
YES%
\else%
NO%
\fi%
\endgroup}
\begin{document}
\mytest{test}
\end{document}


where \ifx\@tempa\myjob is true (assuming the correct string is passed to \mytest). I would prefer not to detokenize the input string. Rather, I am looking for a different way of defining \myjob that "retokenizes" \jobname.

• 'Retokenizing' is risky as there might be a % or similar: see e-TeX's \scantokens Oct 19, 2016 at 14:44
• @JosephWright if a user is silly enough to put % or other nonsense in the \jobname then I am fine with it causing problems. Oct 19, 2016 at 14:48
• The detokenizing of \@tempa contents is much more safer. It can be done by a simple \@onelevel@sanitize\@tempa, which does not even require e-TeX. The tokenization method via \scantokens is not reliable at all. Depending on the current category code settings and the used characters, the latter method can break with a cryptic error message; also, the result is not even stable in general. Oct 19, 2016 at 21:00

Thanks to the hint from Joseph Wright, all I need is \scantokens.

\documentclass{article}

\edef\myjob{\expandafter\scantokens\expandafter{\jobname\noexpand}}
\makeatletter
\newcommand{\mytest}[1]{\begingroup%
\def\@tempa{#1}%
%  \expandafter\def\expandafter\@tempa\expandafter{\detokenize{#1}}%
\meaning\@tempa\par%
\meaning\myjob\par%
\ifx\@tempa\myjob%
YES%
\else%
NO%
\fi%
\endgroup}

\begin{document}

\mytest{test}

\end{document}