michal-h21 / linebreaker

Some excersises with luatex's line breaking callback
15 stars 1 forks source link

ensure compatibility with lua widow control package #3

Closed hpvd closed 2 years ago

hpvd commented 2 years ago

Since linebreaker and lua widow control package both work on optimizing typesetting results in fully automated fashion, it would be great if one could take care to keep them compatible/playing well with each other.

michal-h21 commented 2 years ago

I don't know much about this package, but from what I saw in the source code, one possible issue is that both of these packages sets the hpack_quality callback. Linebreaker uses it to record badness, but lua-widow-control adds empty callback, which removes the overfull box warning.

I've tried to use \usepackage{lua-widow-control} in the documentation both before, and after \usepackage{linebreaker}, and seems that it doesn't have a negative impact on Linebreaker. I don't know about the impact on the widow control, as I don't have an example for testing.

hpvd commented 2 years ago

many thanks for having a first look on this! Maybe @gucci-on-fleek could also look in this.

this is the corresponding issue at lua-widow-control package: https://github.com/gucci-on-fleek/lua-widow-control/issues/18

gucci-on-fleek commented 2 years ago

Yeah, I think that it should be fine. The only callbacks that lua-widow-control and linebreaker share are hpack_quality and post_linebreak_filter. Lua-widow-control only activates the hpack_quality callback while processing the pre_linebreak_filter filter, so there shouldn't be any interference there. linebreaker and lua-widow-control both register the post_linebreak_filter, but neither package does anything "interesting" there, so luatexbase should handle that just fine, regardless of the package load order.

I've done some quick tests and the packages seem to work together fine. It is quite tricky to test them together since lua-widow-control fails pretty badly with really narrow \hsizes and linebreaker works the best with narrow \hsizes.

Once linebreaker is added to TeX Live (probably about ~1 week), I'll make sure to add it to lua-widow-control's automated tests.

gucci-on-fleek commented 2 years ago

Ok, so it looks like lua-widow-control + linebreaker failed pretty bad when in an align environment:

warning  (node filter): error: .../texlive/2021/texmf-dist/tex/latex-dev/base/l
tluatex.lua:110: 
Module luatexbase Error: Cannot add second callback to exclusive function
(luatexbase)             `hpack_quality' on input line 66

.
\start@align ...urrenvir }{}\@gobble }\fi \else $$
                                                  \let \split \insplit@ \DN@...

l.66     \begin{align*}

gucci-on-fleek/lua-widow-control@c4e96ee fixes this by making making sure that lua-widow-control only registers the callback if no one else has. I don't think that there should be any other issues, but let me know if I break anything else.

michal-h21 commented 2 years ago

Ah, good catch. I expect that there will be lots of issues with Linebreaker when users try it on real-world documents, as I tested it mostly on text-only documents.

hpvd commented 2 years ago

both packages seem to work flawlessly together -> this issue could be closed

michal-h21 commented 2 years ago

Yeah, you are right. Thanks for the reminder.