I’m attempting to parse the jobname of my (Xe)LaTeX document to set a true/false flag for later use. I came across this solution which seemed promising and which I implemented (see the following MWE).
\documentclass{report}
\newif\ifFraktur
\makeatletter%
\newcommand{\filenameparse}[1]{\expandafter\filename@parse@#1\@nil}%
\def\filename@parse@#1_#2\@nil{%
\gdef\filenameflag{#2}%
}%
\makeatother
\filenameparse{\jobname}%
\if{f}\filenameflag{%
\Frakturtrue}%
\else{%
\Frakturfalse}%
\fi%
\begin{document}
\ifFraktur{We have an f document}%
\else{We have an a document.}%
\fi
\end{document}
The filename of this file is mwe-1-0_a.tex which corresponds to what I’m going to use for my actual file (version-m-n_f.tex, where m and n are placeholders for the version numbers and f is a placeholder for the flag which can bei either a or f).
Running this, I get the following error:
Runaway argument?
mwe-1-0_a\@nil
! Paragraph ended before \filename@parse@ was complete.
<to be read again>
\par
l.11
Ignoring the error (hitting enter) allowed the document to compile with no further errors.
Trying to get to the bottom of the issue, I decided to copy the already linked answer, but I modified it slightly to be the following:
\documentclass{article}
\makeatletter
\newcommand{\filenameparse}[1]{\expandafter\filename@parse@#1\@nil}
\def\filename@parse@#1_#2_#3\@nil{%
\gdef\fileA{#1}% first part
\gdef\fileB{#2}% middle part
\gdef\fileC{#3}% final part
}
\makeatother
\filenameparse{\jobname}
\begin{document}
\fileA \par
\fileB \par
\fileC
\end{document}
Surprisingly, this not only also generates a runaway argument, but also none of the three macros \fileA, \fileB or \fileC are defined. Whereupon I examined the mwe-1-0_f.tex (as above) and realised that it compiled, but the final \ifFraktur clause was evaluated as false.
There are probably multiple issues at work here, but I would be most interested in the cause for the runaway argument for the time being.


\if{f}although I may have guessed wrong. – David Carlisle Nov 18 '16 at 01:09