# [NTG-context] Label loops within a XeConTeXt document

Sat Jun 23 23:39:30 CEST 2007

```On Sat, 23 Jun 2007, nicola wrote:

> In article <alpine.WNT.0.99.0706231512220.2368 at nqvgln>,
>
>> 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.