[Tugindia] RE: Counters
Suresh A.L
sureshal at sps.co.in
Tue Dec 30 05:18:24 CET 2003
Dear Sir,
Thank you very much, for your kind help.
It is working very well for me.
I have used the "\@car" command to check the
first letter of the word and given a condition loop.
with regards,
suresh
-----Original Message-----
From: Radhakrishnan CV [mailto:cvr at river-valley.org]
Sent: Saturday, December 27, 2003 10:05 AM
To: TUGIndia Mailing List
Subject: Re: [Tugindia] RE: Counters
>>>>> "Manoj" == Manoj Kummini <kummini at math.ukans.edu> writes:
Manoj> On Fri, Dec 26, 2003 at 18:42:25hrs +0530, Suresh A.L
Manoj> wrote:
Suresh> I am having the pages numbers indicated with alphanumeric
Suresh> values.
Suresh> Say Page number: A241
Suresh> I need to take only the numeric value "241" alone and
Suresh> asign it to a counter, (without including 'A') to
Suresh> manipulate the text. I have to split the text as 'A' and
Suresh> '241'.
Manoj> How have you defined \thepage? Its definition should give
Manoj> us a clue how to remove the letter from the string.
At times, it becomes a necessity to split the numbers which might be
defined to print with alphabets originally for some obvious reasons.
Surely, LaTeX provides many hooks to do the job. Here are two of them:
One way:
-------
\makeatletter
\newcounter{mycount} % we define counter to grab the number
\newtoks\mytoks % a token register for the alphabet
\def\grabNo#1{\@grabNo#1\@nil}
\def\@grabNo#1#2\@nil{\mytoks{#1}\setcounter{mycount}{#2}
\the\mytoks : \themycount
}
\makeatother
You might suitably use the token and counter registers for your
specific purpose or assign more meaningful names to it.
Another way:
-----------
\makeatletter
\newcounter{mycounter}
\def\grabNo#1{\edef\x{\@car#1\@nil}\relax
\expandafter\c at mycount\@cdr#1\@nil
\x : \themycount
}
\makeatother
LaTeX provides two commands namely, \@car and \@cdr which would grab
the first character and the rest of the characters respectively. This
is how LaTeX programmers prefer to do.
Please try the following examples with any one of the above macros
defined:
\grabNo{A234}
\grabNo{X 234}
\grabNo{B 4}
\grabNo{C234789}
Hope this would help to solve your problem.
Best regards
Radhakrishnan
_______________________________________________
Home: http://www.tug.org.in/
unsubscribe: http://tug.org/mailman/listinfo/tugindia
More information about the tugindia
mailing list