[NTG-context] How to obtain the hbox's node when there is only one hbox for an entire paragraph?

2024-05-01 Thread 黄复雄
Dear list,

What is the non-hacking way to obtain the hbox's node in a Lua hook
when there is only one hbox for an entire paragraph?

Best regards,
Huang Fusyong (黄复雄)

% start ConTeXt

\startluacode
Moduledata = Moduledata or {}
Moduledata.jiazhu = Moduledata.jiazhu or {}

---[[
local function show_detail(n, label)
local l = label or "==="
print(">"..l.."<<")
print(nodes.toutf(n))
for i in node.traverse(n) do
local char
if i.id == nodes.nodecodes.glyph then
char = utf8.char(i.char)
print(i, char)
elseif i.id == nodes.nodecodes.penalty then
print(i, i.penalty)
elseif i.id == nodes.nodecodes.glue then
print(i, i.width, i.stretch, i.shrink, i.stretchorder,
i.shrinkorder)
elseif i.id == nodes.nodecodes.hlist then
print(i,
nodes.toutf(i.list),i.width,i.height,i.depth,i.shift,i.glue_set,i.glue_sign,i.glue_order)
elseif i.id == nodes.nodecodes.kern then
print(i, i.kern, i.expension)
else
print(i)
end
end
end
--]]

function Moduledata.jiazhu.main(head)
show_detail(head,"head")
return head, true
end

nodes.tasks.appendaction("processors", "after", "Moduledata.jiazhu.main")

\stopluacode
\starttext

\hbox{a b c}
% The result is as follows (without the  I expected):
% >head<<
% a b c
%3448 : glyph unset>   a
%3702 : glue spaceskip>261738
130869  87246   0   0
%3484 : glyph unset>   b
%3716 : glue spaceskip>261738
130869  87246   0   0
% nil : glyph unset>   c

~\hbox{a b c}
% Hacking with the `~`, the result is as follows (containing the
 I expected):
% >head<<
% a b c
%3377 : glyph unset>   a
%3733 : glue spaceskip>261738
130869  87246   0   0
%3491 : glyph unset>   b
%3747 : glue spaceskip>261738
130869  87246   0   0
% nil : glyph unset>   c
% >head<<
% a b c
%3484 : par vmodepar>
%2208 : glue indentskip>   0   0
   0   0   0
%3498 : penalty userpenalty>   1
%3325 : glue spaceskip>261738
130869  87246   0   0
%3441 : hlist box> a b c   1702476
545484  86460   nil nil nil
   nil : glue spaceskip>261738  130869  87246   0   0

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

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Re: \par and \startlines

2024-05-01 Thread Henning Hraban Ramm

Am 01.05.24 um 09:44 schrieb Wolfgang Schuster:
but that should be sufficient, but to repeat Hraban's question: What 
would be the advantage of using the format module?


The module provides features like

     - alignment of the verse lines
     - numbering of the lines (which isn't supported by \startlines 
unless you add the normal linenumbering mechanism)
     - support for lines which don't fit on a single page where the 
consecutive lines are indented


but the module is outdated and relies on an old mkii style code base.

A big difference between the \startlines environment and the format 
module is that the first treats
each line in the input file as a separate line in the output while the 
format module requires begin/end

tags for each line which works better for xml input.


Thank you! Doesn’t sound like I should use it…

Hraban

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

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Re: \par and \startlines

2024-05-01 Thread Wolfgang Schuster

denisma...@mailbox.org schrieb am 30.04.2024 um 14:28:

-Ursprüngliche Nachricht-
Von: Wolfgang Schuster 
Gesendet: Samstag, 27. April 2024 07:40
An: Denis Maier 
Cc: mailing list for ConTeXt users 
Betreff: Re: [NTG-context] Re: \par and \startlines

Denis Maier schrieb am 26.04.2024 um 19:52:


I see. But there's no command that could be used to simulate an empty line?
If not, me should I perhaps try to replicate the wrapper structure
from the XML source in context? (I'll also look into the format module
of
course.) What do you think?

Below is a different solution to your problem with works without \startlines
because you already mark up each individual line in the poem which make it
possible to add a linebreak in the output.

With \blank options (samepage) you can avoid pagebreaks between stanzas.

\startxmlsetups xml:test
  \xmlsetsetup{#1}{*}{-}
  \xmlsetsetup{#1}{doc|poem|stanza|line}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:test}

\startxmlsetups xml:doc
  \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:poem
  \blank[line]
  \xmlflush{#1}
  \blank[back,line]
\stopxmlsetups

\startxmlsetups xml:stanza
 \xmlflush{#1}\blank[preference,line]
\stopxmlsetups

\startxmlsetups xml:line
  \xmlflush{#1}\blank[samepage,none]
\stopxmlsetups

\startbuffer[test]




The
lines
are
there!


The
lines
are
there!


The
lines
are
there!



\stopbuffer

\starttext

\samplefile{lorem}

\xmlprocessbuffer{test}{test}{}

\samplefile{lorem}

\stoptext

Thanks for this solution. I've had a quick look, and it seems to do exactly 
what I need. My requirements are rather simple at the moment, but that should 
be sufficient, but to repeat Hraban's question: What would be the advantage of 
using the format module?


The module provides features like

    - alignment of the verse lines
    - numbering of the lines (which isn't supported by \startlines 
unless you add the normal linenumbering mechanism)
    - support for lines which don't fit on a single page where the 
consecutive lines are indented


but the module is outdated and relies on an old mkii style code base.

A big difference between the \startlines environment and the format 
module is that the first treats
each line in the input file as a separate line in the output while the 
format module requires begin/end

tags for each line which works better for xml input.

Wolfgang

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

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___