TeX (any engine) decides the job name it will use for the main output and log files in the following way
- If a file name has been specified in the command line, that file name is used as job name
- If started in interactive mode, the first file that is
\input at the ** prompt determines the job name
- However, if something needs to be written to the log file before the job name has been determined, or the primitive
\jobname is accessed to, the job name is set to texput
Note that the -jobname command line option overrides the above steps and makes TeX set the job name to what's specified with the option.
When the job name has been established, the meaning of \jobname becomes the string (with characters of category code 12) representing the job name as determined before (spaces keep category code 10, however, provided the implementation of the TeX engine is able to cope with spaces in the file name).
Afterwards, no “internal” access to \jobname is made and it's impossible to change the file name of the main output file (DVI or PDF) or log file.
So changing the meaning of \jobname is possible. Macros will use the current meaning of \jobname, which however should be either the primitive or a macro expanding to a string.
For instance, LaTeX does \@input{\jobname.aux} when processing \begin{document} and then, unless \if@filesw returns false, \immediate\openout\@mainaux\jobname.aux.
Macros such as \makeindex will set up an output stream based on \jobname and so on. The main output file name is not available to TeX other than with the primitive \jobname.
Therefore I see no real problem in redefining it. However it should be a string (category code 12 characters) for uniformity and to avoid problems if some macro does a check on \jobname. Hence
\edef\TeXjobname{\jobname} % keep a copy just for safety
\edef\jobname{\detokenize{WHATEVER}}
seems to be what you need, where WHATEVER stands for the string you'd like to use.
If e-TeX is not assumed, the second definition could be
\begingroup\escapechar=-1
\xdef\jobname{\expandafter\string\csname WHATEVER\endcsname}
\endgroup
As \jobname is an expandable primitive, there should be no difference in behavior, so long as the redefined \jobname is a macro expanding to a string.
Note that in pdfTeX and LuaTeX one can use \pdfprimitive\jobname for accessing the original meaning. It is \primitive\jobname in XeTeX. So saving the original meaning with the above code is really necessary with Knuth TeX.
\jobnamehere using catcode-11 chars, so at the very least I'd go with\edef\jobname{\detokenize{<new-name>}}(assuming e-TeX). – Joseph Wright Jun 26 '15 at 09:24\jobname, it doesn't look to\jobnameany more. Macros can use\jobname, of course, but they'll use whatever\jobnameexpands to. – egreg Jun 26 '15 at 09:35tex.jobnamein a callback: the core input/output names are unchanged. – Joseph Wright Jun 26 '15 at 09:38