What is the variable that contains the source file name?
You want the macro \jobname
. This isn't quite the filename; to quote from the TeX FAQ:
TeX retains what it considers the name of the job, only, in the primitive
\jobname
; this is the name of the file first handed to TeX, stripped of its directory name and of any extension (such as.tex
). If no file was passed (i.e., you're using TeX interactively),\jobname
has the valuetexput
(the name that's given to.log
files in this case).
So if you're processing foo.tex
, \jobname
will be foo
(which, of course, is probably what you want anyway).
You are looking for \jobname
.
EDIT: To add some value to my answer - pages 288-289 of the LaTeX2e sources contain the definition of \@starttoc
, the command that reads/writes ToC data from/to external files. This definition reveals the answer to your question.
\usepackage{currfile}
Filename: \currfilename