Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LuaTeX – Babel – Font change not applied without \babelfont or with \addfontfeatures. #721

Open
BenjaminGalliot opened this issue Sep 23, 2024 · 0 comments

Comments

@BenjaminGalliot
Copy link

BenjaminGalliot commented Sep 23, 2024

(Sorry for using English.)

The font change (in my case to the Kaiti style) doesn't seem to be applied unless a \babelfont command (even an incorrect one) has been called beforehand. I'm not sure if this is intended or documented behavior, nor whether the issue originates from ctex... It also seems that using \selectlanguage{chinese} before instead of \foreignlanguage{chinese}{...} can sometimes result in a different, but expected, behavior, though it's difficult for me to fully understand why (several mechanisms at play).

Furthermore, if the language set with \babelfont is the document's main language, the \addfontfeatures command (with options) placed before the language/font change appears to reset the font. I believe this behavior is not intended. Also, how can font features be added in this case?

Finally, and I’m not sure if this is related, some font options (such as Color=...) seem to cause the compilation to fail. It worked with TexLive 2023…

I used some advices provided in #628.

MWE

\documentclass{book}
\usepackage[french]{babel}
\usepackage{ctex}
\usepackage{xcolor}

\babelprovide[import=zh-Hans]{chinese}

% Enable any of the 3 lines will generate good behaviour for « test »…
%\babelfont[french]{rm}{EBGaramond} % … but enable this line (language same as Babel default, it could be « english ») will generate bad behaviour for one « extra test » (\addfontfeatures{…} will generate warnings and reset the font).
%\babelfont[chinese]{rm}{STKaiti}
%\babelfont[xx]{yy}{zz} % It works with bad values!

\setCJKfamilyfont{chineserm}[AutoFakeBold=1.5]{STKaiti} % Add « Color=blue » in options will generate errors, by the way…

\NewDocumentCommand \tfra { m } {\foreignlanguage{french}{#1}}
\NewDocumentCommand \tcmn { m } {{\foreignlanguage{chinese}{#1}}}
\NewDocumentCommand \tcmnbis { m } {{\CJKfamily{chineserm}#1}}

\ExplSyntaxOn
\tl_put_right:cn {extraschinese} {
    \RenewDocumentCommand \CJKrmdefault {} {chineserm}
}
\ExplSyntaxOff

% Following hints from warnings for \addfontfeatures, without success.
%\setfontfamily \chinesermfont {STKaiti} 
%\RenewDocumentCommand \tcmnbis { m } {{\fontspec{STKaiti}\chinesermfont\CJKfamily{chineserm}#1}} 

\NewDocumentCommand \showlanguage { m } {\quad \textcolor{blue}{\emph{#1}}}

\begin{document}

\chapter*{\tcmn{楷体} \showlanguage{cmn} (test)}

\section{Section \showlanguage{none}}

\section{\tfra{Section} \showlanguage{fra}}

\section{楷体 \showlanguage{none}}

\section{\tfra{楷体} \showlanguage{fra}}

\section{\tcmnbis{楷体} \showlanguage{cmnbis} (control: always Kaiti)}

\section{\tcmn{楷体} \showlanguage{cmn} (test)}

\Large

control: \tcmnbis{楷体}

test: \tcmn{楷体}

extra control (font features): {\tcmn{\addfontfeatures{}楷体}}

extra test (font features outside): {\addfontfeatures{Scale=2}\tcmn{楷体}}

extra test (font features inside): {\tcmn{\addfontfeatures{Scale=2}楷体}}

\end{document}

Some screenshots:

Test without any \babelfont

test without babelfont

Test with a non-main-language \babelfont

test with non french babelfont

Test with main-language \babelfont

test with french babelfont

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant