Label loops within a XeConTeXt document
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
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
In article
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
On Sat, 23 Jun 2007, nicola wrote:
In article
, Aditya Mahajan 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
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
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
participants (2)
-
Aditya Mahajan
-
nicola