ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* \numstr errors out in chapter star logic
@ 2010-06-28 15:59 Tom
  2010-06-28 20:30 ` Wolfgang Schuster
  0 siblings, 1 reply; 14+ messages in thread
From: Tom @ 2010-06-28 15:59 UTC (permalink / raw)
  To: ntg-context

\numstr seems to work fine in the body of text but errors out as if #1 was
not a number when it is used in chapter start loc. Here is an example:


%\numstr begins here

\unprotect

\def\numstring#1{\expandafter\@numstring\csname c@#1\endcsname}

\def\@numstring#1{\ns@numstr{#1}\ns@nineteens{null}{}}

\let\numstr\@numstring%

\def\ns@numoutofrange#1#2{\number#1#2}

\def\ns@numstr#1#2#3#4%
  {\ifnum\number#1<\plusone%
     #3%
   \else\ifnum\number#1<1000000000 %
     \expandafter\ns@numstring\expandafter{\number#1}#2%
   \else%
     \ns@numoutofrange{#1}{#4}%
   \fi\fi}

\def\ns@numstring#1#2{%
  \expandafter\ns@@numstring%
  \ifcase%
  \ifnum#1<10 1%
  \else\ifnum#1<100 2%
  \else\ifnum#1<\@m 3%
  \else\ifnum#1<\@M 4%
  \else\ifnum#1<100000 5%
  \else\ifnum#1<1000000 6%
  \else\ifnum#1<10000000 7%
  \else\ifnum#1<100000000 8%
  \else9%
  \fi\fi\fi\fi\fi\fi\fi\fi %
  \or00000000#1% case 1: Add 8 leading zeros
  \or0000000#1%  case 2: Add 7 leading zeros
  \or000000#1%   case 3: Add 6 leading zeros
  \or00000#1%    case 4: Add 5 leading zeros
  \or0000#1%     case 5: Add 4 leading zeros
  \or000#1%      case 6: Add 3 leading zeros
  \or00#1%       case 7: Add 2 leading zeros
  \or0#1%        case 8: Add 1 leading zero
  \or#1%         case 9: Add no leading zeros
  \or%
  \@nil#2%
  \fi}

\def\ns@@numstring#1#2#3#4#5#6#7\or#8\@nil#9%
  {\ifnum#1#2#3>\z@
   \ns@million#1#2#3%
   \ifnum#4#5#6>\z@\space\fi%
   \fi%
   \ifnum#4#5#6>\z@%
   \ns@hundred#4#5#6{#1#2#3}{#4#5}\ns@nineteen%
   \ifnum#4#5#6>\z@\space\fi%
   thousand%
   \ifnum#7>\z@\space\fi%
   \fi%
   \ns@hundred#7{#4#5#6}1#9}

\def\ns@million#1#2#3%
  {\ifnum#1#2#3=\plusone%
   \ns@hundred#1#2#301\ns@nineteene%
   \space%
   million%
   \else%
   \ns@hundred#1#2#301\ns@nineteens%
   \space%
   millions%
   \fi}

\def\ns@hundred#1#2#3#4#5#6%
  {\ifnum#1>\z@%
   \ifnum#4#1>\z@\ns@nineteen#1\space\fi%
   hundred%
   \ifnum#2#3>\z@\space and\space\fi%
   \fi%
   \ifnum#2#3<20 %
   \ifnum#5#2#3>\z@#6{#2#3}\fi%
   \else%
   \ns@ninety#2\ifnum#3>\z@-\ns@nineteen#3\fi%
   #60%
   \fi}

\def\ns@nineteen#1%
  {\ifcase#1\empty\or one\or two\or three\or four\or five\or six\or%
   seven\or eight\or nine\or ten\or eleven\or twelve\or thirteen\or%
   fourteen\or fifteen\or sixteen\or seventeen\or%
   eighteen\or nineteen\fi}

\def\ns@nineteens#1{\ns@nineteen{#1}}

\def\ns@nineteene#1{\ns@nineteen{#1}}


\def\ns@ninety#1%
  {\ifcase#1
   \or
   \or twenty%
   \or thirty%
   \or forty%
   \or fifty%
   \or sixty%
   \or seventy%
   \or eighty%
   \or ninety%
   \fi}

\protect


\def\MyChapterCommandA#1#2% #1 is number, #2 is text
      {\numstr{#1}}

\def\MyChapterCommandB#1#2% #1 is number, #2 is text
      {#1  #2}

\setuphead[chapter]
 [command=\MyChapterCommandA]  %change A to B to eliminate \substr call

\starttext

\chapter{First Chapter}

Some sample text. Chapter \numstr{1} numstr logic works correctly when
embedded in the text. Chapter title displays correctly when numstr not in
chapter start logic. Errors out when numstr is in chapter start logic as if
parameter is not a number.

\stoptext


Tom Benjey
717-258-9733 voice
717-243-0074 fax
Twitter: @TomBenjey






___________________________________________________________________________________
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  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

end of thread, other threads:[~2010-06-30 22:27 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-28 15:59 \numstr errors out in chapter star logic Tom
2010-06-28 20:30 ` Wolfgang Schuster
2010-06-28 21:03   ` Tom
2010-06-28 21:13     ` Wolfgang Schuster
2010-06-28 21:17       ` Aditya Mahajan
2010-06-28 21:41         ` Wolfgang Schuster
2010-06-29 12:16           ` Mojca Miklavec
2010-06-29 13:29             ` Aditya Mahajan
2010-06-28 21:33       ` Tom
2010-06-28 21:39         ` Wolfgang Schuster
2010-06-29  0:26           ` Tom
2010-06-29  7:08             ` Wolfgang Schuster
2010-06-29 11:12           ` Tom
2010-06-30 22:27           ` Tom

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).