# How to test --jobname compilation option within latex file

Due to some commands in my preamble (\synctex=1,\makenomenclature,\settocdepth{subsection}) which are not fully compatible with --jobname procedure, I would like to add a test before these three line to detect if --jobname is specified at the compilation. Do you know a way to do such test ?

Or maybe you have another way to get my file compiled with and without --jobname option...

I should stress that this only works if \jobname is not equal to the file name.

The only method I know of is to hard-code you document name in the file. So for instance if your file is named test.tex you could do this testing:

\def\myjob{test}
\edef\myjob{\meaning\myjob}
\edef\tmpjob{\jobname}
\edef\tmpjob{\meaning\tmpjob}
\ifx\myjob\tmpjob
\message{My own job: \jobname}
\else
\message{Other job: \jobname}
\fi


before the \documentclass. In this way you know whether you use your regular jobname or have supplied it. I do not think you can do it automatically, although I might be wrong.

The reason for doing the above \edefs is that \jobname is a character where \myjob is a letter. Therefore you need to transfer them to the same macro, done by the \edef and \meaning. If in doubt you can do \message{\meaning} in each step to see what is done.

The v0.6 of the currfile can now detect the real main file using the -recorder compiler argument. You can test if this name is identical to the jobname using \ifcurrfile... and so determine if the jobname was changed:

% Compile with: (pdf|xe|lua|)latex -recorder filename
% Needs two runs with MiKTeX, one with TeX Live
\documentclass{article}

\usepackage[realmainfile]{currfile}[2012/05/06]

\ifcurrfile{\themainfile}{\jobname.tex}{%
%or: \ifcurrfilebase{\jobname}{%
\message{No \string\jobname\space used!}%
}{%
\message{\string\jobname\space was used!}%
}

\begin{document}
...
\end{document}