reutenauer / polyglossia

An alternative to Babel for XeLaTeX and LuaLaTeX
http://www.ctan.org/pkg/polyglossia
MIT License
190 stars 51 forks source link

With nested language switches, any inner switch sets the font family that outer switch had “seen”, not the current font #519

Closed tifv closed 2 months ago

tifv commented 2 years ago
\documentclass[10pt]{article}

\usepackage[no-math]{fontspec}
\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{russian}

\begin{document}

\sffamily
\begin{russian}
Should be sans.
\ttfamily
Should be monospaced.
\begin{english}
Sans, but should be monospaced?
\end{english}
\end{russian}

\end{document}

will produce image You can see that inner language switch resets the font back to sans. This is unexpected, as I intended to switch language, not the font.

Further tests show that the outer language switch somehow “memorizes” the font family that was used at the moment it was enabled, and any inner language switch will set it irregardless of subsequent font family changes. (Tested with TeXLive 2021. Using English inside russian environment is irrelevant, it will work the same with a Russian text. Probably related to #251.)

jspitz commented 2 years ago

251 is not the culprit here.

jspitz commented 2 years ago

Should be fixed.

Udi-Fogiel commented 4 months ago

I'm reopening as it seems like we have a regression in master. The example provided by the OP no longer produce a correct output.

Udi-Fogiel commented 4 months ago

Was this bug really fixed? If I reverse the rolls of russian and english in the example

\documentclass[10pt]{article}

\usepackage[no-math]{fontspec}
\usepackage{xcolor}
\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}[Color=blue]
\setmonofont{CMU Typewriter Text}[Color=red]
\usepackage{polyglossia}
\setdefaultlanguage{russian}
\setotherlanguage{english}

\begin{document}

\sffamily
\begin{english}
Should be sans.
\ttfamily
Should be monospaced.
\begin{russian}
Sans, but should be monospaced?
\end{russian}
\end{english}

\end{document}

I get the same problem (also tested with TL 2022). In 8ef31ad I also stored font families in Latin fonts, which fixed it.

jspitz commented 2 months ago

The problem is fixed, AFAICS