On 8/29/2022 1:31 PM, Denis Maier via ntg-context wrote:
-----Ursprüngliche Nachricht-----
Von: Hans Hagen <j.ha...@freedom.nl>
Gesendet: Sonntag, 28. August 2022 10:41
An: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Maier, Denis Christian (UB) <denis.ma...@unibe.ch>
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,
%D version=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
|
with | WITH
two | TWO
stanzas | STANZAS
\stopbuffer
\ctxlua {
moduledata.poetry.sidebyside {
left = "lines-1",
right = "lines-2",
template = "|l|i2r|"
}
}
\ctxlua {
moduledata.poetry.sidebyside {
left = "lines-1b",
right = "lines-2",
template = "|l|i2r|"
}
}
\ctxlua {
moduledata.poetry.sidebyside {
left = "lines-3",
template = "|r|il|"
}
}
\poetrysidebyside
[left=lines-3,
template={|r|il|}]
\stoptext
___________________________________________________________________________________
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
___________________________________________________________________________________