Closed dbitouze closed 3 years ago
\MT_cramped_internal:Nn was indeed updated in the latest release. IMO this should be a bug in lualatex-math
.
See issue #18 and issue #19
@daleif I think we discussed once in the chat if mathtools should take over the lualatex-math patches.
@u-fischer I don't think I've heard any talk about mathtools and lualatex. That would also mean porting mathtools to real expl3 (it is not really written in expl3) Had a look at that patch and I don't even understand what it does and why.
@daleif we had a discussion around here: https://chat.stackexchange.com/transcript/message/55641430#55641430 (it is only for the case that unicode-math is used, not for traditional fonts).
Ahh, that one, forgot about that one.
Why is it \ensuremath is needed?
I never use unicode-math and never test against it
@daleif I don't know why ensuremath is used. I even don't know if the patch is good or not, but imho it is either good then it should move into mathtools, or it is bad then it should be removed from lualatex-math. Having many years such patches in external packages is not good.
The changes to crampedsubarray also gives problems. I have no idea what lualatex needs or does not need.
Ahh, right, lualatex has its own cramped primitives, and we cannot expect them to give the same cramped-ness we get in pdflatex.
Hmm, so why is
\ensuremath {
\use:c { cramped \cs_to_str:N #1 } #2
}
no longer enough in lualatex-math.sty
. I keep getting an error about a missing {
when I get with the example from https://github.com/latex3/mathtools/issues/17, presumably because we made this change
%%$\m@th\scriptstyle\kern-\nulldelimiterspace\radical\z@{##}$% <-- changed line
\span\MT_cramped_internal:Nn \scriptstyle {##}%
in the definition of crampedsubstack
@daleif I can't reproduce the "missing {
" with the code from issue 17, but if you send me a small example I'll have a look what's going on.
@zauguin Here is what I did
MWE
\documentclass{article}
\usepackage{mathtools}
\usepackage{unicode-math}
\usepackage{graphicx} % for \scalebox
\newcommand\drawbaseline{%
\leavevmode
\hbox to 0pt {\hss\vrule width 50pt height 0.1pt depth 0pt }%
}
\begin{document}
\centering
\scalebox{6}%
{$\displaystyle\sum_{k^2=n}\quad
\sum_{\crampedsubstack{k^2=n\drawbaseline}}$}
\end{document}
then I also changed a local copy of lualatex-math.sty
to have
\__lltxmath_after_package_or_now:nn { mathtools } {
\__lltxmath_patch:NNnnn \MT_cramped_internal:Nn
\cs_set_nopar:Npn { #1 #2 } {
\setbox\z@\hbox{$\m@th#1\kern-\nulldelimiterspace\radical\z@{#2}$}
\ifx#1\displaystyle
\dimen@=\fontdimen8\textfont3
\advance\dimen@ .25\fontdimen5\textfont2
\else
\dimen@=1.25\fontdimen8
\ifx#1\textstyle\textfont
\else
\ifx#1\scriptstyle
\scriptfont
\else
\scriptscriptfont
\fi
\fi
3
\fi
\advance\dimen@-\ht\z@ \ht\z@=-\dimen@
\ifvmode\leavevmode\fi
{}\box\z@
} {
{
\ensuremath {
\use:c { cramped \cs_to_str:N #1 } #2
}
}
}
}
basically updating the code it is trying to patch.
This now gives me
./bug.tex:16: Missing { inserted.
<inserted text>
{
l.16 ...sum_{\crampedsubstack{k^2=n\drawbaseline}}$}
I should have explained more carefully.
I'm guessing this is now related to the following change to crampedsubarray
(used by \crampedsubstack
)
\newenvironment{crampedsubarray}[1]{%
\vcenter\bgroup
\Let@ \restore@math@cr \default@tag
\baselineskip\fontdimen10 \scriptfont\tw@
\advance\baselineskip\fontdimen12 \scriptfont\tw@
\lineskip\thr@@\fontdimen8 \scriptfont\thr@@
\lineskiplimit\lineskip
\ialign\bgroup\ifx c#1\hfil\fi
%%$\m@th\scriptstyle\kern-\nulldelimiterspace\radical\z@{##}$% <-- changed line
\span\MT_cramped_internal:Nn \scriptstyle {##}%
\hfil\crcr%
}{%
\crcr\egroup\egroup
}
the \span
part is new
Seems for lualatex we then need crampedsubarray
to be using
\renewenvironment{crampedsubarray}[1]{%
\vcenter\bgroup
\Let@ \restore@math@cr \default@tag
\baselineskip\fontdimen10 \scriptfont\tw@
\advance\baselineskip\fontdimen12 \scriptfont\tw@
\lineskip\thr@@\fontdimen8 \scriptfont\thr@@
\lineskiplimit\lineskip
\ialign\bgroup\ifx c#1\hfil\fi
\span$\MT_cramped_internal:Nn \scriptstyle {##}$% <---- I added the $'s
\hfil\crcr%
}{%
\crcr\egroup\egroup
}
though I don't quite understand why? since under lualatex \MT_cramped_internal:Nn
is now using \ensuremath
+ the lualatex crammped macros (@u-fischer it might be therefore \ensuremath
was used.
Anyone understand why this extra $...$
is needed here?
I agree with @u-fischer, we ought to check for lualatex in mathtools and perform the change there.
Looking at amsmath, one should of course use that updated code for crampedsubarray
instead
Anyone understand why this extra
$...$
is needed here?
The issue is that in \MT_cramped_internal:Nn
, the #
ends up in the argument of \ensuremath
, which doesn't get expanded until after the cell is completed, therefore the end of the cell can't be identified correctly. So the \endcrampedsubarray
ends up inside of the \ensuremath
, leading to mismatched braces and math delimiters. Adding $...$
fixes this since it turns \ensuremath
basically in a noop, so it's placement is less important. I'm not sure though why this didn't show up earlier without the \span
.
@zauguin that makes sense, I was wondering in that direction. I think it \ensuremath
was uses like that because the original \cramped
actually works outside math mode. Accident?
It seems to be better to just adjust the version of subarray
from amsmath
using \crampedscriptstyle
directly when lualatex is used: No need for MT_cramped_internal:Nn
\renewenvironment{crampedsubarray}[1]{%
\vcenter\bgroup
\Let@ \restore@math@cr \default@tag
\baselineskip \Umathstacknumup \scriptstyle
\advance\baselineskip \Umathstackdenomdown \scriptstyle
\lineskip \Umathstackvgap \scriptstyle
\lineskiplimit \lineskip
\ialign\bgroup\ifx c#1\hfil\fi
\Ustartmath
% \m@th\scriptstyle##
\crampedscriptstyle{##}
\Ustopmath
\hfil\crcr
}{%
\crcr\egroup\egroup
}
@zauguin any idea why in lualatex-math.sty
we have
{
\ensuremath {
\use:c { cramped \cs_to_str:N #1 } #2
}
}
Why the extra grouping? Might be usage related
BTW: the grouping is explained in lualatex-math
:
Here the additional set of braces is absolutely necessary, otherwise the changed mathematical style would be applied to the material after the \mathchoice construct. As the original command works in both text and math mode, we use \ensuremath here.
I think this solves this from the mathtools
side. I'll write the maintainer of lualatex-math
to note that their patch for lualatex is now in mathtools
itself.
I've fixed this in lualatex-math for mathtools 1.26 (https://github.com/phst/lualatex-math/commit/ad51bb060107da4e5cc82e16e19243049fe97a58). Since this is now fixed in mathtools, I'm planning to remove the patch eventually from lualatex-math. For now I haven't added a patch for mathtools 1.25; not sure how important that would be if 1.26 makes it into TeX Live 2021.
FWIW, since the 1.25 version of
mathtools
, a new warning appears when it is used in conjunction withlualatex-math
:Here is a MCE:
and the file list:
BTW: I will draw the attention of the author of
lualatex-math
.