[texhax] A problem about \jobname

Rodolfo Medina romeomedina at libero.it
Sun Aug 15 11:03:51 CEST 2004


Hartmut Henkel wrote:

>maybe this hack keeps you going...
>
>\input eplain
>\def\fileword{file}
>\definexref{label}{myfile}{file}
>
>\def\xrefn#1{%
>\edef\tempa{\refn{#1}}\edef\tempa{\meaning\tempa}}
>
>\xrefn{label}
>\edef\tempb{\jobname}\edef\tempb{\meaning\tempb}
>
>See \ifx\tempa\tempb this file\else \ref{label}\fi.
>\bye

The problem seems to be solved now.

An analogous problem arises when you try to `treat \refn as a number',
i. e. to compare the result of \refn{label} with a number.
Example: if you say:

 \definexref{label}{1}{}

and, some lines below, you try to compare the result of \refn{label},
which is the number 1,
with a number, say 2, using \ifnum, you have troubles: if I say, e.g.,

 \ifnum2=\refn{label2}yes\else no\fi

you get the error message

 ! Missing number, treated as zero.

The reason why you get that `Missing number, treated as zero' message
is that on the very first run of TeX on your input file,
when no .aux file is present yet,
\refn cannot know what the definition of your label is,
therefore it defines your label to a string (`label', in typewriter face).
So when you try to compare this definition with a number,
TeX gets a back-quote where it expects a number, hence the error message.
Note that when you run TeX next time,
after definition for the label has been written out to the .aux file,
the label will get correct definition and will expand to a number,
and you won't get the error message.

The solution to this problem was suggested by Oleg Katsitadze,
in the tex-eplain eplain mailing list.
It boils down to checking whether \refn{label} expands to a number,
and doing the comparison only when the label does expand to a number.
Here is the hack:

  \def\gobbleminus#1{\ifx-#1\else#1\fi}
  \def\IsInteger#1{%
    TT\fi
    \ifcat_\ifnum9<1\gobbleminus#1 _\else A\fi
  }                %this definition looks deeply misterious to me!
                   %what on earth will ever mean that `TT\fi'??
                   %and `\ifnum9<1'?

, which must be used as

  \if\IsInteger{<subject of test>}%
    <deal with integer>%
  \else
    <deal with non-integer>%
  \fi

. \IsInteger macro has a flaw, as \IsInteger{ {<integer>}} will hold true,
disregarding the braces and/or leading spaces,
but for our purpose this is good enough.

Now comparing the result of \refn{label} with a number would look like the
following:

  \definexref{label}{1}{}

  \edef\temp{\refn{label}}
  \if\IsInteger{\temp}%
    \ifnum2=\refn{label}yes\else no\fi
  \else
    <no .aux file present yet>%
  \fi

Once again, this will not work
if it's possible for the label to get defined as {<integer>}.
In that case you'll need to write a better \IsInteger macro.

Thanks to all,
        	Rodolfo




More information about the texhax mailing list