* how to figure out the number of elements inside \defineconversion?
@ 2006-08-10 14:16 Mojca Miklavec
2006-08-10 15:22 ` Hans Hagen
0 siblings, 1 reply; 3+ messages in thread
From: Mojca Miklavec @ 2006-08-10 14:16 UTC (permalink / raw)
Hello,
I would like to \defineconversion and the use that set of symbols
inside a metapost graphic. But I need to know the number of symbols,
so that I can define enough "metapost images with symbols" in advance.
I realise that there might be a problem since conversion can sometimes
take an arbitrary number (using a command defined elsewhere), but if I
could have a reasonable guess for conversions defined explicitely,
that would already help a lot. (As a workaround and/or if there is no
easy method to figure that out I can still hardcode "25" and wait
until someone complains that that is not enough to satisfy his/her
needs.)
Thanks a lot,
Mojca
\startMPextensions
numeric variant; variant = 1;
vardef gp_the_symbol(expr n) =
picture pict;
% using metapost
if variant=1:
pict := image( fill fullcircle scaled 4pt; ); % TODO
% using TeX, variant = 2
else: % TODO: limit the number first
pict := sometxt(n);
fi;
pict shifted -center pict
enddef ;
def gp_point(expr x, y, n) =
draw (gp_the_symbol(n) scaled 1 shifted (x,y));
enddef ;
\stopMPextensions
\starttext
\defineconversion[abc][$\star$,$\bullet$,$\ast$]
\startTeXtexts
% TODO: 6 is only a guess: I need a better guess (3 in this case)
\dostepwiserecurse{1}{6}{1}{\TeXtext{\recurselevel}{{\convertnumber{abc}{\recurselevel}}}}
\stopTeXtexts
\startMPcode
variant := 1;
gp_point(1cm,0cm,1);
gp_point(2cm,0cm,2);
variant := 2;
gp_point(1cm,1cm,1);
gp_point(2cm,1cm,2);
gp_point(3cm,1cm,3);
gp_point(4cm,1cm,4);
gp_point(5cm,1cm,8);
\stopMPcode
\stoptext
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: how to figure out the number of elements inside \defineconversion?
2006-08-10 14:16 how to figure out the number of elements inside \defineconversion? Mojca Miklavec
@ 2006-08-10 15:22 ` Hans Hagen
2006-08-10 19:36 ` Mojca Miklavec
0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen @ 2006-08-10 15:22 UTC (permalink / raw)
Mojca Miklavec wrote:
> Hello,
>
> I would like to \defineconversion and the use that set of symbols
> inside a metapost graphic. But I need to know the number of symbols,
> so that I can define enough "metapost images with symbols" in advance.
> I realise that there might be a problem since conversion can sometimes
> take an arbitrary number (using a command defined elsewhere), but if I
> could have a reasonable guess for conversions defined explicitely,
> that would already help a lot. (As a workaround and/or if there is no
> easy method to figure that out I can still hardcode "25" and wait
> until someone complains that that is not enough to satisfy his/her
> needs.)
>
> Thanks a lot,
> Mojca
>
>
> \startMPextensions
> numeric variant; variant = 1;
> vardef gp_the_symbol(expr n) =
> picture pict;
> % using metapost
> if variant=1:
> pict := image( fill fullcircle scaled 4pt; ); % TODO
> % using TeX, variant = 2
> else: % TODO: limit the number first
> pict := sometxt(n);
> fi;
> pict shifted -center pict
> enddef ;
>
> def gp_point(expr x, y, n) =
> draw (gp_the_symbol(n) scaled 1 shifted (x,y));
> enddef ;
> \stopMPextensions
>
> \starttext
>
> \defineconversion[abc][$\star$,$\bullet$,$\ast$]
>
> \startTeXtexts
> % TODO: 6 is only a guess: I need a better guess (3 in this case)
> \dostepwiserecurse{1}{6}{1}{\TeXtext{\recurselevel}{{\convertnumber{abc}{\recurselevel}}}}
> \stopTeXtexts
>
> \startMPcode
> variant := 1;
> gp_point(1cm,0cm,1);
> gp_point(2cm,0cm,2);
> variant := 2;
> gp_point(1cm,1cm,1);
> gp_point(2cm,1cm,2);
> gp_point(3cm,1cm,3);
> gp_point(4cm,1cm,4);
> gp_point(5cm,1cm,8);
> \stopMPcode
>
> \stoptext
>
\unprotect
\def\doifelseconversionnumber#1#2%
{\doifdefinedelse{\??cv#1#2}}
\protect
\defineconversion[abc][$\star$,$\bullet$,$\ast$]
\defineconversion[def][m,o,j,c,a]
\doloop
{\doifelseconversionnumber{abc}{\recurselevel}
{[abc \recurselevel\space defined]}
{\exitloop}}
\doloop
{\doifelseconversionnumber{def}{\recurselevel}
{[def \recurselevel\space defined]}
{\exitloop}}
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: how to figure out the number of elements inside \defineconversion?
2006-08-10 15:22 ` Hans Hagen
@ 2006-08-10 19:36 ` Mojca Miklavec
0 siblings, 0 replies; 3+ messages in thread
From: Mojca Miklavec @ 2006-08-10 19:36 UTC (permalink / raw)
On 8/10/06, Hans Hagen wrote:
> Mojca Miklavec wrote:
> > Hello,
> >
> > I would like to \defineconversion and the use that set of symbols
> > inside a metapost graphic. But I need to know the number of symbols,
> > so that I can define enough "metapost images with symbols" in advance.
> > I realise that there might be a problem since conversion can sometimes
> > take an arbitrary number (using a command defined elsewhere), but if I
> > could have a reasonable guess for conversions defined explicitely,
> > that would already help a lot. (As a workaround and/or if there is no
> > easy method to figure that out I can still hardcode "25" and wait
> > until someone complains that that is not enough to satisfy his/her
> > needs.)
> \unprotect
>
> \def\doifelseconversionnumber#1#2%
> {\doifdefinedelse{\??cv#1#2}}
>
> \protect
>
> \defineconversion[abc][$\star$,$\bullet$,$\ast$]
> \defineconversion[def][m,o,j,c,a]
>
> \doloop
> {\doifelseconversionnumber{abc}{\recurselevel}
> {[abc \recurselevel\space defined]}
> {\exitloop}}
>
> \doloop
> {\doifelseconversionnumber{def}{\recurselevel}
> {[def \recurselevel\space defined]}
> {\exitloop}}
Perfect. That's exactly what I needed. I only have to keep my fingers
crossed now (I haven't tested the executable for a while) ...
Mojca
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-08-10 19:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-10 14:16 how to figure out the number of elements inside \defineconversion? Mojca Miklavec
2006-08-10 15:22 ` Hans Hagen
2006-08-10 19:36 ` Mojca Miklavec
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).