LaTeX Jobname – Macro to Retrieve Real Name of Source File with Pdflatex -jobname

file-lookupjobname

This question led to a new feature in a package:
As of version 0.6 currfile supports the requested feature via a new package option and the -recorder compiler switch. For details, see Martin's answer below.

From the documentation I assumed that Martin Scharrer's currfile package would do this. However, while it deals well with tracking the actual file name over \inputs and \includes, the name of the main .tex file is still set to \jobname:

\documentclass{article}
\usepackage{currfile}

\begin{document}
  I was compiled as job \texttt{\jobname} from the file \texttt{\currfilename}.
\end{document}

If saved as test.tex and compiled with pdflatex -jobname bla test.tex the output is:

enter image description here

Even compiling with pdflatex -jobname bla "\input{test.tex}" does not change the output.

Best Answer

With the call

pdflatex -jobname bla "\RequirePackage{currfile}\input{test}"

the macro \currfilename prints test.tex

One has to change the meaning of \input (actually of \@iinput) before executing it.