Re: recognizing prime (page) numbers in LaTeX



mpg wrote:

However, having the test work within only two expansion-steps looks very
impressive to me. I'm going to study your code carefully, but I'm not sure
I am able to understand it by myself. Would you mind explaining the main
ideas to me ?

I think you already explained the main-ideas yourself.
The phrase "two expansion-steps" is confusing.
(You need two \expandafter-chains in order to get the result.)

The point is that both \romannumeral and \csname... keep expanding
stuff "by themselves" until the number is complete / until a matching
\endcsname is found.

\csname..\endcsname does form a token.
\romannumeral0<space> delivers nothing/emptiness/no tokens at all -
I think the romans didn't use zero all too often in their calculations.

\romamnumeral0\csname...\endcsname does form and afterwards
expand a token.

(In order to stop \romannumeral you can use a space-token and
some \expandafter in the right places:

\romannumeral0%
\expandafter\expandafter
\expandafter \@sptoken
\csname...\endcsname
)

I used these things in order to launch the trial-division-loop within
\csname. Thus you get either
\csname <stuff that vanishes during expansion>@firstoftwo\endcsname
or
\csname <stuff that vanishes during expansion>@secondoftwo\endcsname

That means either the token \@firstoftwo or the token \@secondoftwo.

The preceeding \romannumeral will now expand that token ...

One could just put
\primetest{\arabic{page}}{\textbf}{}{\thepage} in place of \thepage in the
definition of the headers/footer, I think. Am I wrong ?

I think you are not wrong.
You can of course define your own page-style in terms of these
\ps@<pagestyle>-macros.
I hoped to circumvent \thispagestyle-problems by redefining
\thepage. But instead there is the \frontmatter, \mainmatter,
\backmatter issue.
I think your suggestion of going at a new page-style is the better
idea.

% It all takes place within an argument to \@firstofone, so maybe
% it also works inside alignments.

Hum, my question is maybe stupid, but what is the matter with alignments? I
mean, why would it possibly not work there?

The question is not stupid. But I am.
At first I had some iterator in mind which would look up
primes from a table (created by an external program) where values
are separated by "&". When going that approach, I needed &-masking
within alignments. This is not needed with trial-division but I was
still a bit confused yesterday. So I think you are right, and
\primetest can be shortened:

\newcommand\primetest[3]{\romannumeral0%
\expandafter\expandafter\expandafter\@sptoken\csname
\expandafter\@@primetest\expandafter{\expandafter2\expandafter}%
\expandafter{\number\expandafter\@primetest\number#1}{#2}{#3}{#1}%
}%

Ulrich
.



Relevant Pages

  • Re: Ride out complete: Being forced off the road by a car
    ... rider of a green Trophy a hand to pick his unhappy bike off of the ... it due to a rather bad experience on the way home which I will expand ... Mind you, I can't remember how I felt first time, but now I think of it as juvenile and don't worry. ...
    (uk.rec.motorcycles)
  • Re: alternate language
    ... language to expand your mind. ... Not with the standard library but AFAIK GHC comes with alot of things ... It may take you some time get the idea of pure functional programming ...
    (comp.lang.python)
  • Re: NBC considers expanding "The Office" to an hour
    ... Office Shooting Two Endings and May Expand Next Season ... they don't produce the show with your sensibilities in mind. ... up to stretch Office because their new fall comedy development slate ... Isn't that the hell from whence such rumors come? ...
    (rec.arts.tv)
  • Re: valve amp power output
    ... please expand on this statement of yours. ... if you don't mind. ... i.e. 0.1% The only drawback is that the heater supply requirement is ...
    (rec.audio.tubes)
  • Re: Fastcode MM Alignment
    ... This still incorpotates options ... Thanks, John, ... I only had alignments in multiples of 4 in mind. ...
    (borland.public.delphi.language.basm)