This question led to a new feature in a package:
As of version 0.6currfile
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 \input
s and \include
s, 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:
Even compiling with pdflatex -jobname bla "\input{test.tex}"
does not change the output.
Best Answer
With the call
the macro
\currfilename
printstest.tex
One has to change the meaning of
\input
(actually of\@iinput
) before executing it.