ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: Max Chernoff via ntg-context <ntg-context@ntg.nl>
Cc: Hans Hagen <j.hagen@freedom.nl>
Subject: Re: upload
Date: Fri, 8 Jul 2022 16:20:44 +0200	[thread overview]
Message-ID: <45b6c99e-37e9-40a6-9ce2-74718653187d@freedom.nl> (raw)
In-Reply-To: <9eb10804-56f0-5aaf-e603-101ce846297f@telus.net>

On 7/8/2022 9:40 AM, Max Chernoff via ntg-context wrote:
>> This is because you need to pass a list that conforms to what the 
>> builder expects and the callback that you use doesn't do that for you 
>> (after all, it also gets hbox content).
> 
> Isn't "processors/after" the same as "pre_linebreak_filter"? I thought 
> that only "hpack_filter" gets \hbox content? Anyways, my actual function 
> has this guard at the very start:
> 
>      if (head.id ~= par_id and context) or -- Ensure that we were 
> actually given a par
>          status.output_active or -- Don't run during the output routine
>          tex.nest.ptr > 1 -- Don't run inside boxes
>      then
>          return head
>      end
> 
> so I think that I'm only processing actual top-level paragraphs here.
> 
>> There is no 'callback sequence handler' for the par builder (currently 
>> i see no need for it, also given the extra overhead involved) but this 
>> what what you can do:
>>
>> \startluacode
>>      function builders.paragraphs.constructors.methods.preroll_a(head)
>>          local result, info = tex.linebreak(head)
>>          tex.prevdepth = info.prevdepth
>>          tex.prevgraf = info.prevgraf
>>          return result
>>      end
>>      function builders.paragraphs.constructors.methods.preroll_b(head)
>>          local result, info = tex.linebreak(nodes.nuts.copylist(head))
>>          inspect(info)
>>          return true
>>      end
>> \stopluacode
>>
>> \defineparbuilder[preroll_a]
>> \defineparbuilder[preroll_b]
>>
>> \starttext
>>      \setmainparbuilder[default]   \input tufte \par \input tufte \page
>>      \setmainparbuilder[preroll_a] \input tufte \par \input tufte \page
>>      \setmainparbuilder[preroll_b] \input tufte \par \input tufte \page
>> \stoptext
> 
> I think that that code is for replacing the linebreaker entirely, like 
> with using "linebreak_filter"? My goal isn't to replace the linebreaker; 
> I just want to be able to inspect the paragraph before it is broken, 
> without modifying anything.

as long as you return true the built in will do the work but you can 
still do the preroll so basically nothing gets replaced .. it's just a 
more natural hook;l keep in mind that if someone replaces the linebreak 
your code woudl fail to do its work anyway

> What I'm trying to do *very* roughly looks like the following:
> 
>      paragraphs = {}
>      attribute = 1234
> 
>      function pre_linebreak_filter(head)
>          if head.id ~= node.id"par" then
>              return head
>          end
> 
>          local nat_node, nat_info = tex.linebreak(node.copylist(head))
>          node.freelist(nat_node)
> 
>          local long_node, long_info = tex.linebreak(
>              node.copylist(head), {looseness = 1}
>          )
> 
>          if long_info.prevgraf == nat_info.prevgraf + 1 then
>              table.insert(paragraphs, long_node)
>          end
> 
>          return head
>      end
> 
>      function post_linebreak_filter(head)
>          node.setattribute(head, attribute, #paragraphs)
>          node.setattribute(node.slide(head), attribute, #paragraphs)
> 
>          return head
>      end
> 
>      function pre_output_filter(head)
>          if tex.outputpenalty ~= tex.widowpenalty then
>              return head
>          end
> 
>          -- Pick a paragraph from `paragraphs` somehow
> 
>          -- Replace that paragraph on the page with the one
>          -- from `paragraphs`
> 
>          -- Move the last line of the page onto the top of
>          -- tex.lists.contributehead
> 
>          return head
>      end
> 
> (The full implementation is in the module "lua-widow-control" on CTAN, 
> TeX Live, and modules.contextgarden.net, or directly at 
> "https://github.com/gucci-on-fleek/lua-widow-control/blob/master/source/lua-widow-control.lua". 
> It's pretty long though, so I'm just trying to summarize here.)
> 
> This works pretty well with Plain LuaTeX, LuaLaTeX, OpTeX, MkIV, and 
> MkXL before the latest upload, but something broke with the latest 
> upload in MkXL. I understand that I'm mucking around with volatile 
> interfaces, and I have no problem making a bunch of changes whenever the 
> engine/format changes; the problem is that I'm not too sure what changed 
> in the engine, so I don't know what I need to change in my code.

the tricky part is probably to make sure that it doesn't interfere with 
what other functions hooked into the callbacks are doing because who 
knows what gets injected in those lists

>> On the to do is a to add a 'prepare' helper that adds the mandate 
>> nodes (par fillers etc) 
> 
> Maybe that's all that I need? If that's the case, I have no problem 
> coding my own "prepare helper" if you think that it'll be awhile before 
> you get around to it; the problem is that I'm not entirely sure what 
> nodes I would need to add. These new nodes aren't added until after 
> "pre_linebreak_filter", and they're gone after the linebreaker runs, so 
> I can't inspect a "regular" paragraph to see where these nodes belong.

there will be (untested on what you do)

   tex.preparelinebreak(par)

that will add the additional stuff needed (and bark if something is 
there already).

btw, a par builder - even in luatex - needs a parfillskip to properly do 
its work, some penalty and in the case of context lmtx also a 
leftparfill skip and optionally initleft and right skip
  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
___________________________________________________________________________________

  reply	other threads:[~2022-07-08 14:20 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06 20:10 upload Hans Hagen via ntg-context
2022-07-06 20:38 ` upload Mikael Sundqvist via ntg-context
2022-07-07  1:15 ` upload Max Chernoff via ntg-context
2022-07-07  8:27   ` upload Hans Hagen via ntg-context
2022-07-08  7:40     ` upload Max Chernoff via ntg-context
2022-07-08 14:20       ` Hans Hagen via ntg-context [this message]
2022-07-07 20:48 ` upload Aditya Mahajan via ntg-context
2022-07-07 21:16   ` upload Hans Hagen via ntg-context
2022-07-08 22:34 ` upload Otared Kavian via ntg-context
2022-07-08 22:40   ` upload Otared Kavian via ntg-context
2022-07-09  7:39     ` upload Hans Hagen via ntg-context
2022-07-09  6:40   ` upload Hans Hagen via ntg-context
  -- strict thread matches above, loose matches on Subject: below --
2023-04-11 21:02 upload Hans Hagen via ntg-context
2022-12-21 16:20 upload Hans Hagen via ntg-context
2022-12-21 21:15 ` upload Pablo Rodriguez via ntg-context
2022-12-09 16:41 upload Hans Hagen via ntg-context
2022-10-21 19:23 upload Hans Hagen via ntg-context
2022-05-09 15:41 upload Hans Hagen via ntg-context
2022-05-09 15:54 ` upload mf via ntg-context
2022-05-09 16:16   ` upload Hans Hagen via ntg-context
2022-05-09 16:39     ` upload Alexandre Christe via ntg-context
2022-05-09 16:16   ` upload Alexandre Christe via ntg-context
2022-05-09 16:36     ` upload Mikael Sundqvist via ntg-context
2022-05-10  5:10       ` upload śrīrāma via ntg-context
2022-05-11 12:48   ` upload śrīrāma via ntg-context
2022-05-11 15:46 ` upload Zhichu Chen via ntg-context
2022-05-11 17:00   ` upload Hans Hagen via ntg-context
2022-03-25 10:01 upload Hans Hagen via ntg-context
2022-03-28 21:22 ` upload Otared Kavian via ntg-context
2022-03-28 21:54   ` upload Mikael Sundqvist via ntg-context
2022-03-29  4:37     ` upload Otared Kavian via ntg-context
2022-03-29 14:10       ` upload Mikael Sundqvist via ntg-context
2022-03-29 16:08         ` upload Aditya Mahajan via ntg-context
2022-03-30 10:02           ` upload Otared Kavian via ntg-context
2021-12-30 18:14 upload Hans Hagen via ntg-context
     [not found] <mailman.320.1640390435.1172.ntg-context@ntg.nl>
2021-12-25  9:09 ` upload Jeong Dal via ntg-context
2021-12-25 10:57   ` upload Hans Hagen via ntg-context
2021-12-24 18:45 upload Hans Hagen via ntg-context
2021-12-24 22:08 ` upload Jairo A. del Rio via ntg-context
2021-12-24 23:39   ` upload Rik Kabel via ntg-context
2021-12-24 23:54   ` upload Hans Hagen via ntg-context
2021-12-25  9:19 ` upload Marco Patzer via ntg-context
2021-12-25 10:55   ` upload Hans Hagen via ntg-context
2021-12-25 11:22     ` upload Marco Patzer via ntg-context
2021-12-25 11:44       ` upload Hans Hagen via ntg-context
2021-12-25 12:18         ` upload Marco Patzer via ntg-context
2021-12-03 14:29 upload Hans Hagen via ntg-context
2021-12-06  4:41 ` upload Jairo A. del Rio via ntg-context
2021-11-24 14:29 upload Hans Hagen via ntg-context
2021-11-26 10:06 ` upload Alain Delmotte via ntg-context
2021-11-26 10:44   ` upload Hans Hagen via ntg-context
2021-10-21 18:04 upload Hans Hagen via ntg-context
2021-10-21 19:13 ` upload Pablo Rodriguez via ntg-context
2021-10-22  7:55   ` upload Hans Hagen via ntg-context
2021-10-21 20:31 ` upload Mikael Sundqvist via ntg-context
2021-10-22  7:22   ` upload Hans Hagen via ntg-context
2021-10-23  8:10     ` upload Mikael Sundqvist via ntg-context
2021-10-22 15:50 ` upload Michal Vlasák via ntg-context
2021-10-22 16:51   ` upload Pablo Rodriguez via ntg-context
2021-10-23  0:40   ` upload Hans Hagen via ntg-context
2021-10-18 21:17 upload Hans Hagen via ntg-context
2021-10-19  6:43 ` upload Axel Kielhorn via ntg-context
2021-10-20  7:29   ` upload Hans Hagen via ntg-context
2021-10-19 16:03 ` upload Pablo Rodriguez via ntg-context
2020-11-23 17:55 upload Hans Hagen
2020-11-23 18:28 ` upload Pablo Rodriguez
2020-11-23 18:29 ` upload Christian Prim
2020-11-23 19:21   ` upload Otared Kavian
2020-11-23 19:27     ` upload Hans Hagen
2020-11-23 19:24   ` upload Hans Hagen
2020-11-17 11:55 upload Hans Hagen
2020-11-17 13:57 ` upload Pablo Rodriguez
2020-11-17 14:15   ` upload Hans Hagen
2020-11-18 20:29     ` upload Pablo Rodriguez
2020-11-18 22:57       ` upload Hans Hagen
2020-11-17 15:26 ` upload Willi Egger
2020-07-27 14:42 upload Hans Hagen
2020-07-28  8:58 ` upload Fabrice Couvreur
2020-07-28 11:28   ` upload Hans Hagen
2020-02-11 16:00 upload Hans Hagen
2020-02-11 16:18 ` upload Floris van Manen
2020-02-11 19:07   ` upload Hans Hagen
2020-02-11 21:09     ` upload Richard Mahoney | Indica et Buddhica
2020-02-13 10:28 ` upload mf
2020-02-13 12:57   ` upload Hans Hagen
2020-02-17  9:39     ` upload mf
2013-03-05 18:18 upload Hans Hagen
2013-03-05 19:45 ` upload Thomas A. Schmitz
2012-07-04  8:56 upload Hans Hagen
2012-07-04 10:40 ` upload Hongwen Qiu
2012-07-04 11:29   ` upload Hans Hagen
2012-07-04 16:02 ` upload Philipp Gesang
2012-06-22  9:37 upload Hans Hagen
2012-06-22 10:10 ` upload Marco
2012-06-22 11:24   ` upload Hans Hagen
2012-06-22 12:19     ` upload Marco
2012-06-19 20:40 upload Hans Hagen
2012-06-20  3:28 ` upload Hongwen Qiu
2012-06-20 14:20   ` upload Hans Hagen
2006-04-07  8:22 upload Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45b6c99e-37e9-40a6-9ce2-74718653187d@freedom.nl \
    --to=ntg-context@ntg.nl \
    --cc=j.hagen@freedom.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).