Re: recognizing prime (page) numbers in LaTeX
- From: Ulrich Diez <eu_angelion@xxxxxxxxxxxxxx>
- Date: Thu, 7 Feb 2008 10:03:52 +0100
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
.
- References:
- recognizing prime (page) numbers in LaTeX
- From: PrimeMogul
- Re: recognizing prime (page) numbers in LaTeX
- From: Ulrich Diez
- Re: recognizing prime (page) numbers in LaTeX
- From: mpg
- recognizing prime (page) numbers in LaTeX
- Prev by Date: Re: Documentation on TeX macros
- Next by Date: Re: 6 by 4 inch Record (Note) Cards
- Previous by thread: Re: recognizing prime (page) numbers in LaTeX
- Next by thread: Cluestick; graph of spectrum analysis for square wave pulses
- Index(es):
Relevant Pages
|