> On 17 Feb 2021, at 17:40, Fabrice Couvreur <fabrice1.couvr...@gmail.com> 
> wrote:
> 
> Hi, The code works, but is it possible to make it shorter ? 
> Thank you
> Fabrice
> 

You can reduce the size of the test by storing the pattern in a table:

\startluacode
  local background_one = {
   align = "middle",
   style = "type",
   background = "DiagonalRule",
  }

  local letters_1 = { "A", "B", "C", "D", "E", "F", "G", "H" }
  local pattern_1 = { 
    ".XXX..XX",
    "X...XXX.",
    "X..X.XXX",
    "X.X.X..X",
    ".X.X.XX.",
    ".XX.X...",
    "XXX.X...",
    "X.XX...." }
  context.startxtable({"align={middle,lohi}, 
width=0.8cm,offset=0.8ex,bodyfont=9pt,framecolor=cyan"})
  context.startxrow()
  context.startxcell({"frame=off"})
  context()
  context.stopxcell()
  for _, letter in ipairs(letters_1) do
    context.startxcell()
    context(letter) context.stopxcell()
  end
  context.stopxrow()
   for i, letter in ipairs(letters_1) do
  context.startxrow()
    context.startxcell()
    context(letter)
    context.stopxcell()
  for j = 1, 8 do
    context.startxcell( string.sub(pattern_1[i],j,j) == "X" and background_one )
  context()
  context.stopxcell()
  end
  context.stopxrow()
  end
  context.stopxtable()
\stopluacode

—
Bruce Horrocks
Hampshire, UK

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to