ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Converting counters?
@ 2008-04-01  7:18 Zhichu Chen
  2008-04-01  7:41 ` Wolfgang Schuster
  0 siblings, 1 reply; 7+ messages in thread
From: Zhichu Chen @ 2008-04-01  7:18 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2124 bytes --]

Hi,

I'm trying to convert the counter to Chinese character one on one, like
0->a, 1->b, etc., so 10 will be "ba" (I use a, b, c, . . . to denote the
Chinese
glyphs which makes more sense for you). I used some codes like:
======================================================
\def\ChineseZero {o}
\def\ChineseOne  {a}
\def\ChineseTwo  {b}
\def\ChineseThree{c}
\def\ChineseFour {d}
\def\ChineseFive {e}
\def\ChineseSix  {f}
\def\ChineseSeven{g}
\def\ChineseEight{h}
\def\ChineseNine {i}

\unexpanded\def\zhnumber
  {\bgroup
   \catcode`\0=\active \uccode`\~=`\0 \uppercase{\let~\ChineseZero}%
   \catcode`\1=\active \uccode`\~=`\1 \uppercase{\let~\ChineseOne}%
   \catcode`\2=\active \uccode`\~=`\2 \uppercase{\let~\ChineseTwo}%
   \catcode`\3=\active \uccode`\~=`\3 \uppercase{\let~\ChineseThree}%
   \catcode`\4=\active \uccode`\~=`\4 \uppercase{\let~\ChineseFour}%
   \catcode`\5=\active \uccode`\~=`\5 \uppercase{\let~\ChineseFive}%
   \catcode`\6=\active \uccode`\~=`\6 \uppercase{\let~\ChineseSix}%
   \catcode`\7=\active \uccode`\~=`\7 \uppercase{\let~\ChineseSeven}%
   \catcode`\8=\active \uccode`\~=`\8 \uppercase{\let~\ChineseEight}%
   \catcode`\9=\active \uccode`\~=`\9 \uppercase{\let~\ChineseNine}%
   \loggingall
   \dozhnumber }

\def\stripunwantedspaces{}

\def\dozhnumber#1%
  {\expandafter\scantokens\expandafter
        {\detokenize{#1\stripunwantedspaces}}\egroup}
======================================================
It works fine with \zhnumber{15}, it gives "ae" which is exactly what I
want.
But it won't work in the following situation:
++++++++++++++++++++++++++
\newcount\tcpageno
\advance\tcpageno15
\zhnumber{\number\tcpageno}
++++++++++++++++++++++++++
I know it's not weird, I just don't know how to expand the counter to
number.


Thank you in advance.

-- 
Best Regards
Chen
----------------------------------------------------------------

Zhi-chu Chen | Shanghai Synchrotron Radiation Facility
No. 2019 | Jialuo Rd. | Jiading | Shanghai | P.R. China
tel: 086 21 5955 3405 | zhichu.chen.googlepages.com
| www.sinap.ac.cn
----------------------------------------------------------------

[-- Attachment #1.2: Type: text/html, Size: 2634 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Converting counters?
  2008-04-01  7:18 Converting counters? Zhichu Chen
@ 2008-04-01  7:41 ` Wolfgang Schuster
  2008-04-01  7:56   ` Zhichu Chen
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfgang Schuster @ 2008-04-01  7:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi Chen,

You could use \chinesenumber from font-chi.tex

Wolfgang

On Tue, Apr 1, 2008 at 9:18 AM, Zhichu Chen <zhichu.chen@gmail.com> wrote:
> Hi,
>
> I'm trying to convert the counter to Chinese character one on one, like
> 0->a, 1->b, etc., so 10 will be "ba" (I use a, b, c, . . . to denote the
> Chinese
> glyphs which makes more sense for you). I used some codes like:
> ======================================================
> \def\ChineseZero {o}
> \def\ChineseOne  {a}
> \def\ChineseTwo  {b}
> \def\ChineseThree{c}
> \def\ChineseFour {d}
> \def\ChineseFive {e}
> \def\ChineseSix  {f}
> \def\ChineseSeven{g}
> \def\ChineseEight{h}
> \def\ChineseNine {i}
>
> \unexpanded\def\zhnumber
>   {\bgroup
>    \catcode`\0=\active \uccode`\~=`\0 \uppercase{\let~\ChineseZero}%
>    \catcode`\1=\active \uccode`\~=`\1 \uppercase{\let~\ChineseOne}%
>    \catcode`\2=\active \uccode`\~=`\2 \uppercase{\let~\ChineseTwo}%
>    \catcode`\3=\active \uccode`\~=`\3 \uppercase{\let~\ChineseThree}%
>    \catcode`\4=\active \uccode`\~=`\4 \uppercase{\let~\ChineseFour}%
>    \catcode`\5=\active \uccode`\~=`\5 \uppercase{\let~\ChineseFive}%
>    \catcode`\6=\active \uccode`\~=`\6 \uppercase{\let~\ChineseSix}%
>    \catcode`\7=\active \uccode`\~=`\7 \uppercase{\let~\ChineseSeven}%
>    \catcode`\8=\active \uccode`\~=`\8 \uppercase{\let~\ChineseEight}%
>    \catcode`\9=\active \uccode`\~=`\9 \uppercase{\let~\ChineseNine}%
>    \loggingall
>    \dozhnumber }
>
> \def\stripunwantedspaces{}
>
> \def\dozhnumber#1%
>   {\expandafter\scantokens\expandafter
>         {\detokenize{#1\stripunwantedspaces}}\egroup}
> ======================================================
> It works fine with \zhnumber{15}, it gives "ae" which is exactly what I
> want.
> But it won't work in the following situation:
> ++++++++++++++++++++++++++
> \newcount\tcpageno
> \advance\tcpageno15
> \zhnumber{\number\tcpageno}
> ++++++++++++++++++++++++++
> I know it's not weird, I just don't know how to expand the counter to
> number.
>
>
> Thank you in advance.
>
> --
> Best Regards
> Chen
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Converting counters?
  2008-04-01  7:41 ` Wolfgang Schuster
@ 2008-04-01  7:56   ` Zhichu Chen
  2008-04-01  8:49     ` Wolfgang Schuster
  0 siblings, 1 reply; 7+ messages in thread
From: Zhichu Chen @ 2008-04-01  7:56 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 3515 bytes --]

Yes, only I don't need that complex. I mean \chinesenumber{123} will give
"one hundred and twenty-three" but all I want is "one two three." Besides,
I don't like to copy such long codes since I really don't want to load
font-chi.tex
which gives weird spacing problems while typesetting Chinese along with
English. Anyway, I'd love to learn something rather than to use something.

Thanks.

On Tue, Apr 1, 2008 at 3:41 PM, Wolfgang Schuster <
schuster.wolfgang@googlemail.com> wrote:

> Hi Chen,
>
> You could use \chinesenumber from font-chi.tex
>
> Wolfgang
>
> On Tue, Apr 1, 2008 at 9:18 AM, Zhichu Chen <zhichu.chen@gmail.com> wrote:
> > Hi,
> >
> > I'm trying to convert the counter to Chinese character one on one, like
> > 0->a, 1->b, etc., so 10 will be "ba" (I use a, b, c, . . . to denote the
> > Chinese
> > glyphs which makes more sense for you). I used some codes like:
> > ======================================================
> > \def\ChineseZero {o}
> > \def\ChineseOne  {a}
> > \def\ChineseTwo  {b}
> > \def\ChineseThree{c}
> > \def\ChineseFour {d}
> > \def\ChineseFive {e}
> > \def\ChineseSix  {f}
> > \def\ChineseSeven{g}
> > \def\ChineseEight{h}
> > \def\ChineseNine {i}
> >
> > \unexpanded\def\zhnumber
> >   {\bgroup
> >    \catcode`\0=\active \uccode`\~=`\0 \uppercase{\let~\ChineseZero}%
> >    \catcode`\1=\active \uccode`\~=`\1 \uppercase{\let~\ChineseOne}%
> >    \catcode`\2=\active \uccode`\~=`\2 \uppercase{\let~\ChineseTwo}%
> >    \catcode`\3=\active \uccode`\~=`\3 \uppercase{\let~\ChineseThree}%
> >    \catcode`\4=\active \uccode`\~=`\4 \uppercase{\let~\ChineseFour}%
> >    \catcode`\5=\active \uccode`\~=`\5 \uppercase{\let~\ChineseFive}%
> >    \catcode`\6=\active \uccode`\~=`\6 \uppercase{\let~\ChineseSix}%
> >    \catcode`\7=\active \uccode`\~=`\7 \uppercase{\let~\ChineseSeven}%
> >    \catcode`\8=\active \uccode`\~=`\8 \uppercase{\let~\ChineseEight}%
> >    \catcode`\9=\active \uccode`\~=`\9 \uppercase{\let~\ChineseNine}%
> >    \loggingall
> >    \dozhnumber }
> >
> > \def\stripunwantedspaces{}
> >
> > \def\dozhnumber#1%
> >   {\expandafter\scantokens\expandafter
> >         {\detokenize{#1\stripunwantedspaces}}\egroup}
> > ======================================================
> > It works fine with \zhnumber{15}, it gives "ae" which is exactly what I
> > want.
> > But it won't work in the following situation:
> > ++++++++++++++++++++++++++
> > \newcount\tcpageno
> > \advance\tcpageno15
> > \zhnumber{\number\tcpageno}
> > ++++++++++++++++++++++++++
> > I know it's not weird, I just don't know how to expand the counter to
> > number.
> >
> >
> > Thank you in advance.
> >
> > --
> > Best Regards
> > Chen
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : https://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________
>



-- 
Best Regards
Chen
----------------------------------------------------------------

Zhi-chu Chen | Shanghai Synchrotron Radiation Facility
No. 2019 | Jialuo Rd. | Jiading | Shanghai | P.R. China
tel: 086 21 5955 3405 | zhichu.chen.googlepages.com
| www.sinap.ac.cn
----------------------------------------------------------------

[-- Attachment #1.2: Type: text/html, Size: 4935 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Converting counters?
  2008-04-01  7:56   ` Zhichu Chen
@ 2008-04-01  8:49     ` Wolfgang Schuster
  2008-04-01  9:04       ` Wolfgang Schuster
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfgang Schuster @ 2008-04-01  8:49 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Tue, Apr 1, 2008 at 9:56 AM, Zhichu Chen <zhichu.chen@gmail.com> wrote:
> Yes, only I don't need that complex. I mean \chinesenumber{123} will give
> "one hundred and twenty-three" but all I want is "one two three." Besides,
> I don't like to copy such long codes since I really don't want to load
> font-chi.tex
> which gives weird spacing problems while typesetting Chinese along with
> English. Anyway, I'd love to learn something rather than to use something.
>
> Thanks.

\def\dododozhnumber#1%
  {\ifcase#1
   a\or
   b\or
   c\or
   d\or
   e\or
   f\or
   g\or
   i\or
   h\or
   i\fi
   \dozhnumber}

\def\zhnumber#1%
  {\dozhnumber#1\endzhnumber}

\def\endzhnumber{\endzhnumber}

\def\dozhnumber
  {\futurelet\next\dodozhnumber}

\def\dodozhnumber
  {\ifx\next\endzhnumber
     \expandafter\gobbleoneargument
   \else
     \expandafter\dododozhnumber
   \fi}

\starttext
\zhnumber{123}
\stoptext

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Converting counters?
  2008-04-01  8:49     ` Wolfgang Schuster
@ 2008-04-01  9:04       ` Wolfgang Schuster
  2008-04-01 11:37         ` Zhichu Chen
  2008-04-02  6:18         ` Wolfgang Schuster
  0 siblings, 2 replies; 7+ messages in thread
From: Wolfgang Schuster @ 2008-04-01  9:04 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Tue, Apr 1, 2008 at 10:49 AM, Wolfgang Schuster
<schuster.wolfgang@googlemail.com> wrote:
> On Tue, Apr 1, 2008 at 9:56 AM, Zhichu Chen <zhichu.chen@gmail.com> wrote:
> > Yes, only I don't need that complex. I mean \chinesenumber{123} will give
> > "one hundred and twenty-three" but all I want is "one two three." Besides,
> > I don't like to copy such long codes since I really don't want to load
> > font-chi.tex
> > which gives weird spacing problems while typesetting Chinese along with
> > English. Anyway, I'd love to learn something rather than to use something.
> >
> > Thanks.

A slightly modified version.

You could now also use counter values.

\def\dododozhnumber#1%
 {\ifcase#1
  a\or
  b\or
  c\or
  d\or
  e\or
  f\or
  g\or
  i\or
  h\or
  i\fi}

\def\zhnumber#1%
 {\expandafter\dozhnumber#1\endzhnumber}

\def\endzhnumber{\endzhnumber}

\def\dozhnumber
 {\futurelet\next\dodozhnumber}

\def\dodozhnumber
 {\ifx\next\endzhnumber
    \let\next\gobbleoneargument
  \else
    \def\next##1{\dododozhnumber{##1}\dozhnumber}%
  \fi\next}

\starttext
\zhnumber{01234}

\zhnumber{\number\pageno}
\stoptext

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Converting counters?
  2008-04-01  9:04       ` Wolfgang Schuster
@ 2008-04-01 11:37         ` Zhichu Chen
  2008-04-02  6:18         ` Wolfgang Schuster
  1 sibling, 0 replies; 7+ messages in thread
From: Zhichu Chen @ 2008-04-01 11:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2193 bytes --]

Thanks Wolfgang, it's perfect.

On Tue, Apr 1, 2008 at 5:04 PM, Wolfgang Schuster <
schuster.wolfgang@googlemail.com> wrote:

> On Tue, Apr 1, 2008 at 10:49 AM, Wolfgang Schuster
> <schuster.wolfgang@googlemail.com> wrote:
> > On Tue, Apr 1, 2008 at 9:56 AM, Zhichu Chen <zhichu.chen@gmail.com>
> wrote:
> > > Yes, only I don't need that complex. I mean \chinesenumber{123} will
> give
> > > "one hundred and twenty-three" but all I want is "one two three."
> Besides,
> > > I don't like to copy such long codes since I really don't want to load
> > > font-chi.tex
> > > which gives weird spacing problems while typesetting Chinese along
> with
> > > English. Anyway, I'd love to learn something rather than to use
> something.
> > >
> > > Thanks.
>
> A slightly modified version.
>
> You could now also use counter values.
>
> \def\dododozhnumber#1%
>  {\ifcase#1
>  a\or
>  b\or
>  c\or
>  d\or
>  e\or
>  f\or
>  g\or
>  i\or
>  h\or
>  i\fi}
>
> \def\zhnumber#1%
>  {\expandafter\dozhnumber#1\endzhnumber}
>
> \def\endzhnumber{\endzhnumber}
>
> \def\dozhnumber
>  {\futurelet\next\dodozhnumber}
>
> \def\dodozhnumber
>  {\ifx\next\endzhnumber
>     \let\next\gobbleoneargument
>  \else
>    \def\next##1{\dododozhnumber{##1}\dozhnumber}%
>  \fi\next}
>
> \starttext
> \zhnumber{01234}
>
> \zhnumber{\number\pageno}
> \stoptext
>
> Wolfgang
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : https://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________
>



-- 
Best Regards
Chen
----------------------------------------------------------------

Zhi-chu Chen | Shanghai Synchrotron Radiation Facility
No. 2019 | Jialuo Rd. | Jiading | Shanghai | P.R. China
tel: 086 21 5955 3405 | zhichu.chen.googlepages.com
| www.sinap.ac.cn
----------------------------------------------------------------

[-- Attachment #1.2: Type: text/html, Size: 3524 bytes --]

[-- Attachment #2: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Converting counters?
  2008-04-01  9:04       ` Wolfgang Schuster
  2008-04-01 11:37         ` Zhichu Chen
@ 2008-04-02  6:18         ` Wolfgang Schuster
  1 sibling, 0 replies; 7+ messages in thread
From: Wolfgang Schuster @ 2008-04-02  6:18 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Tue, Apr 1, 2008 at 11:04 AM, Wolfgang Schuster
<schuster.wolfgang@googlemail.com> wrote:
> On Tue, Apr 1, 2008 at 10:49 AM, Wolfgang Schuster
> <schuster.wolfgang@googlemail.com> wrote:
> > On Tue, Apr 1, 2008 at 9:56 AM, Zhichu Chen <zhichu.chen@gmail.com> wrote:
> > > Yes, only I don't need that complex. I mean \chinesenumber{123} will give
> > > "one hundred and twenty-three" but all I want is "one two three." Besides,
> > > I don't like to copy such long codes since I really don't want to load
> > > font-chi.tex
> > > which gives weird spacing problems while typesetting Chinese along with
> > > English. Anyway, I'd love to learn something rather than to use something.
> > >
> > > Thanks.

Another solution using \afterassignment.

The number is now removed from the input but you have to use
a if test, number tests did not work.

\def\zhnumber#1%
  {\expandafter\dozhnumber#1\endzhnumber}

\def\endzhnumber{\endzhnumber}

\def\dozhnumber
  {\afterassignment\dodozhnumber\let\next= }

\def\dodozhnumber
  {\ifx\next\endzhnumber\let\next\relax
   \else
     \if\next 0a\else
       \if\next 1b\else
         \if\next 2c\else
           \if\next 3d\else
             \if\next 4e\else
               \if\next 5f\else
                 \if\next 6g\else
                   \if\next 7h\else
                     \if\next 8i\else
                       \if\next 9j\relax
     \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
     \let\next\dozhnumber
   \fi\next}

\starttext

\zhnumber{01234}

\zhnumber{\number\pageno}

\stoptext

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-04-02  6:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-01  7:18 Converting counters? Zhichu Chen
2008-04-01  7:41 ` Wolfgang Schuster
2008-04-01  7:56   ` Zhichu Chen
2008-04-01  8:49     ` Wolfgang Schuster
2008-04-01  9:04       ` Wolfgang Schuster
2008-04-01 11:37         ` Zhichu Chen
2008-04-02  6:18         ` Wolfgang Schuster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).