Re: [NTG-context] Merging two lua tables

2022-08-29 Thread Aditya Mahajan via ntg-context
On Mon, 29 Aug 2022, Hans Hagen via ntg-context wrote:

> On 8/29/2022 2:20 PM, Aditya Mahajan via ntg-context wrote:
> > Hi,
> > 
> > How do I merge two lua tables? I believe that table.merge or table.merged
> should do the trick, but I cannot figure out how to use them.
> > 
> > ```
> > local t1 = { 1, 2 }
> > local t2 = { 8, 9 }
> > 
> > local m1 = {}
> > table.merge(m1,t1, t2)
> > table.print(m1)
> > 
> > local m2 = table.merged(t1, t2)
> > table.print(m2)
> > ```
> > 
> > Processing the file with context filename shows that both m1 and m2 are {8,
> 9}. What am I missing.
> table.imerge(m1,t1, t2)

Ah, thanks!

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

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


Re: [NTG-context] Typearea module fails with “Missing number”

2022-08-29 Thread Wolfgang Schuster via ntg-context

Marco Patzer via ntg-context schrieb am 29.08.2022 um 09:49:

On Mon, 29 Aug 2022 09:30:34 +0200
Marco Patzer via ntg-context  wrote:


The typearea module fails on LMTX (runs ok with MkIV):

   tex error   > tex error on line 89 in file
/usr/local/share/context-lmtx/tex/texmf-modules/tex/context/third/typearea/t-typearea.tex:
Missing number, treated as zero

Sorry, forgot the MWE:

   \usemodule[typearea]
   \starttext\null\stoptext


To fix the module you have to change the line

\edef\Ratio{\withoutpt{\the\dimexpr2\paperheight/(\PageWidth/32768)\relax}}

with (remove one pair of curly braces)

\edef\Ratio{\withoutpt\the\dimexpr2\paperheight/(\PageWidth/32768)\relax}


Similar problems can happens with other modules because many of them are 
outdated
and they should be either updated or removed (the files can still be 
archived).


Wolfgang

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

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


Re: [NTG-context] Merging two lua tables

2022-08-29 Thread Hans Hagen via ntg-context

On 8/29/2022 7:33 PM, BPJ via ntg-context wrote:

Hi,

I use the attached Lua function to merge array, map and mixed tables alike
(but differently! :-) The trick is to check if each key is numeric or not,
append if it is and overwrite if it isn't.


you really want something like this then:

local  tab = table.pack(...)
local  rv  = {}


This function just ignores non-table arguments because that is what I
usually want. You may want to throw an error instead. Also it uses
table.pack. You might need to use `tab = {...}` and ipairs, or implement
pack:
I might add table.himerged (hash and index) but slightly different (and 
some 30% faster) to util-tab but i think merging mixed hash/indexed 
tables is rare.


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 / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


Re: [NTG-context] Merging two lua tables

2022-08-29 Thread BPJ via ntg-context
Hi,

I use the attached Lua function to merge array, map and mixed tables alike
(but differently! :-) The trick is to check if each key is numeric or not,
append if it is and overwrite if it isn't.

This function just ignores non-table arguments because that is what I
usually want. You may want to throw an error instead. Also it uses
table.pack. You might need to use `tab = {...}` and ipairs, or implement
pack:

``lua
local function pack (...)
  return { n = select('#', ...), ... }
end
``


Den mån 29 aug. 2022 14:32Aditya Mahajan via ntg-context 
skrev:

> On Mon, 29 Aug 2022, Aditya Mahajan via ntg-context wrote:
>
> > Hi,
> >
> > How do I merge two lua tables? I believe that table.merge or
> table.merged should do the trick, but I cannot figure out how to use them.
> >
> > ```
> > local t1 = { 1, 2 }
> > local t2 = { 8, 9 }
> >
> > local m1 = {}
> > table.merge(m1,t1, t2)
> > table.print(m1)
> >
> > local m2 = table.merged(t1, t2)
> > table.print(m2)
> > ```
> >
> > Processing the file with context filename shows that both m1 and m2 are
> {8, 9}. What am I missing.
>
> Looking at the code, I see what is happening. table.merge(d) assume that
> the tables are key-value tables so the keys of the first table are silently
> overwritten by the send. I guess, I'll have to write my own function to
> merge "array" tables.
>
> Aditya
>
> ___
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> https://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki : https://contextgarden.net
>
> ___
>


table-merge.lua
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 / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


[NTG-context] SHA added to wiki

2022-08-29 Thread Pablo Rodriguez via ntg-context
Dear list,

I added https://contextgarden.net/SHA.

I know that my composition is minimal and maybe the sample is poor.

Just in case anyone might want to improve it.

Best,

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

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


Re: [NTG-context] Merging two lua tables

2022-08-29 Thread Hans Hagen via ntg-context

On 8/29/2022 2:20 PM, Aditya Mahajan via ntg-context wrote:

Hi,

How do I merge two lua tables? I believe that table.merge or table.merged 
should do the trick, but I cannot figure out how to use them.

```
local t1 = { 1, 2 }
local t2 = { 8, 9 }

local m1 = {}
table.merge(m1,t1, t2)
table.print(m1)

local m2 = table.merged(t1, t2)
table.print(m2)
```

Processing the file with context filename shows that both m1 and m2 are {8, 9}. 
What am I missing.

table.imerge(m1,t1, t2)

-
  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 / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


Re: [NTG-context] Merging two lua tables

2022-08-29 Thread Aditya Mahajan via ntg-context
On Mon, 29 Aug 2022, Aditya Mahajan via ntg-context wrote:

> Hi,
> 
> How do I merge two lua tables? I believe that table.merge or table.merged 
> should do the trick, but I cannot figure out how to use them. 
> 
> ``` 
> local t1 = { 1, 2 }
> local t2 = { 8, 9 }
> 
> local m1 = {}
> table.merge(m1,t1, t2)
> table.print(m1)
> 
> local m2 = table.merged(t1, t2)
> table.print(m2)
> ```
> 
> Processing the file with context filename shows that both m1 and m2 are {8, 
> 9}. What am I missing. 

Looking at the code, I see what is happening. table.merge(d) assume that the 
tables are key-value tables so the keys of the first table are silently 
overwritten by the send. I guess, I'll have to write my own function to merge 
"array" tables. 

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

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


[NTG-context] Merging two lua tables

2022-08-29 Thread Aditya Mahajan via ntg-context
Hi,

How do I merge two lua tables? I believe that table.merge or table.merged 
should do the trick, but I cannot figure out how to use them. 

``` 
local t1 = { 1, 2 }
local t2 = { 8, 9 }

local m1 = {}
table.merge(m1,t1, t2)
table.print(m1)

local m2 = table.merged(t1, t2)
table.print(m2)
```

Processing the file with context filename shows that both m1 and m2 are {8, 9}. 
What am I missing. 

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

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


Re: [NTG-context] Parallel texts: verse with blanks between stanzas via tabulate

2022-08-29 Thread Hans Hagen via ntg-context

On 8/29/2022 1:31 PM, Denis Maier via ntg-context wrote:

-Ursprüngliche Nachricht-
Von: Hans Hagen 
Gesendet: Sonntag, 28. August 2022 10:41
An: mailing list for ConTeXt users 
Cc: Maier, Denis Christian (UB) 
Betreff: Re: [NTG-context] Parallel texts: verse with blanks between stanzas
via tabulate

On 8/27/2022 11:25 PM, Denis Maier via ntg-context wrote:

Thanks, Wolfgang. That gives me a blank between the verses. However the

blank is rather huge and I don't see how I could make it smaller? Is it possible
to do this?
morning exercise attached (you can run the file)

Hans


Another, more general question on this: why is the function poetry.sidebyside 
defined twice? If I understand correctly, depending on the input one or the 
other will be used, but I don't see where that happens...

the first can be commented as it is the first simple variant

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
-%D \module
%D   [   file=m-poetry,
%Dversion=2022.08.28
%D  title=\CONTEXT\ Extra Modules,
%D   subtitle=Whatever comes up,
%D author=Hans Hagen,
%D   date=\currentdate,
%D  copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% For Denis Maier (see mails to list end of August 2022)

\startluacode

local  poetry = moduledata.poetry or { }
moduledata.poetry = poetry

-- function poetry.sidebyside(specification)
-- local first   = string.splitlines(buffers.getcontent(specification.left))
-- local second  = 
string.splitlines(buffers.getcontent(specification.right))
-- local template = specification.template or "|||"
-- context.starttabulate { template }
-- for i=1,#first do
-- local f = first [i] or ""
-- local s = second[i] or ""
-- if f == "" and s == "" then
-- context.TB { "medium" }
-- else
-- context.NC() context(f)
-- context.NC() context(s)
-- context.NC() context.NR()
-- end
-- end
-- context.stoptabulate()
-- end

function poetry.sidebyside(specification)
local left= specification.left
local right   = specification.right
local first   = left  and string.splitlines(buffers.getcontent(left )) or { 
}
local second  = right and string.splitlines(buffers.getcontent(right)) or { 
}

if #first > 0 and #second == 0 then
for i=1,#first do
local t = string.split(first[i], "|")
first[i]  = string.strip(t[1] or "")
second[i] = string.strip(t[2] or "")
end
end

local template = specification.template or "|||"

context.starttabulate { template }
local fi = 1
local si = 1
local n  = #first > #second and #first or #second

local function flush(f,s)
context.NC() context(f)
context.NC() context(s)
context.NC() context.NR()
if f ~= "" then
fi = fi + 1
end
if s ~= "" then
si = si + 1
end
end

while fi <= n and si <= n do
local f = first [fi] or ""
local s = second[si] or ""
if f ~= "" and s ~= "" then
flush(f,s)
else
while true do
if f ~= "" or s ~= "" then
flush(f,s)
else
while f == "" do
fi = fi + 1
f = first [fi] or ""
end
while s == "" do
si = si + 1
s = second[si] or ""
end
break
end
f = first [fi] or ""
s = second[si] or ""
end
 -- context.HL()
context.TB { "medium" }
end
end
context.stoptabulate()
end

interfaces.implement {
name  = "poetrysidebyside",
protected = true,
public= true,
actions   = poetry.sidebyside,
arguments = "hash",
}

\stopluacode

\continueifinputfile{m-poetry.mkxl}

\starttext

\starttext

\startbuffer[lines-1]
THIS
IS
A
POEM

WITH
TWO
STANZAS
\stopbuffer

\startbuffer[lines-1b]
THIS
IS
A
LONGER
POEM

WITH
TWO
STANZAS
\stopbuffer

\startbuffer[lines-2]
this
is
a
poem

with
two
stanzas
\stopbuffer

\startbuffer[lines-3]
this | THIS
is   | IS
a| A
poem | POEM
  

Re: [NTG-context] Parallel texts: verse with blanks between stanzas via tabulate

2022-08-29 Thread Denis Maier via ntg-context
> -Ursprüngliche Nachricht-
> Von: Hans Hagen 
> Gesendet: Sonntag, 28. August 2022 10:41
> An: mailing list for ConTeXt users 
> Cc: Maier, Denis Christian (UB) 
> Betreff: Re: [NTG-context] Parallel texts: verse with blanks between stanzas
> via tabulate
> 
> On 8/27/2022 11:25 PM, Denis Maier via ntg-context wrote:
> > Thanks, Wolfgang. That gives me a blank between the verses. However the
> blank is rather huge and I don't see how I could make it smaller? Is it 
> possible
> to do this?
> morning exercise attached (you can run the file)
> 
> Hans

Another, more general question on this: why is the function poetry.sidebyside 
defined twice? If I understand correctly, depending on the input one or the 
other will be used, but I don't see where that happens...

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

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


Re: [NTG-context] Parallel texts: verse with blanks between stanzas via tabulate

2022-08-29 Thread Denis Maier via ntg-context
Thanks Hans, that's very nice indeed. Looks like I really need to dive into 
CLD. There seem to be so many possibilies...

However, the major pitfall seems to be that this assumes stanzas of equal 
length (as it relies on \TB to produce the blanks), which does not apply to my 
situation. (Modfied version attached.)
Do you see any way to support this kind of situation?

Best,
Denis



> -Ursprüngliche Nachricht-
> Von: Hans Hagen 
> Gesendet: Sonntag, 28. August 2022 10:41
> An: mailing list for ConTeXt users 
> Cc: Maier, Denis Christian (UB) 
> Betreff: Re: [NTG-context] Parallel texts: verse with blanks between stanzas
> via tabulate
> 
> On 8/27/2022 11:25 PM, Denis Maier via ntg-context wrote:
> > Thanks, Wolfgang. That gives me a blank between the verses. However the
> blank is rather huge and I don't see how I could make it smaller? Is it 
> possible
> to do this?
> morning exercise attached (you can run the file)
> 
> 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
> -


m-poetry.mkxl
Description: m-poetry.mkxl
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


Re: [NTG-context] Typearea module fails with “Missing number”

2022-08-29 Thread Marco Patzer via ntg-context
On Mon, 29 Aug 2022 09:30:34 +0200
Marco Patzer via ntg-context  wrote:

> The typearea module fails on LMTX (runs ok with MkIV):
> 
>   tex error   > tex error on line 89 in file
> /usr/local/share/context-lmtx/tex/texmf-modules/tex/context/third/typearea/t-typearea.tex:
> Missing number, treated as zero

Sorry, forgot the MWE:

  \usemodule[typearea]
  \starttext\null\stoptext

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

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


[NTG-context] Typearea module fails with “Missing number”

2022-08-29 Thread Marco Patzer via ntg-context
Hi!

The typearea module fails on LMTX (runs ok with MkIV):

  tex error   > tex error on line 89 in file 
/usr/local/share/context-lmtx/tex/texmf-modules/tex/context/third/typearea/t-typearea.tex:
 Missing number, treated as zero

LMTX 2022.08.25 19:21

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

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