wrong spacing around display with \matheqdirmode=1

This is the current test for deciding not to use shortskip ((d + line_s <= pre_display_size_par) || ((! dir_math_save && l) || (dir_math_save && ! l))) It has two problems: * if eqno_box is null then l (the leqno bool) is always false, so for short unnumbered equations the test is reduced to the value of dir_math_save which is based on \textdirection and \mathdirection, but in this case shortskip should always be used. * dir_math_save is correlated to \textdirection, but the shortskip detection should be based on the position of the equation number, and parfillskip, none of which \textdirection controls. I think \pardirection should be tested here. Here is a faulty example, where shortskip should be used but it is not \matheqdirmode=1\pardirection=1\textdirection=1 Test $$ Test $$ Test \bye In fact if I change \textdirection in this example shortskip is used, which kind of demonstrates the second point. For a better example of the second point you can test \matheqdirmode=1\textdirection=1 Test $$ Test\leqno(1) $$ Test \bye Whereas \textdirection and \mathdirection are opposites dir_math_save is true and leqno bool is false, hence short skp is used but the output clearly shows it should not be, as the equation number is right below the text. Note that I also tested with LuaTeX 1.18.0 to make sure this is not the fault of recent changes. I attached a patch. Udi

On 2/5/2025 9:57 PM, Udicoudco wrote:
This is the current test for deciding not to use shortskip
((d + line_s <= pre_display_size_par) || ((! dir_math_save && l) || (dir_math_save && ! l)))
It has two problems:
* if eqno_box is null then l (the leqno bool) is always false, so for short unnumbered equations the test is reduced to the value of dir_math_save which is based on \textdirection and \mathdirection, but in this case shortskip should always be used.
* dir_math_save is correlated to \textdirection, but the shortskip detection should be based on the position of the equation number, and parfillskip, none of which \textdirection controls. I think \pardirection should be tested here.
Here is a faulty example, where shortskip should be used but it is not
\matheqdirmode=1\pardirection=1\textdirection=1 Test $$ Test $$ Test \bye
In fact if I change \textdirection in this example shortskip is used, which kind of demonstrates the second point.
For a better example of the second point you can test
\matheqdirmode=1\textdirection=1 Test $$ Test\leqno(1) $$ Test \bye
Whereas \textdirection and \mathdirection are opposites dir_math_save is true and leqno bool is false, hence short skp is used but the output clearly shows it should not be, as the equation number is right below the text.
Note that I also tested with LuaTeX 1.18.0 to make sure this is not the fault of recent changes.
I attached a patch.
we (luatex team) are starting to worry about this kind of accumulated patching because it all interferes so one option is to delay these patches till after the 2025 code freeze one can make a point that if we have directions at all, short skips should never kick in and that one should handle it either in macros or in lua callbacks where one can fine tune for a specific situation these three-dir-var relates heuristics are messy 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 -----------------------------------------------------------------

On Thu, Feb 6, 2025 at 12:39 PM Hans Hagen
we (luatex team) are starting to worry about this kind of accumulated patching because it all interferes so one option is to delay these patches till after the 2025 code freeze
Sure, I don't mind if it will get in after the code freeze.
one can make a point that if we have directions at all, short skips should never kick in and that one should handle it either in macros or in lua callbacks where one can fine tune for a specific situation
Yes, isn't it why \matheqdirmode exists in the first place? I'm just wondering how useful is this mode primitive if using it results with unpredictable skips.
these three-dir-var relates heuristics are messy
Just for fun, I wondered how luametatex deals with it, as there are parfillrightskip and parfilleftskip to consider, which complicates things even more... Udi

On 2/6/2025 12:22 PM, Udicoudco wrote:
Just for fun, I wondered how luametatex deals with it, as there are parfillrightskip and parfilleftskip to consider, which complicates things even more...
indeed, when we remove the empty par we look at these two skips but also at an indent skip (when no indent hlist is used) so when it comes to display math, we can use the same checker but for the sake of experiments I made it configurable (dir node, parnode, indent hlist node, three glue variants) (controlled by a parameter that is a bitset) 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 -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Udicoudco