The basis of my problem is I am making a 14x14 crossword puzzle, I have the data for each of the 196 cells from an outside document, but need only the cells with text inside to have borders.
I tried using MetaPost to solve this. For simplicity, I've reduced the code to just a 14x1 grid example here.
I created an outside script which gives me all of the values that should go inside the grid. E.g., if the first row has "cat" across, then it gives this:
\setvalue{1}{c}
\setvalue{2}{a}
\setvalue{3}{t}
\setvalue{4}{}
\setvalue{5}{}
\setvalue{6}{}
\setvalue{7}{}
\setvalue{8}{}
\setvalue{9}{}
\setvalue{10}{}
\setvalue{11}{}
\setvalue{12}{}
\setvalue{13}{}
\setvalue{14}{}
The full 14x14 example has 196 such variables, but place in another file by a script, so they aren't unwieldy.
I used MetaPost to create many boxes, rather than tables, as I could find no clean way to add the subscript text to the corner of a cell in a table without it pushing the letter in that cell to the right.
Here is the minimal working example of the solution page is this:
\setvalue{1}{c}
\setvalue{2}{a}
\setvalue{3}{t}
\setvalue{4}{}
\setvalue{5}{}
\setvalue{6}{}
\setvalue{7}{}
\setvalue{8}{}
\setvalue{9}{}
\setvalue{10}{}
\setvalue{11}{}
\setvalue{12}{}
\setvalue{13}{}
\setvalue{14}{}
\define\crosswordsolution{%
\scale[width=\textwidth]{%
\startMPcode
draw (0,0)--(100,0)--(100,100)--(0,100)--(0,0);
draw (100,0)--(200,0)--(200,100)--(100,100)--(100,0);
draw (200,0)--(300,0)--(300,100)--(200,100)--(200,0);
draw (300,0)--(400,0)--(400,100)--(300,100)--(300,0);
draw (400,0)--(500,0)--(500,100)--(400,100)--(400,0);
draw (500,0)--(600,0)--(600,100)--(500,100)--(500,0);
draw (600,0)--(700,0)--(700,100)--(600,100)--(600,0);
draw (700,0)--(800,0)--(800,100)--(700,100)--(700,0);
draw (800,0)--(900,0)--(900,100)--(800,100)--(800,0);
draw (900,0)--(1000,0)--(1000,100)--(900,100)--(900,0);
draw (1000,0)--(1100,0)--(1100,100)--(1000,100)--(1000,0);
draw (1100,0)--(1200,0)--(1200,100)--(1100,100)--(1100,0);
draw (1200,0)--(1300,0)--(1300,100)--(1200,100)--(1200,0);
draw (1300,0)--(1400,0)--(1400,100)--(1300,100)--(1300,0);
label("\getvalue{1}", (50,50));
label("\getvalue{2}", (150,50));
label("\getvalue{3}", (250,50));
label("\getvalue{4}", (350,50));
label("\getvalue{5}", (450,50));
label("\getvalue{6}", (550,50));
label("\getvalue{7}", (650,50));
label("\getvalue{8}", (750,50));
label("\getvalue{9}", (850,50));
label("\getvalue{10}", (950,50));
label("\getvalue{11}", (1050,50));
label("\getvalue{12}", (1150,50));
label("\getvalue{13}", (1250,50));
label("\getvalue{14}", (1350,50));
label("1", (25,75));
\stopMPcode
}%
}%
\starttext
\crosswordsolution
\stoptext
The problem I have is that I need only those boxes with a letter inside to be drawn. The empty boxes needn't be drawn at all. In other words, only the boxes containing the letters in C-A-T need to be drawn, the others are invisible.
I tried using simple TeX conditionals inside MetaPost, checking if the variable is empty, but the code came up with errors, so I suspect MetaPost can't have TeX or ConTeXt code inside \startMPcode
and \endMPcode
.
Is there some way to create conditions that allows specific boxes to be drawn only if the matching variable has text?