latex3 / babel

The babel system for LaTeX, LuaLaTeX and XeLaTeX
LaTeX Project Public License v1.3c
126 stars 34 forks source link

Underfull \hbox with amsmath #133

Closed ethey closed 3 years ago

ethey commented 3 years ago

When using a split environment inside an align one, I always get an Underfull \hbox warning if Babel is loaded.

Here is a minimal working example:

\documentclass{article}

\usepackage{babel}
\usepackage{amsmath}

\begin{document}

\begin{align}
  \begin{split}
    a &= a \\
      &\quad + 0
  \end{split} \\
  \begin{split}
    a &= a \\
      &\quad + 0
  \end{split} \\
\end{align}

\end{document}

If I remove Babel, then I do not have any warning. Visually I do not observe any difference in the PDF that is produced, and this only seems to happen with LuaLaTeX, and not pdfLaTeX nor XeLaTeX. So I am not sure if that should be reported here.

I have tried with an up to date version of TeXLive 2021.

FrankMittelbach commented 3 years ago

I don't get any underfull box with babel from your example, but I get a third equation number because of the \\ after the last split. When I add \listfilesto the preamble it reports

 *File List*
 article.cls    2020/04/10 v1.4m Standard LaTeX document class
  size10.clo    2020/04/10 v1.4m Standard LaTeX file (size option)
   babel.sty    2021/05/16 3.59 The Babel package
     nil.ldf    2021/05/16 3.59 Nil language
 amsmath.sty    2020/09/23 v2.17i AMS math features
 amstext.sty    2000/06/29 v2.01 AMS text
  amsgen.sty    1999/11/30 v2.0 generic functions
  amsbsy.sty    1999/11/29 v1.2d Bold Symbols
  amsopn.sty    2016/03/08 v2.02 operator names
l3backend-pdftex.def    2021-05-07 L3 backend support: PDF output (pdfTeX)
 ***********

as version numbers.

u-fischer commented 3 years ago

@FrankMittelbach you used pdftex, but the report says the problem is with lualatex (and I get underfull hboxes there).

FrankMittelbach commented 3 years ago

@u-fischer ok one should read to the end, sorry. So yes, it is there in LuaTeX and to report it report here seems correct, as it comes from

\bbl@mathboxdir ->\ifcase \bbl@thetextdir \relax \everyhbox {\textdir TLT\relax
 }\else \everyhbox {\textdir TRT\relax }\fi 

Thus \begindir TLT ends up in each and every hbox and that is basically deadly ... in particular here

\split@ ->\hbox to\wd \thr@@ {}&\vcenter {\vbox {\moveleft \wd \thr@@ \boxz@ }}

Tex doesn't report underful boxes when they are empty (so the above was fine but with the TLT node added it isn't any longer empty, thus ... :-)

At least that is how I read it.

FrankMittelbach commented 3 years ago

Well, one could argue that such nodes just setting direction should not change the state of the box being empty or not, but I'm not sure that is going to be a sell for the LaTeX developers --- but maybe it is.

blefloch commented 3 years ago

Alternatively, to stay with changing stuff that's under our control, change \bbl@mathboxdir to

\def\bbl@mathboxdir{\ifcase \bbl@thetextdir \relax
  \everyhbox {\bbl@mathboxdir@ L}\else\everyhbox{\bbl@mathboxdir@ R}\fi}
\def\bbl@mathboxdir@#1{\@ifnextchar\egroup{}{\textdir T#1T\relax}}

(Not tested but the idea is to suppress the \textdir TLT when the box is empty.)

FrankMittelbach commented 3 years ago

cool approach @blefloch , can't think of a reason why that shouldn't work.

ethey commented 3 years ago

I have tested on my document, and none of the spurious bad boxes are reported anymore.

Also, I almost did not want to report this because I could not figure out where this came from. Basically what you did @FrankMittelbach was to use \showoutput and noticed the \begindir TLT?

FrankMittelbach commented 3 years ago

Yes (after reading your report when Ulrike pointed out my initial mistake). From there it was a little guesswork, but likely that @jbezos introduced it so I'll cut down your example further and then did a \traceon on it searching for suspicious usages of TLT :-) the rest was easy.

ethey commented 3 years ago

Thanks!

jbezos commented 3 years ago

You have sent 8 replies before I even read it! 🙂 Seems easy to fix (actually, there is very likely another issue, because this function should not be enabled by default, only with bidi =).

jbezos commented 3 years ago

@blefloch Nice. It fails if there is some macro (eg, \@empty), but it's a very good solution.