Should not the name \jobname expand to the name of the file without the extension?

I looked at

It says that show results in the meaning of a macro. Does my result imply that \jobname is not a macro?




> \jobname=\jobname.
l.4 \show\jobname
  • 1
    \showtokens\expandafter{\jobname} – egreg Jan 21 '16 at 22:43
  • 1
    or \message{HERE \jobname}, \wlog{HERE \jobname}, \typeout{HERE \jobname}... – user4686 Jan 21 '16 at 22:45

\jobname is not a macro (essentially it's not defined with \def) it is an expandable primitive that expands to the filename.

You can make a macro with the same expansion


> \xjobname=macro:

so \xjobname has the same expansion as \jobname but they have different \show behaviour and crucially they are not equal if tested with


but two macros with the same expansion are \ifx equal.

| improve this answer | |

Typically that's the way TeX primitives react. From the TeXbook (Chapter 3: Controlling TeX, p 10):

How can a person distinguish a TeX primitive from a control sequence that has been defined at a higher level? There are two ways: (1) The index to this manual lists all of the control sequences that are discussed, and each primitive is marked with an asterisk. (2) You can display the meaning of a control sequence while running TeX. If you type \show\cs where \cs is any control sequence, TeX will respond with its current meaning. For example, \show\input results in > \input=\input., because \input is primitive. On the other hand, \show\thinspace yields

> \thinspace=macro:
->\kern .16667em .

This means that \thinspace has been defined as an abbreviation for \kern .16667em. By typing \show\kern you can verify that \kern is primitive. The results of \show appear on your terminal and in the log file that you get after running TeX.

Commands that are declared in a robust way have a similarly bizarre output even though they are declared as a "macro". For example, \show\vspace prints

> \vspace=macro:
->\protect \vspace  .

in the terminal.

Some primitives can be expanded and there is also a way around peeking inside the definition of robust commands. For those primitives that cannot be expanded, you'd have to look into TeX The Program - the .web code or its documentation - in order to understand what it's doing.

Using David's example that input the following in the TeX terminal (no filename specified):


> \xjobname=macro:

528. Initially job_name = 0; it becomes nonzero as soon as the true name is known. We have job_name = 0 if and only if the log file has not been opened, except of course for a short time just after job name has become nonzero.

534. The open_log_file routine...

if job_name = 0 then job_name ← "texput";

| improve this answer | |
  • ...this is a minor supplement to David's answer. – Werner Jan 21 '16 at 23:30
  • Pretty hefty supplement I'd say. I almost gave the answer to you for writing a more detailed, time-consuming explanation. Nonetheless, David's also provides useful information. I'd be interested in understanding how to use \jobname in xstring's \IfEq{}{}{}{}, for example, where it needs to be expanded at a very specific time in order to be true, like why \IfEq{\jobname}{<nameoffile>}{TRUE}{FALSE} does not become TRUE. It seems \jobname can be expanded, but only sometimes (when the log is written-if I understand you correctly.) – Jonathan Komar Jan 22 '16 at 7:48
  • @macmadness86: As David says, \jobname has to be expanded. Try with \expandafter\IfEq\expandafter{\jobname}{<nameoffile>}{TRUE}{FALSE}... When the .log is opened... – Werner Jan 22 '16 at 7:51
  • That code is still not expanding it at the right time, but I verified that the strings are equal with \typeout{**** \jobname}. Filename=test.tex and my code was therefore \expandafter\IfEq\expandafter{\jobname}{test}{TRUE}{FALSE} Result: FALSE, typeout shows **** test. This is baffling me a bit, and because \IfEq\expandafter{\jobname}{test}{TRUE} results in TRUEFALSE – Jonathan Komar Jan 22 '16 at 8:12
  • 1
    @macmadness86 beware that \jobname produces catcode 12 tokens, I don't know how \IfEq of xstring acts. To produce on your own catcode 12 "letters" (for comparison), something like \expandafter\expandafter\expandafter\@gobble\expandafter\string\csname FOOBAR\endcsname (assuming \escapechar is standard) is a possibility. – user4686 Jan 22 '16 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.