1

I would like to expand one string array in a short metafun loop. Each box should be labelled with the appropriate string ("classicism", "Lumières", "romanticism"). How can I make the label function, inside btex etex, expand those strings. I did not find some example of string array, let's hope it's properly declared.

\setuppapersize[S6][S6]
\starttext
  \startMPcode
           %numeric u, l, h ;
           u:=5pt ;
           l:=20 ;
           h:=8 ;
           path p ;
           p:= unitsquare xscaled (l*u) yscaled (h*u) ;
           string c[] ;
           c[0]:="classicisme"; 
           c[20]:="Lumières";
           c[40]:="romantisme";
           for i=0 step 20 until 40 :
              fill p xshifted i*u  withcolor  (.8-(i/200))*white; 
              label(btex c[i] etex, ((i+l/2)*u,(h/2)*u)) ; 
           endfor ;
   \stopMPcode

\stoptext

My MWE does not even return c[0], c[20] and c[40] as labels, so I surely miss something with expansion.

EDIT After reading this question, I tried this

 label.bot(TEX("c[i]"), ((i+l/2)*u,(h/2)*u)) ;

but it does not compile.

2
  • Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. A MWE should compile and be as small as possible to demonstrate your problem. it's much easier to help you if we have full working code to start from. Currently your code does not compile and I have no idea what packges you're using.
    – user30471
    Oct 10, 2017 at 4:52
  • @Andrew This MWE compiles and is as small as possible. Nevertheless my mistake, I forgot to say this is a ConTeXt MWE.
    – sztruks
    Oct 10, 2017 at 7:14

1 Answer 1

1

You can just pass the string as it is to label: replace the line

label(btex c[i] etex, ((i+l/2)*u,(h/2)*u)) ;

with

label(c[i], ((i+l/2)*u,(h/2)*u)) ;

and you're done.

(By the way, nowadays (reference) you can just do \setuppapersize[S6] instead of \setuppapersize[S6][S6]: the second argument, if not given, will default to the first one.)

5
  • Do you know, if there is a way to get it done within a TeX parsing ?
    – sztruks
    Oct 10, 2017 at 9:52
  • 1
    @sztruks I'm afraid I don't know what you mean. In my experience you can pretend that MetaPost strings are "TeX strings" and (by some dark magic that ConTeXt performs) you won't run into any trouble. For example, replace c[0]:="classicisme"; with c[0]:="\color[red]{\em classicisme}"; and it just works.
    – 9tTn9B
    Oct 10, 2017 at 10:06
  • Ok, I did not knew that. Maybe some metafun improvement…
    – sztruks
    Oct 10, 2017 at 16:35
  • Yes this is a Metafun feature. You can get the same effect with luamplib and the textextenable option.
    – Thruston
    Oct 10, 2017 at 20:34
  • The latexmp MetaPost package allows this as well for vanilla MetaPost with LaTeX as labels typesetter. At the cost of a double compilation, though. Oct 26, 2017 at 9:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .