ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Label loops within a XeConTeXt document
@ 2007-06-23 18:12 nicola
  2007-06-23 19:20 ` Aditya Mahajan
  0 siblings, 1 reply; 6+ messages in thread
From: nicola @ 2007-06-23 18:12 UTC (permalink / raw)
  To: ntg-context

Hi,
given the following XeConTeXt document (I use ConTeXt  ver: 2007.01.12):

\definetypeface[MyMainFace][rm][Xserif][Charis SIL][default][encoding=uc]
\definetypeface[MyMainFace][mm][math][euler][euler]
\setupbodyfont[MyMainFace,10pt]

\startuseMPgraphic{foo}
   for i = 0 upto 10:
      % Draw a label at position (i*cm,0)
   endfor;
\stopuseMPgraphic

\starttext
\midaligned{\useMPgraphic{foo}}
\stoptext

is it possible to replace the comment with an instruction (or a macro), 
such that I do not get compilation errors and I get consistent font 
usage?

I have tried the following possibilities:

a) label("test",(i*cm,0)); % Complains about missing metrics for font
b) label(\textext{test},(i*cm,0)); % Ditto
c) label(btex test $x$ etex,(i*cm,0));  % Results in wrong font
d) label(\sometxt{test},(i*cm,0)); % Ok, right font, but loop is ignored

The best option to my knowledge is \sometxt, but I have read that it 
cannot be used in loops. Before I start unrolling all the loops in my 
figures

1) is it possible to specify the fonts in an MPenviroment? If so, how?
2) is there some hack, maybe along the lines of the following (not 
working) example?

vardef prepare(expr n) =
   save s; string s;
   s = "";
   for i = 0 upto n-1:
      s := s & "label(\sometxt{test},(" & decimal(i) & "*cm,0));";
   endfor;
   s
enddef;
scantokens(prepare(10));

Nicola

___________________________________________________________________________________
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] 6+ messages in thread

* Re: Label loops within a XeConTeXt document
  2007-06-23 18:12 Label loops within a XeConTeXt document nicola
@ 2007-06-23 19:20 ` Aditya Mahajan
  2007-06-23 20:42   ` nicola
  0 siblings, 1 reply; 6+ messages in thread
From: Aditya Mahajan @ 2007-06-23 19:20 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sat, 23 Jun 2007, nicola wrote:

> Hi,
> given the following XeConTeXt document (I use ConTeXt  ver: 2007.01.12):
>
> \definetypeface[MyMainFace][rm][Xserif][Charis SIL][default][encoding=uc]
> \definetypeface[MyMainFace][mm][math][euler][euler]
> \setupbodyfont[MyMainFace,10pt]
>
> \startuseMPgraphic{foo}
>   for i = 0 upto 10:
>      % Draw a label at position (i*cm,0)
>   endfor;
> \stopuseMPgraphic
>
> \starttext
> \midaligned{\useMPgraphic{foo}}
> \stoptext
>
> is it possible to replace the comment with an instruction (or a macro),
> such that I do not get compilation errors and I get consistent font
> usage?
>
> I have tried the following possibilities:
>
> a) label("test",(i*cm,0)); % Complains about missing metrics for font
> b) label(\textext{test},(i*cm,0)); % Ditto

This is strange. Do you also get this error if you use pdftex instead 
of xetex?

> c) label(btex test $x$ etex,(i*cm,0));  % Results in wrong font
> d) label(\sometxt{test},(i*cm,0)); % Ok, right font, but loop is ignored
>
> The best option to my knowledge is \sometxt, but I have read that it
> cannot be used in loops. Before I start unrolling all the loops in my
> figures
>
> 1) is it possible to specify the fonts in an MPenviroment? If so, how?

Just as you will specify fonts in your regular document. The easiest 
way is as follows:

Place

\startMPinclusions[global]
..
\stopMPinclusions

around the font definitions in your document. That way, the same fonts 
will be used in your document and in metapost. But I have never tested 
this with xetex. In priciple, this should work (as long as texexec 
calls metapost with tex=xetex).

> 2) is there some hack, maybe along the lines of the following (not
> working) example?
>
> vardef prepare(expr n) =
>   save s; string s;
>   s = "";
>   for i = 0 upto n-1:
>      s := s & "label(\sometxt{test},(" & decimal(i) & "*cm,0));";
>   endfor;
>   s
> enddef;
> scantokens(prepare(10));

Have you checked \startTeXtexts ...\stopTeXtexts? See Section 4.4 of 
Mojca's MyWay on \sometxt 
(http://dl.contextgarden.net/myway/sometxt.pdf)

Aditya
___________________________________________________________________________________
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] 6+ messages in thread

* Re: Label loops within a XeConTeXt document
  2007-06-23 19:20 ` Aditya Mahajan
@ 2007-06-23 20:42   ` nicola
  2007-06-23 21:39     ` Aditya Mahajan
  0 siblings, 1 reply; 6+ messages in thread
From: nicola @ 2007-06-23 20:42 UTC (permalink / raw)
  To: ntg-context

In article <alpine.WNT.0.99.0706231512220.2368@nqvgln>,
 Aditya Mahajan <adityam@umich.edu> wrote:

> On Sat, 23 Jun 2007, nicola wrote:
> 
> > Hi,
> > given the following XeConTeXt document (I use ConTeXt  ver: 2007.01.12):
> >
> > \definetypeface[MyMainFace][rm][Xserif][Charis SIL][default][encoding=uc]
> > \definetypeface[MyMainFace][mm][math][euler][euler]
> > \setupbodyfont[MyMainFace,10pt]
> >
> > \startuseMPgraphic{foo}
> >   for i = 0 upto 10:
> >      % Draw a label at position (i*cm,0)
> >   endfor;
> > \stopuseMPgraphic
> >
> > \starttext
> > \midaligned{\useMPgraphic{foo}}
> > \stoptext
> >
> > is it possible to replace the comment with an instruction (or a macro),
> > such that I do not get compilation errors and I get consistent font
> > usage?
> >
> > I have tried the following possibilities:
> >
> > a) label("test",(i*cm,0)); % Complains about missing metrics for font
> > b) label(\textext{test},(i*cm,0)); % Ditto
> 
> This is strange. Do you also get this error if you use pdftex instead 
> of xetex?
> 
> > c) label(btex test $x$ etex,(i*cm,0));  % Results in wrong font
> > d) label(\sometxt{test},(i*cm,0)); % Ok, right font, but loop is ignored
> >
> > The best option to my knowledge is \sometxt, but I have read that it
> > cannot be used in loops. Before I start unrolling all the loops in my
> > figures
> >
> > 1) is it possible to specify the fonts in an MPenviroment? If so, how?
> 
> Just as you will specify fonts in your regular document. 

Putting the same definitions inside \startMPinclusions... 
\stopMPinclusions does not seem to work with XeTeX.

> Have you checked \startTeXtexts ...\stopTeXtexts? See Section 4.4 of 
> Mojca's MyWay on \sometxt 
> (http://dl.contextgarden.net/myway/sometxt.pdf)

Ah, I did not know about those commands: that works! Just a silly 
question, though: how do I change

\startTeXtexts 
   \dorecurse{10}{\TeXtext{\recurselevel}{$x_{\recurselevel}$}} 
\stopTeXtexts 

so that I can print labels from x_0 up to x_9? Do I need to use 
\defineconversion and \convertnumber?

Nicola

___________________________________________________________________________________
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] 6+ messages in thread

* Re: Label loops within a XeConTeXt document
  2007-06-23 20:42   ` nicola
@ 2007-06-23 21:39     ` Aditya Mahajan
  2007-06-23 22:09       ` nicola
  2007-06-24  8:33       ` nicola
  0 siblings, 2 replies; 6+ messages in thread
From: Aditya Mahajan @ 2007-06-23 21:39 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sat, 23 Jun 2007, nicola wrote:

> In article <alpine.WNT.0.99.0706231512220.2368@nqvgln>,
> Aditya Mahajan <adityam@umich.edu> wrote:
>
>> On Sat, 23 Jun 2007, nicola wrote:
>>
>>> Hi,
>>> given the following XeConTeXt document (I use ConTeXt  ver: 2007.01.12):
>>>
>>> \definetypeface[MyMainFace][rm][Xserif][Charis SIL][default][encoding=uc]
>>> \definetypeface[MyMainFace][mm][math][euler][euler]
>>> \setupbodyfont[MyMainFace,10pt]
>>>
>>> \startuseMPgraphic{foo}
>>>   for i = 0 upto 10:
>>>      % Draw a label at position (i*cm,0)
>>>   endfor;
>>> \stopuseMPgraphic
>>>
>>> \starttext
>>> \midaligned{\useMPgraphic{foo}}
>>> \stoptext
>>>
>>> is it possible to replace the comment with an instruction (or a macro),
>>> such that I do not get compilation errors and I get consistent font
>>> usage?
>>>
>>> I have tried the following possibilities:
>>>
>>> a) label("test",(i*cm,0)); % Complains about missing metrics for font
>>> b) label(\textext{test},(i*cm,0)); % Ditto
>>
>> This is strange. Do you also get this error if you use pdftex instead
>> of xetex?
>>
>>> c) label(btex test $x$ etex,(i*cm,0));  % Results in wrong font
>>> d) label(\sometxt{test},(i*cm,0)); % Ok, right font, but loop is ignored
>>>
>>> The best option to my knowledge is \sometxt, but I have read that it
>>> cannot be used in loops. Before I start unrolling all the loops in my
>>> figures
>>>
>>> 1) is it possible to specify the fonts in an MPenviroment? If so, how?
>>
>> Just as you will specify fonts in your regular document.
>
> Putting the same definitions inside \startMPinclusions...
> \stopMPinclusions does not seem to work with XeTeX.

It is MPenvironent and not MPinclusions. I do not have xetex, so I 
can not test this.

>> Have you checked \startTeXtexts ...\stopTeXtexts? See Section 4.4 of
>> Mojca's MyWay on \sometxt
>> (http://dl.contextgarden.net/myway/sometxt.pdf)
>
> Ah, I did not know about those commands: that works! Just a silly
> question, though: how do I change
>
> \startTeXtexts
>   \dorecurse{10}{\TeXtext{\recurselevel}{$x_{\recurselevel}$}}
> \stopTeXtexts
>
> so that I can print labels from x_0 up to x_9? Do I need to use
> \defineconversion and \convertnumber?

No, use \dostepwiserecuse. The general syntax is

\dostepwiserecurse {from} {to} {step} {action}

so

\dostepwiserecurse {0} {9} {1} 
{\TeXtext{\recurselevel}{$x_{\recurselevel}$} should work.

Aditya



___________________________________________________________________________________
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] 6+ messages in thread

* Re: Label loops within a XeConTeXt document
  2007-06-23 21:39     ` Aditya Mahajan
@ 2007-06-23 22:09       ` nicola
  2007-06-24  8:33       ` nicola
  1 sibling, 0 replies; 6+ messages in thread
From: nicola @ 2007-06-23 22:09 UTC (permalink / raw)
  To: ntg-context


> >>> 1) is it possible to specify the fonts in an MPenviroment? If so, how?
> >>
> >> Just as you will specify fonts in your regular document.
> >
> > Putting the same definitions inside \startMPinclusions...
> > \stopMPinclusions does not seem to work with XeTeX.
> 
> It is MPenvironent and not MPinclusions. I do not have xetex, so I 
> can not test this.

Ok, even if I put those definitions in an MPenvironment the text fonts 
do not change (I guess the mechanism for font selection is slightly 
different in XeTeX).

> > how do I change
> >
> > \startTeXtexts
> >   \dorecurse{10}{\TeXtext{\recurselevel}{$x_{\recurselevel}$}}
> > \stopTeXtexts
> >
> > so that I can print labels from x_0 up to x_9? Do I need to use
> > \defineconversion and \convertnumber?
> 
> No, use \dostepwiserecuse. The general syntax is
> 
> \dostepwiserecurse {from} {to} {step} {action}
> 
> so
> 
> \dostepwiserecurse {0} {9} {1} 
> {\TeXtext{\recurselevel}{$x_{\recurselevel}$} should work.

Thank you very much!

Nicola

___________________________________________________________________________________
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] 6+ messages in thread

* Re: Label loops within a XeConTeXt document
  2007-06-23 21:39     ` Aditya Mahajan
  2007-06-23 22:09       ` nicola
@ 2007-06-24  8:33       ` nicola
  1 sibling, 0 replies; 6+ messages in thread
From: nicola @ 2007-06-24  8:33 UTC (permalink / raw)
  To: ntg-context

> >  how do I change
> >
> > \startTeXtexts
> >   \dorecurse{10}{\TeXtext{\recurselevel}{$x_{\recurselevel}$}}
> > \stopTeXtexts
> >
> > so that I can print labels from x_0 up to x_9? Do I need to use
> > \defineconversion and \convertnumber?
> 
> No, use \dostepwiserecuse. The general syntax is
> 
> \dostepwiserecurse {from} {to} {step} {action}
> 
> so
> 
> \dostepwiserecurse {0} {9} {1}

I guess it must be \dostepwiserecurse {0} {9} {1} {}

> {\TeXtext{\recurselevel}{$x_{\recurselevel}$} should work.

I have tried that, but sometxt(0) prints nothing. Anyway, I have solved 
it like this:

\startTeXtexts
   \TeXtext{0}{$x_0$}
   \dorecurse{30}{\TeXtext{\recurselevel}{$x_{\recurselevel}$}}
\stopTeXtexts

Thanks again!
Nicola

___________________________________________________________________________________
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] 6+ messages in thread

end of thread, other threads:[~2007-06-24  8:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-23 18:12 Label loops within a XeConTeXt document nicola
2007-06-23 19:20 ` Aditya Mahajan
2007-06-23 20:42   ` nicola
2007-06-23 21:39     ` Aditya Mahajan
2007-06-23 22:09       ` nicola
2007-06-24  8:33       ` nicola

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