I am designing pseudo-crosswords for my pupils exercices with the following macro:
\startMPinclusions
% could'nt achieve using the word string length as a first parameter
vardef MotMystere (expr taille,speciale,index) =
numeric avant,apres;
path case;
case:= fullsquare scaled 13;
avant=speciale-1;
apres=taille-speciale;
if avant >= 1:
for j=1 upto avant:
draw (case rotated 180
cutafter point 3 of case rotated 180)
shifted (-13j,-13*index);
endfor;
fi;
label.lft (index,point 3.5 of
case shifted (-13*avant,-13*index));
draw case yshifted (-13*index);
fill case yshifted (-13*index)
withcolor \MPcolor{gray-8};
if apres > 0:
for j=1 upto apres:
draw (case cutafter point 3 of case)
shifted (13j,-13*index);
endfor;
fi;
enddef;
\stopMPinclusions
\starttext
An example with "enigma"
\startMPcode
MotMystere(6,4,1)
\stopMPcode
\stoptext
I tried to spare some error-prone counts using string.len()
. The idea would be to give the word as a first parameter, instead of its manually counted string length, eg MotMystere("enigma",4,1)
. However I couldn't figure out how should I pass this string parameter to the lua function.