latex3 / babel

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

Bad interraction between bidi option and mathtools package in align environment #166

Closed yrogge closed 2 years ago

yrogge commented 2 years ago

Using the new 3.70 version with luaLaTeX, there is a strange behavior in align environment. See example below. With both bidi=basic option (line 4) and \usepackage{mathtools} (line 7), there are errors in align (at line 23). Commenting either one, the tags in it are misplaced.

\documentclass[a4paper,twoside,10pt,english]{article}
\usepackage[no-math,silent]{fontspec}
\usepackage[
  bidi=basic, % not compatible with package mathtools
]{babel}
\usepackage{amsmath}
\usepackage{mathtools} % not compatible with bidi option
\renewcommand{\familydefault}{\sfdefault} % Pour polices sans empattement
\babelfont{rm}{Noto Serif}     % alias \setmainfont
\babelfont{sf}{Noto Sans}      % alias \setsansfont
\babelfont{tt}{Noto Sans Mono} % alias \setmonofont (no Italic, no Bold Italic)
\usepackage{lualatex-math}
\usepackage{unicode-math}      % => \setmathfont
\setmathfont[StylisticSet={8,11,16}]{STIX Two Math} % upint, neg.set, circled op. (+ \mathscr)
\usepackage[basic,asterisk,unicodeminus,defaultmathsizes]{mathastext}
\begin{document}
\section{Test}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
\begin{align}
  W(X,Y)
    &= \frac{1}{q^\varrho}\ \left( \Bigl( Y+(q\!-\!1)X \Bigr)^\frac{q^\varrho-1}{q-1} + (q^\varrho-1)\ \Bigl( Y-X \Bigr)^{q^{\varrho-1}}\,\Bigl( Y+(q\!-\!1)X \Bigr)^\frac{q^{\varrho-1}-1}{q-1} \right) \\
    &= \Bigl( Y+(q\!-\!1)X \Bigr)^\frac{q^{\varrho-1}-1}{q-1} \left[ \frac{1}{q^\varrho}\ \Bigl( Y+(q\!-\!1)X \Bigr)^{q^{\varrho-1}} + \left( 1 - \frac{1}{q^\varrho}\ \right) \Bigl( Y-X \Bigr)^{q^{\varrho-1}} \right]
\end{align}
\end{document} 
yrogge commented 2 years ago

NB. Everything was OK with version 3.67.

jbezos commented 2 years ago

As a workaround, try with:

\usepackage{amsmath}
\usepackage{mathtools} % not compatible with bidi option
\makeatletter
\let\save@intertext\intertext@
\AtBeginDocument{\let\intertext@\save@intertext}
\makeatother

Babel patches for \intertext are meant for amsmath, but mathtools changes this command further and the definition is messed up.

yrogge commented 2 years ago

OK. It works. Thank you. But there is now another strange behavior: after tagged environments (equation, align, etc.), the following non-math text is always indented as at the begin of a new paragraph. It is not the case if there were no tags ([ ], align*, etc.). Note that it is not the case when the text is produced inside the environment with \intertext or \shortintertext macros.