[tex-eplain] Treat \refn as a number?
geolsoft at mail.ru
geolsoft at mail.ru
Fri Aug 13 19:15:19 CEST 2004
On Thu, Aug 12, 2004 at 06:13:40PM +0200, Rodolfo Medina wrote:
> Hi, all.
>
> Using plain TeX, and eplain macros for cross references. If I say:
>
> \definexref{label}{1}{}
>
> and, some lines below, I try to compare the result of \refn{label}, which is
> the nuber 1,
> with a number, say 2, using \ifnum, I have troubles: if I say, e.g.,
>
> \ifnum2=\refn{label2}yes\else no\fi
>
> I get the error message
>
> ! Missing number, treated as zero.
>
> I'd need to compare the result of \refn{label} with a number.
> Is there a way to achieve this purpose?
>
> Thanks in advance,
> Rodolfo
>
> _______________________________________________
> tex-eplain at tug.org
> http://tug.org/mailman/listinfo/tex-eplain
>
I've had a similar problem, and solution below worked in my case.
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 boils down to checking whether \refn{label} expands to a number,
and doing the comparison only when the label does expand to a number. I used
the following for the checking:
\def\gobbleminus#1{\ifx-#1\else#1\fi}
\def\IsInteger#1{%
TT\fi
\ifcat_\ifnum9<1\gobbleminus#1 _\else A\fi
}
which must be used as
\if\IsInteger{<subject of test>}%
<deal with integer>%
\else
<deal with non-integer>%
\fi
(I adopted these macros from The UK TeX FAQ, http://www.tex.ac.uk/faq).
\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.
Hope this will be of use to you.
Best regards,
Oleg Katsitadze
More information about the tex-eplain
mailing list