From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/4114 Path: main.gmane.org!not-for-mail From: Taco Hoekwater Newsgroups: gmane.comp.tex.context Subject: Number conversions (Was Re: My ideas for tooltips) Date: Sun, 18 Feb 2001 00:28:44 +0100 Sender: owner-ntg-context@let.uu.nl Message-ID: <3A8F092C.DA3381D0@quicknet.nl> References: <00a301c096d2$0f28bb00$a3ccfea9@nuovo> <007b01c09806$6306f540$a3ccfea9@nuovo> <3A8D1B4E.C1394A13@elvenkind.com> <01021622452908.00577@bilbo> <3A8EB3FC.A882C793@quicknet.nl> <000501c0992c$f7eeb180$a3ccfea9@nuovo> NNTP-Posting-Host: coloc-standby.netfonds.no Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2708132DD8DB6616593C5ED0" X-Trace: main.gmane.org 1035394800 22970 80.91.224.250 (23 Oct 2002 17:40:00 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 23 Oct 2002 17:40:00 +0000 (UTC) Original-To: ntg-context@ntg.nl Xref: main.gmane.org gmane.comp.tex.context:4114 X-Report-Spam: http://spam.gmane.org/gmane.comp.tex.context:4114 This is a multi-part message in MIME format. --------------2708132DD8DB6616593C5ED0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Giuseppe Bilotta wrote: > > Taco wrote: > > > > It is *possible* btw. that the example tooltip worked ok just because > > of that. I don't think I have the math core patch installed on this > > machine. > > > > Nope. I'm using pdfeTeX in extended mode too, same version as you. Rats. Maybe I *do* have the math patch installed then? Anyway, my context deviates from the distribution regularly ;) ... and now for something completely different ... I needed some extensions to the number conversions provided by context (like character conversion for numbers > 26, which is broken :() nd the attached file is what I came up with. It's rough, but maybe someone will be interested enough to make requests? Here's a usage example/demo (\maxcount == TeX's max integer divided by 26): %&cont-en \input radix \switchtobodyfont[9pt] \def\c#1{\hbox to 4.5em{#1\hss}} \edef\maxcount{41297762} \starttext \noindent \c{dec} \c{dchar} \c{char} \c{Char} \c{oct} \c{hex} \c{Hex} \c{bin}\par \medskip \hrule \medskip \advance\baselineskip -1pt \dorecurse{53}{% \noindent \c{\recurselevel} \c{\dcharacters{\recurselevel}} \c{\characters{\recurselevel}} \c{\Characters{\recurselevel}} \c{\octal{\recurselevel}} \c{\hexal{\recurselevel}} \c{\Hexal{\recurselevel}} \c{\binary{\recurselevel}}\par } \noindent \c{\maxcount} \c{} \c{\characters{\maxcount}} \c{\Characters{\maxcount}} \c{\octal{\maxcount}} \c{\hexal{\maxcount}} \c{\Hexal{\maxcount}} \c{\binary{\maxcount}}\par \stoptext Greetings, Taco --------------2708132DD8DB6616593C5ED0 Content-Type: application/x-tex; name="radix.tex" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="radix.tex" \unprotect \newcount\argument \newcount\radix \newcount\scratcha \newcount\scratchb % \scratcha => radix multiplier % \scratchb => scratch for division with rest \def\converttoradix#1#2{% % \message{<- #2 to #1: }% \def\radixresult##1{}% \radix = #1 \scratcha = 1 \argument = #2 \ifnum \argument > 0 \doloop{% \multiply \scratcha \radix \ifnum \scratcha > \argument \exitloop \fi }% \divide \scratcha \radix \ifnum \scratcha = 1 \edef\radixresult{\the\argument}% \else \doloop{% need to do division with remainder % \message{((\the\argument)(\the\scratcha))}% \scratchb = \argument \divide \scratchb \scratcha \edef\radixresult{\radixresult,\the\scratchb}% \multiply \scratchb \scratcha \advance \argument - \scratchb \divide \scratcha \radix \ifnum \scratcha = 1 \edef\radixresult{\radixresult,\the\argument}% \exitloop\fi }% \fi \else \edef\radixresult{0}% \fi % \message{\radixresult -> }% } \newcount\result \def\convertfromradix#1#2{% \radix = #1 \expandafter\let\expandafter\chartonum\csname radtonum#1\endcsname \buildcommalist #2\end\end \edef\radixresult{\the\result}% } \def\convertradix#1#2#3{% \convertfromradix{#1}{#3}% \converttoradix{#2}{\radixresult}% } \def\buildcommalist#1#2% {\ifx#2\end \advance \result \chartonum{#1}% \let\next\gobbletwoarguments \else \advance \result \chartonum{#1}% \multiply \result \radix \let\next\buildcommalist \fi \next#2% } \setvalue{radtonum2}#1% {\ifcase #1 0\or 1\else \error\fi} \setvalue{radtonum8}#1% {\ifcase #1 0\or 1\or2\or3\or4\or5\or6\or7\else \error\fi} \setvalue{radtonum10}#1% {\ifcase #1 0\or 1\or2\or3\or4\or5\or6\or7\or8\or9\else \error\fi} \setvalue{radtonum16}#1% {\ifcase #1 0\or 1\or2\or3\or4\or5\or6\or7\or8\or9\else \ifx#1a10\else \ifx#1b11\else \ifx#1c12\else \ifx#1d13\else \ifx#1e14\else \ifx#1f15\else \ifx#1A10\else \ifx#1B11\else \ifx#1C12\else \ifx#1D13\else \ifx#1E14\else \ifx#1F15\else \error \fi\fi\fi\fi\fi\fi \fi\fi\fi\fi\fi\fi \fi} % certain radix types don't use zero's. In decimal, there is % a special thingy for 0, and we use "1" "0" to indicate 10. % In e.g. alphabetic radices, there is a symbol for "10", and % no special symbol for 0. (In such radices, there is generally % a special way to specify "zero") \def\radixnozeroes#1#2{% \def\oldval{}% \edef\newlist##1{}% \def\radixnum{#1}% \processcommacommand[#2]\dofixzeroes \edef\newlist{\newlist,\oldval}% \let#2\newlist } \def\dofixzeroes#1{% \ifnum #1 = 0 \ifx\oldval\empty \edef\newval{#1}% \else \scratchcounter = \oldval \advance\scratchcounter -1 \edef\oldval{\the\scratchcounter}% \ifnum\oldval > 0 \edef\newlist{\newlist,\oldval}% \fi \edef\newval{\radixnum}% \fi \else \ifx\oldval\empty\else \edef\newlist{\newlist,\oldval}% \fi \edef\newval{#1}% \fi \edef\oldval{\newval}% } % 1,1 => aa % 1,2 => bb % 2,1 => aaa % 1,2,3 => 26*1+2 x (3) % toplevel commands: \newcount\dcharc \newcount\dcharcount \def\dodcharacter#1{% \advance\scratchcounter 1 \ifnum\scratchcounter = \commalistsize \ifnum\dcharcount = 0 \dcharcount = 1\fi \dorecurse{\the\dcharcount}{\character{#1}}% \else \dcharc = #1 \advance \dcharc 1 \ifnum \dcharcount = 0 \else \multiply \dcharcount 26 \fi \advance\dcharcount \dcharc \fi }% \def\dcharacters#1{% \converttoradix{26}{#1}% \radixnozeroes{26}\radixresult \expandafter\getcommalistsize\expandafter[\radixresult] \dcharcount = 0 \scratchcounter = 0 \dcharc = 1 \processcommacommand[\radixresult]\dodcharacter} \def\characters#1{% \converttoradix{26}{#1}% \radixnozeroes{26}\radixresult \processcommacommand[\radixresult]\character} \def\Characters#1{% \converttoradix{26}{#1}% \radixnozeroes{26}\radixresult \processcommacommand[\radixresult]\Character} \def\octal#1{\converttoradix{8}{#1}% \expandafter\processcommalist\expandafter[\radixresult]\numbers} \def\hexal#1{\converttoradix{16}{#1}% \expandafter\processcommalist\expandafter[\radixresult]\lchexnumber} \def\Hexal#1{\converttoradix{16}{#1}% \expandafter\processcommalist\expandafter[\radixresult]\uchexnumber} \def\binary#1{\converttoradix{2}{#1}% \expandafter\processcommalist\expandafter[\radixresult]\numbers} \protect --------------2708132DD8DB6616593C5ED0--