latex3 / babel

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

Weird behavior when using \babelfont with two styles in LuaTeX #178

Closed NudPiyapon closed 12 months ago

NudPiyapon commented 2 years ago

Note: This issue stems from stackexchange forum: https://tex.stackexchange.com/questions/637687/weird-behavior-when-using-babelfont-with-two-styles-in-luatex

Consider these MWEs.

\documentclass{article}

\usepackage[english]{babel}
\babelprovide[onchar=ids fonts]{english}
\babelprovide[main,import]{thai}
\usepackage{fontspec}

% \babelfont[thai]{rm}[
%     Script=Thai,
%     UprightFont = *.otf,
%     BoldFont = *-Bold.otf,
%     ItalicFont = *-Italic.otf,
%     BoldItalicFont = *-BoldItalic.otf]
%     {Laksaman}
\babelfont[thai]{rm}{FreeSerif}
\babelfont[thai]{sf}[
    Script=Thai,
    UprightFont = *.otf,
    BoldFont = *-Bold.otf,
    ItalicFont = *-Italic.otf,
    BoldItalicFont = *-BoldItalic.otf]
    {Laksaman}

\begin{document}
    ข้อความทดสอบ Test text.
    \textsf{ข้อความทดสอบ Test text.}
\end{document}

The following code produces expected result. (Correctly apply serif and sans-serif style) image

However, when I changed the serif font of Thai to the same as sans-serif one (Laksaman), the product of this code is formatted wrong. (The last test text's style is serif, not sans-serif)

\documentclass{article}

\usepackage[english]{babel}
\babelprovide[onchar=ids fonts]{english}
\babelprovide[main,import]{thai}
\usepackage{fontspec}

\babelfont[thai]{rm}[
    Script=Thai,
    UprightFont = *.otf,
    BoldFont = *-Bold.otf,
    ItalicFont = *-Italic.otf,
    BoldItalicFont = *-BoldItalic.otf]
    {Laksaman}
% \babelfont[thai]{rm}{FreeSerif}
\babelfont[thai]{sf}[
    Script=Thai,
    UprightFont = *.otf,
    BoldFont = *-Bold.otf,
    ItalicFont = *-Italic.otf,
    BoldItalicFont = *-BoldItalic.otf]
    {Laksaman}

\begin{document}
    ข้อความทดสอบ Test text.
    \textsf{ข้อความทดสอบ Test text.}
\end{document}

image

So, could anyone explains to me what happened here? Thanks in advances!

jbezos commented 2 years ago

I’ve posted a workaround in stackexchange, but I’ll investigate a general solution to this issue once TeXLive 2022 is released (I'm taking a short break).

jbezos commented 2 years ago

While investigating how to deal with these cases and how to improve the current algorithm, I’ve discovered a very dirty trick: add a dummy RawFeature (e.g. RawFeature=+xxxx) to the second font. Seems to work.

jbezos commented 12 months ago

The workaround based on the RawFeature doesn’t work anymore, and what’s worse, the working example (with the expected result) doesn’t work with TeXLive 2023... 🙁 (it worked with 2022).