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.

           %numeric u, l, h ;
           u:=5pt ;
           l:=20 ;
           h:=8 ;
           path p ;
           p:= unitsquare xscaled (l*u) yscaled (h*u) ;
           string c[] ;
           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 ;


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.

  • 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 '17 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 '17 at 7:14

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


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

  • Do you know, if there is a way to get it done within a TeX parsing ? – sztruks Oct 10 '17 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 '17 at 10:06
  • Ok, I did not knew that. Maybe some metafun improvement… – sztruks Oct 10 '17 at 16:35
  • Yes this is a Metafun feature. You can get the same effect with luamplib and the textextenable option. – Thruston Oct 10 '17 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. – Franck Pastor Oct 26 '17 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.