Re: [NTG-context] Lua code and table

2021-02-20 Thread Fabrice Couvreur
Hi Hans
The xx.tex file works for me
Thanks
Fabrice

Le ven. 19 févr. 2021 à 14:28, Hans Hagen  a écrit :

> On 2/19/2021 2:12 PM, Jano Kula wrote:
> > Hi,
> >
> > On Fri, 19 Feb 2021 at 13:06, Hans Hagen  > > wrote:
> >
> > On 2/19/2021 12:42 PM, Fabrice Couvreur wrote:
> >  > Hi Hans,Thanks again for the ideas to improve my code. However, I
> > am new
> >  > to Lua and my level is far from sufficient to understand
> > everything. Why
> >  > in no table do the crosses appear in the cells; which was my
> > original
> >  > idea.Thank you.Fabrice
> > I get a cross (see attached).
> >
> >
> > I've got no crosses with ConTeXt  ver: 2021.02.05 17:45 LMTX.
> > Fresh install of ConTeXt  ver: 2021.02.19 13:15 LMTX gives me no
> > crosses, too.
> > No missing fonts in both cases.
> > Log and tuc attached.
> And with the previously attached xx.tex file? maybe the mailer messes up
> something?
>
> Hans
>
> -
>Hans Hagen | PRAGMA ADE
>Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
> tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -
>
> ___
> 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
>
> ___
>
___
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
___


Re: [NTG-context] Lua code and table

2021-02-19 Thread Hans Hagen

On 2/19/2021 2:12 PM, Jano Kula wrote:

Hi,

On Fri, 19 Feb 2021 at 13:06, Hans Hagen > wrote:


On 2/19/2021 12:42 PM, Fabrice Couvreur wrote:
 > Hi Hans,Thanks again for the ideas to improve my code. However, I
am new
 > to Lua and my level is far from sufficient to understand
everything. Why
 > in no table do the crosses appear in the cells; which was my
original
 > idea.Thank you.Fabrice
I get a cross (see attached).


I've got no crosses with ConTeXt  ver: 2021.02.05 17:45 LMTX.
Fresh install of ConTeXt  ver: 2021.02.19 13:15 LMTX gives me no 
crosses, too.

No missing fonts in both cases.
Log and tuc attached.
And with the previously attached xx.tex file? maybe the mailer messes up 
something?


Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
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
___


Re: [NTG-context] Lua code and table

2021-02-19 Thread Jano Kula
Hi,

On Fri, 19 Feb 2021 at 13:06, Hans Hagen  wrote:

> On 2/19/2021 12:42 PM, Fabrice Couvreur wrote:
> > Hi Hans,Thanks again for the ideas to improve my code. However, I am new
> > to Lua and my level is far from sufficient to understand everything. Why
> > in no table do the crosses appear in the cells; which was my original
> > idea.Thank you.Fabrice
> I get a cross (see attached).
>

I've got no crosses with ConTeXt  ver: 2021.02.05 17:45 LMTX.
Fresh install of ConTeXt  ver: 2021.02.19 13:15 LMTX gives me no crosses,
too.
No missing fonts in both cases.
Log and tuc attached.

Jano


hans-metapost.log
Description: Binary data


hans-metapost.tuc
Description: Binary data
___
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
___


Re: [NTG-context] Lua code and table

2021-02-19 Thread Hans Hagen

On 2/19/2021 12:42 PM, Fabrice Couvreur wrote:
Hi Hans,Thanks again for the ideas to improve my code. However, I am new 
to Lua and my level is far from sufficient to understand everything. Why 
in no table do the crosses appear in the cells; which was my original 
idea.Thank you.Fabrice

I get a cross (see attached).

Hans



-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
\setupbodyfont[pagella]

\starttext

\definextable
  [MyTable]
  [align={middle,lohi},
   width=0.8cm,
   offset=0.8ex,
   bodyfont=9pt,
   framecolor=cyan]

\startluacode
function document.MyTable(specification)

local pattern= specification.pattern
local action = specification.action
local conversion = specification.conversion or "Characters"

local n = #pattern

--  context.startxtable { align = "middle,lohi", width = "0.8cm", offset = 
"0.8ex", bodyfont = "9pt", framecolor = "cyan" }
context.startxtable { "MyTable" }
context.startxrow()
context.startxcell { frame = "off" }
context()
context.stopxcell()
for i=1,n do
context.startxcell()
context.convertnumber(conversion,i)
context.stopxcell()
end
context.stopxrow()
for i=1,n do
context.startxrow()
context.startxcell()
context.convertnumber(conversion,i)
context.stopxcell()
for j=1,n do
context.startxcell { align = "middle" }
action(string.sub(pattern[i],j,j))
context.stopxcell()
end
context.stopxrow()
end
context.stopxtable()

end
\stopluacode

\startuniqueMPgraphic{cross}{width,height,depth,color,line}
draw image (
draw (\MPvar{depth},\MPvar{height}) -- (\MPvar{width},0) ;
draw (\MPvar{depth},0) -- (\MPvar{width},\MPvar{height}) ;
)
withpen pencircle scaled \MPvar{line}
withcolor \MPvar{color} ;
\stopuniqueMPgraphic

\definesymbol
  [MyRedCross]
  [\uniqueMPgraphic{cross}{width=1em,height=1ex,depth=.5ex,color=red,line=.2ex}]

\definesymbol
  [MyGreenCross]
  
[\uniqueMPgraphic{cross}{width=1em,height=1ex,depth=.5ex,color=green,line=.2ex}]

\startluacode
document.MyTable {
action = function(value)
context(value == "X" and 1 or 0)
end,
conversion = "Characters",
pattern = {
".XXX..XX",
"X...XXX.",
"X..X.XXX",
"X.X.X..X",
".X.X.XX.",
".XX.X...",
"XXX.X...",
"X.XX"
}
}
\stopluacode

\startluacode
document.MyTable {
action = function(value)
context(value == "X" and 1 or 0)
end,
conversion = "Greek",
pattern = {
".XXX..XX",
"X...XXX.",
"X..X.XXX",
"X.X.X..X",
}
}
\stopluacode

\startluacode
document.MyTable {
action = function(value)
if value == "X" then
context.symbol { "MyRedCross" }
end
end,
conversion = "Romannumerals",
pattern = {
".XXX..XX",
"X...XXX.",
"X..X.XXX",
"X.X.X..X",
".X.X.XX.",
".XX.X...",
"XXX.X...",
"X.XX"
}
}
\stopluacode

\startluacode
document.MyTable {
action = function(value)
context.symbol { value == "X" and "MyRedCross"  or "MyGreenCross" }
end,
conversion = "Romannumerals",
pattern = {
"X.X.X..X",
".X.X.XX.",
".XX.X...",
"XXX.X...",
"X.XX"
}
}
\stopluacode

\stoptext


xx.pdf
Description: Adobe PDF document
___
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
___


Re: [NTG-context] Lua code and table

2021-02-19 Thread Fabrice Couvreur
Hi Hans, Thanks again for the ideas to improve my code. However, I am new
to Lua and my level is far from sufficient to understand everything. Why in
no table do the crosses appear in the cells; which was my original idea. Thank
you. Fabrice

Le jeu. 18 févr. 2021 à 16:28, Fabrice Couvreur 
a écrit :

> Hello Jano,
> Thanks.
> Fabrice
>
> Le jeu. 18 févr. 2021 à 16:27, Jano Kula  a écrit :
>
>> Hello Fabrice,
>>
>>
>>
>> On Thu, 18 Feb 2021 at 16:19, Fabrice Couvreur <
>> fabrice1.couvr...@gmail.com> wrote:
>>
>>> Hi all, Thanks to you, I'm not at your level with Lua, but I'm learning
>>> thanks to you
>>> Hans, I compiled your code and I get an error message :
>>>
>>> lua error   > lua error on line 50 in file ./table_1.tex:
>>>
>>> token call, syntax: [ctxlua]:11: unexpected symbol near '='
>>>
>>> 13 \startluacode
>>> 14  function document.MyTable(specification)
>>> 15
>>> 16  local pattern= specification.pattern
>>> 17  local action = specification.action
>>> 18  local conversion = specification.conversion or
>>> "Characters"
>>> 19
>>> 20  local n = #pattern
>>> 21
>>> 22  --  context.startxtable { align = "middle,lohi", width =
>>> "0.8cm",
>>> 23 >>  offset = "0.8ex", bodyfont = "9pt", framecolor = "cyan" }
>>>
>>
>> Just comment out line 23, too, or join 22 + 23 to one line.
>>
>> Jano
>>
>>
>>
>> ___
>> 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
>>
>> ___
>>
>
___
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
___


Re: [NTG-context] Lua code and table

2021-02-18 Thread Fabrice Couvreur
Hello Jano,
Thanks.
Fabrice

Le jeu. 18 févr. 2021 à 16:27, Jano Kula  a écrit :

> Hello Fabrice,
>
>
>
> On Thu, 18 Feb 2021 at 16:19, Fabrice Couvreur <
> fabrice1.couvr...@gmail.com> wrote:
>
>> Hi all, Thanks to you, I'm not at your level with Lua, but I'm learning
>> thanks to you
>> Hans, I compiled your code and I get an error message :
>>
>> lua error   > lua error on line 50 in file ./table_1.tex:
>>
>> token call, syntax: [ctxlua]:11: unexpected symbol near '='
>>
>> 13 \startluacode
>> 14  function document.MyTable(specification)
>> 15
>> 16  local pattern= specification.pattern
>> 17  local action = specification.action
>> 18  local conversion = specification.conversion or
>> "Characters"
>> 19
>> 20  local n = #pattern
>> 21
>> 22  --  context.startxtable { align = "middle,lohi", width =
>> "0.8cm",
>> 23 >>  offset = "0.8ex", bodyfont = "9pt", framecolor = "cyan" }
>>
>
> Just comment out line 23, too, or join 22 + 23 to one line.
>
> Jano
>
>
>
> ___
> 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
>
> ___
>
___
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
___


Re: [NTG-context] Lua code and table

2021-02-18 Thread Jano Kula
Hello Fabrice,



On Thu, 18 Feb 2021 at 16:19, Fabrice Couvreur 
wrote:

> Hi all, Thanks to you, I'm not at your level with Lua, but I'm learning
> thanks to you
> Hans, I compiled your code and I get an error message :
>
> lua error   > lua error on line 50 in file ./table_1.tex:
>
> token call, syntax: [ctxlua]:11: unexpected symbol near '='
>
> 13 \startluacode
> 14  function document.MyTable(specification)
> 15
> 16  local pattern= specification.pattern
> 17  local action = specification.action
> 18  local conversion = specification.conversion or "Characters"
> 19
> 20  local n = #pattern
> 21
> 22  --  context.startxtable { align = "middle,lohi", width =
> "0.8cm",
> 23 >>  offset = "0.8ex", bodyfont = "9pt", framecolor = "cyan" }
>

Just comment out line 23, too, or join 22 + 23 to one line.

Jano
___
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
___


Re: [NTG-context] Lua code and table

2021-02-18 Thread Fabrice Couvreur
Hi all, Thanks to you, I'm not at your level with Lua, but I'm learning
thanks to you
Hans, I compiled your code and I get an error message :

lua error   > lua error on line 50 in file ./table_1.tex:

token call, syntax: [ctxlua]:11: unexpected symbol near '='

13 \startluacode
14  function document.MyTable(specification)
15
16  local pattern= specification.pattern
17  local action = specification.action
18  local conversion = specification.conversion or "Characters"
19
20  local n = #pattern
21
22  --  context.startxtable { align = "middle,lohi", width =
"0.8cm",
23 >>  offset = "0.8ex", bodyfont = "9pt", framecolor = "cyan" }
24  context.startxtable { "MyTable" }
25  context.startxrow()
26  context.startxcell { frame = "off" }
27  context()
28  context.stopxcell()
29  for i=1,n do
30  context.startxcell()
31  context.convertnumber(conversion,i)
32  context.stopxcell()
33  end

mtx-context | fatal error: return code: 256

TeX Output exited abnormally with code 1 at Thu Feb 18 16:13:29


Thank you very much
Fabrice

Le jeu. 18 févr. 2021 à 10:06, Hans Hagen  a écrit :

> On 2/18/2021 12:22 AM, Bruce Horrocks wrote:
>
> >> On 17 Feb 2021, at 17:40, Fabrice Couvreur 
> wrote:
> >>
> >> Hi, The code works, but is it possible to make it shorter ?
> OK, here is my take, based on earlier posts, bringing together some
> 'technologies':
>
> (1) make a document function which isolatees the code
> (2) then call it where needed
> (3) use the built in conversion code
> (4) use so called unique mp graphics (smaller files, faster run)
> (5) use symbols to get the baseline right
> (6) use a little abstraction in the table setup
>
> watch how we can pass a table instead of a string, so
>
> context.startxtable { align = "middle,lohi", width = "0.8cm", offset =
> "0.8ex", bodyfont = "9pt", framecolor = "cyan" }
>
> is ok, but anm abstraction is even better. Now, who will wikify it ...
>
> %%% code %%%
>
> \setupbodyfont[pagella]
>
> \starttext
>
> \definextable
>[MyTable]
>[align={middle,lohi},
> width=0.8cm,
> offset=0.8ex,
> bodyfont=9pt,
> framecolor=cyan]
>
> \startluacode
>  function document.MyTable(specification)
>
>  local pattern= specification.pattern
>  local action = specification.action
>  local conversion = specification.conversion or "Characters"
>
>  local n = #pattern
>
>  --  context.startxtable { align = "middle,lohi", width = "0.8cm",
> offset = "0.8ex", bodyfont = "9pt", framecolor = "cyan" }
>  context.startxtable { "MyTable" }
>  context.startxrow()
>  context.startxcell { frame = "off" }
>  context()
>  context.stopxcell()
>  for i=1,n do
>  context.startxcell()
>  context.convertnumber(conversion,i)
>  context.stopxcell()
>  end
>  context.stopxrow()
>  for i=1,n do
>  context.startxrow()
>  context.startxcell()
>  context.convertnumber(conversion,i)
>  context.stopxcell()
>  for j=1,n do
>  context.startxcell { align = "middle" }
>  action(string.sub(pattern[i],j,j))
>  context.stopxcell()
>  end
>  context.stopxrow()
>  end
>  context.stopxtable()
>
>  end
> \stopluacode
>
> \startuniqueMPgraphic{cross}{width,height,depth,color,line}
>  draw image (
>  draw (\MPvar{depth},\MPvar{height}) -- (\MPvar{width},0) ;
>  draw (\MPvar{depth},0) -- (\MPvar{width},\MPvar{height}) ;
>  )
>  withpen pencircle scaled \MPvar{line}
>  withcolor \MPvar{color} ;
> \stopuniqueMPgraphic
>
> \definesymbol
>[MyRedCross]
>
>
> [\uniqueMPgraphic{cross}{width=1em,height=1ex,depth=.5ex,color=red,line=.2ex}]
>
> \definesymbol
>[MyGreenCross]
>
>
> [\uniqueMPgraphic{cross}{width=1em,height=1ex,depth=.5ex,color=green,line=.2ex}]
>
> \startluacode
>  document.MyTable {
>  action = function(value)
>  context(value == "X" and 1 or 0)
>  end,
>  conversion = "Characters",
>  pattern = {
>  ".XXX..XX",
>  "X...XXX.",
>  "X..X.XXX",
>  "X.X.X..X",
>  ".X.X.XX.",
>  ".XX.X...",
>  "XXX.X...",
>  "X.XX"
>  }
>  }
> \stopluacode
>
> \startluacode
>  document.MyTable {
>  action = function(value)
>  context(value == "X" and 1 or 0)
> 

Re: [NTG-context] Lua code and table

2021-02-18 Thread Hans Hagen

On 2/18/2021 12:22 AM, Bruce Horrocks wrote:


On 17 Feb 2021, at 17:40, Fabrice Couvreur  wrote:

Hi, The code works, but is it possible to make it shorter ?
OK, here is my take, based on earlier posts, bringing together some 
'technologies':


(1) make a document function which isolatees the code
(2) then call it where needed
(3) use the built in conversion code
(4) use so called unique mp graphics (smaller files, faster run)
(5) use symbols to get the baseline right
(6) use a little abstraction in the table setup

watch how we can pass a table instead of a string, so

context.startxtable { align = "middle,lohi", width = "0.8cm", offset = 
"0.8ex", bodyfont = "9pt", framecolor = "cyan" }


is ok, but anm abstraction is even better. Now, who will wikify it ...

%%% code %%%

\setupbodyfont[pagella]

\starttext

\definextable
  [MyTable]
  [align={middle,lohi},
   width=0.8cm,
   offset=0.8ex,
   bodyfont=9pt,
   framecolor=cyan]

\startluacode
function document.MyTable(specification)

local pattern= specification.pattern
local action = specification.action
local conversion = specification.conversion or "Characters"

local n = #pattern

--  context.startxtable { align = "middle,lohi", width = "0.8cm", 
offset = "0.8ex", bodyfont = "9pt", framecolor = "cyan" }

context.startxtable { "MyTable" }
context.startxrow()
context.startxcell { frame = "off" }
context()
context.stopxcell()
for i=1,n do
context.startxcell()
context.convertnumber(conversion,i)
context.stopxcell()
end
context.stopxrow()
for i=1,n do
context.startxrow()
context.startxcell()
context.convertnumber(conversion,i)
context.stopxcell()
for j=1,n do
context.startxcell { align = "middle" }
action(string.sub(pattern[i],j,j))
context.stopxcell()
end
context.stopxrow()
end
context.stopxtable()

end
\stopluacode

\startuniqueMPgraphic{cross}{width,height,depth,color,line}
draw image (
draw (\MPvar{depth},\MPvar{height}) -- (\MPvar{width},0) ;
draw (\MPvar{depth},0) -- (\MPvar{width},\MPvar{height}) ;
)
withpen pencircle scaled \MPvar{line}
withcolor \MPvar{color} ;
\stopuniqueMPgraphic

\definesymbol
  [MyRedCross]

[\uniqueMPgraphic{cross}{width=1em,height=1ex,depth=.5ex,color=red,line=.2ex}]

\definesymbol
  [MyGreenCross]

[\uniqueMPgraphic{cross}{width=1em,height=1ex,depth=.5ex,color=green,line=.2ex}]

\startluacode
document.MyTable {
action = function(value)
context(value == "X" and 1 or 0)
end,
conversion = "Characters",
pattern = {
".XXX..XX",
"X...XXX.",
"X..X.XXX",
"X.X.X..X",
".X.X.XX.",
".XX.X...",
"XXX.X...",
"X.XX"
}
}
\stopluacode

\startluacode
document.MyTable {
action = function(value)
context(value == "X" and 1 or 0)
end,
conversion = "Greek",
pattern = {
".XXX..XX",
"X...XXX.",
"X..X.XXX",
"X.X.X..X",
}
}
\stopluacode

\startluacode
document.MyTable {
action = function(value)
if value == "X" then
context.symbol { "MyRedCross" }
end
end,
conversion = "Romannumerals",
pattern = {
".XXX..XX",
"X...XXX.",
"X..X.XXX",
"X.X.X..X",
".X.X.XX.",
".XX.X...",
"XXX.X...",
"X.XX"
}
}
\stopluacode

\startluacode
document.MyTable {
action = function(value)
context.symbol { value == "X" and "MyRedCross"  or 
"MyGreenCross" }

end,
conversion = "Romannumerals",
pattern = {
"X.X.X..X",
".X.X.XX.",
".XX.X...",
"XXX.X...",
"X.XX"
}
}
\stopluacode

\stoptext


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
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 / 

Re: [NTG-context] Lua code and table

2021-02-17 Thread Bruce Horrocks


> On 17 Feb 2021, at 17:40, Fabrice Couvreur  
> 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
___


Re: [NTG-context] Lua code and table

2021-02-17 Thread Hans Hagen

On 2/17/2021 10:26 PM, Wolfgang Schuster wrote:

Fabrice Couvreur schrieb am 17.02.2021 um 18:40:

Hi,The code works, but is it possible to make it shorter ?
Thank you
Fabrice


\startuseMPgraphic{DiagonalRule}
    rulethickness := \frameddimension{rulethickness};

    drawoptions(
      withpen pencircle scaled rulethickness
      withcolor \MPcolor{\framedparameter{framecolor}});

    pair leftcorner, rightcorner, Leftcorner, Rightcorner;
    leftcorner  := (rulethickness, \overlayheight-rulethickness);
    rightcorner := (\overlaywidth-rulethickness, rulethickness);
    Leftcorner  := ( rulethickness, rulethickness);
    Rightcorner := 
(\overlaywidth-rulethickness,\overlayheight-rulethickness);


    draw leftcorner -- rightcorner;
    draw Leftcorner -- Rightcorner;
  \stopuseMPgraphic



\startuseMPgraphic{DiagonalRule}
     drawoptions(
     withpen pencircle scaled OverlayLineWidth
     withcolor OverlayLineColor
     );

     draw ulcorner OverlayBox -- lrcorner OverlayBox ;
     draw llcorner OverlayBox -- urcorner OverlayBox ;
\stopuseMPgraphic

Often this also works:

\startuseMPgraphic{DiagonalRule}
draw image (
draw ulcorner OverlayBox -- lrcorner OverlayBox ;
draw llcorner OverlayBox -- urcorner OverlayBox ;
)
withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor ;
\stopuseMPgraphic


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
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
___


Re: [NTG-context] Lua code and table

2021-02-17 Thread Wolfgang Schuster

Fabrice Couvreur schrieb am 17.02.2021 um 18:40:

Hi,The code works, but is it possible to make it shorter ?
Thank you
Fabrice


\startuseMPgraphic{DiagonalRule}
    rulethickness := \frameddimension{rulethickness};

    drawoptions(
      withpen pencircle scaled rulethickness
      withcolor \MPcolor{\framedparameter{framecolor}});

    pair leftcorner, rightcorner, Leftcorner, Rightcorner;
    leftcorner  := (rulethickness, \overlayheight-rulethickness);
    rightcorner := (\overlaywidth-rulethickness, rulethickness);
    Leftcorner  := ( rulethickness, rulethickness);
    Rightcorner := 
(\overlaywidth-rulethickness,\overlayheight-rulethickness);


    draw leftcorner -- rightcorner;
    draw Leftcorner -- Rightcorner;
  \stopuseMPgraphic



\startuseMPgraphic{DiagonalRule}
drawoptions(
withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor
);

draw ulcorner OverlayBox -- lrcorner OverlayBox ;
draw llcorner OverlayBox -- urcorner OverlayBox ;
\stopuseMPgraphic

Wolfgang
___
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
___


Re: [NTG-context] Lua code and table

2021-02-17 Thread Tomas Hala
Hi Fabrice,

see below, I attached two ideas how to do it.

The best,

Tomáš

Wed, Feb 17, 2021 ve 06:40:54PM +0100 Fabrice Couvreur napsal(a):
#Hi,  The code works, but is it possible to make it shorter ?
#Thank you
#Fabrice
#\startuseMPgraphic{DiagonalRule}
#   rulethickness := \frameddimension{rulethickness};
# 
#   drawoptions(
#     withpen pencircle scaled rulethickness
#     withcolor \MPcolor{\framedparameter{framecolor}});
# 
#   pair leftcorner, rightcorner, Leftcorner, Rightcorner;
#   leftcorner  := (rulethickness, \overlayheight-rulethickness);
#   rightcorner := (\overlaywidth-rulethickness, rulethickness);
#   Leftcorner  := ( rulethickness, rulethickness);
#   Rightcorner :=
#(\overlaywidth-rulethickness,\overlayheight-rulethickness);
# 
#   draw leftcorner -- rightcorner;
#   draw Leftcorner -- Rightcorner;
# \stopuseMPgraphic
# 
#\defineoverlay
#  [DiagonalRule]
#  [\useMPgraphic{DiagonalRule}]
# 
#\define[2]\DiagonalLabel{%
#  \setuptabulate [after={\blank[\frameddimension{offset}]}]
#  \starttabulate [|p|r|]
#    \NC    \NC \bf #2 \NC\NR
#    \NC \bf #1 \NC    \NC\NR
#  \stoptabulate
#}
#\starttext
#\startluacode
#  local background_one = {
#   align = "middle",
#   style = "type",
#   background = "DiagonalRule",
#  }
# 
#  local letters_1 = { "A", "B", "C", "D", "E", "F", "G", "H" }
#  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 _, letter in ipairs(letters_1) do
#  context.startxrow()
#    context.startxcell()
#    context(letter)
#    context.stopxcell()
#  for j = 0, 7 do
#  context.startxcell(  j == 0 and letter == "B" and background_one
#  or j == 0 and letter == "C" and background_one
#  or j == 0 and letter == "D" and background_one
#  or j == 0 and letter == "G" and background_one
#  or j == 0 and letter == "H" and background_one
#  or j == 1 and letter == "A" and background_one
#  or j == 1 and letter == "E" and background_one
#  or j == 1 and letter == "F" and background_one
#  or j == 1 and letter == "G" and background_one
#  or j == 2 and letter == "A" and background_one
#  or j == 2 and letter == "D" and background_one
#  or j == 2 and letter == "F" and background_one
#  or j == 2 and letter == "G" and background_one
#  or j == 2 and letter == "H" and background_one
#  or j == 3 and letter == "A" and background_one
#  or j == 3 and letter == "C" and background_one
#  or j == 3 and letter == "E" and background_one
#  or j == 3 and letter == "H" and background_one
#  or j == 4 and letter == "B" and background_one
#  or j == 4 and letter == "D" and background_one
#  or j == 4 and letter == "F" and background_one
#  or j == 4 and letter == "G" and background_one
#  or j == 5 and letter == "B" and background_one
#  or j == 5 and letter == "C" and background_one
#  or j == 5 and letter == "E" and background_one
#  or j == 6 and letter == "A" and background_one
#  or j == 6 and letter == "B" and background_one
#  or j == 6 and letter == "C" and background_one
#  or j == 6 and letter == "E" and background_one
#  or j == 7 and letter == "A" and background_one
#  or j == 7 and letter == "C" and background_one
#  or j == 7 and letter == "D" and background_one
#  )
#  context()
#  context.stopxcell()
#  end
#  context.stopxrow()
#  end
#  context.stopxtable()
#\stopluacode
#\stoptext

%%%=
\starttext
\startluacode

function test()
  for x=0,7 do 
for y=65,72 do 
  local yy=string.char(y)
  context(x)  
  context(" "..yy)
  context(f1(x,yy)..f2(x,yy)..f3(x,yy))
  context.par()
  end end
end

local background_one = true

function f1 (j,letter)
  local res=
   j == 0  and  letter == "B"  and  background_one  
or j == 0  and  letter == "C"  and  background_one 
or j == 0  and  letter == "D"  and  background_one 
or j == 0  and  letter == "G"  and  background_one 
or j == 0  and  letter == "H"  and  background_one 
or j == 1  and  letter == "A"  and  background_one 
or j == 1  and  letter == "E"  and  background_one 
or j == 1  and  letter == "F"  and  background_one 
or j == 1  and  letter == "G"  and  background_one 
or j == 2  and  letter == "A"  and  background_one 
or j == 2  and  letter == "D"  and  background_one 
or j == 2  and  letter == "F"  and  background_one 
or j == 2  and  letter == "G"  and  background_one 
or j == 2  and  letter == "H"  and  

[NTG-context] Lua code and table

2021-02-17 Thread Fabrice Couvreur
Hi, The code works, but is it possible to make it shorter ?
Thank you
Fabrice


\startuseMPgraphic{DiagonalRule}
   rulethickness := \frameddimension{rulethickness};

   drawoptions(
 withpen pencircle scaled rulethickness
 withcolor \MPcolor{\framedparameter{framecolor}});

   pair leftcorner, rightcorner, Leftcorner, Rightcorner;
   leftcorner  := (rulethickness, \overlayheight-rulethickness);
   rightcorner := (\overlaywidth-rulethickness, rulethickness);
   Leftcorner  := ( rulethickness, rulethickness);
   Rightcorner :=
(\overlaywidth-rulethickness,\overlayheight-rulethickness);

   draw leftcorner -- rightcorner;
   draw Leftcorner -- Rightcorner;
 \stopuseMPgraphic

\defineoverlay
  [DiagonalRule]
  [\useMPgraphic{DiagonalRule}]

\define[2]\DiagonalLabel{%
  \setuptabulate [after={\blank[\frameddimension{offset}]}]
  \starttabulate [|p|r|]
\NC\NC \bf #2 \NC\NR
\NC \bf #1 \NC\NC\NR
  \stoptabulate
}
\starttext
\startluacode
  local background_one = {
   align = "middle",
   style = "type",
   background = "DiagonalRule",
  }

  local letters_1 = { "A", "B", "C", "D", "E", "F", "G", "H" }
  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 _, letter in ipairs(letters_1) do
  context.startxrow()
context.startxcell()
context(letter)
context.stopxcell()
  for j = 0, 7 do
  context.startxcell(  j == 0 and letter == "B" and background_one
  or j == 0 and letter == "C" and background_one
  or j == 0 and letter == "D" and background_one
  or j == 0 and letter == "G" and background_one
  or j == 0 and letter == "H" and background_one
  or j == 1 and letter == "A" and background_one
  or j == 1 and letter == "E" and background_one
  or j == 1 and letter == "F" and background_one
  or j == 1 and letter == "G" and background_one
  or j == 2 and letter == "A" and background_one
  or j == 2 and letter == "D" and background_one
  or j == 2 and letter == "F" and background_one
  or j == 2 and letter == "G" and background_one
  or j == 2 and letter == "H" and background_one
  or j == 3 and letter == "A" and background_one
  or j == 3 and letter == "C" and background_one
  or j == 3 and letter == "E" and background_one
  or j == 3 and letter == "H" and background_one
  or j == 4 and letter == "B" and background_one
  or j == 4 and letter == "D" and background_one
  or j == 4 and letter == "F" and background_one
  or j == 4 and letter == "G" and background_one
  or j == 5 and letter == "B" and background_one
  or j == 5 and letter == "C" and background_one
  or j == 5 and letter == "E" and background_one
  or j == 6 and letter == "A" and background_one
  or j == 6 and letter == "B" and background_one
  or j == 6 and letter == "C" and background_one
  or j == 6 and letter == "E" and background_one
  or j == 7 and letter == "A" and background_one
  or j == 7 and letter == "C" and background_one
  or j == 7 and letter == "D" and background_one
  )
  context()
  context.stopxcell()
  end
  context.stopxrow()
  end
  context.stopxtable()
\stopluacode
\stoptext
___
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
___