CTeX-org / ctex-kit

Macro Packages and Scripts for Chinese TeX users
976 stars 124 forks source link

xeCJK: No fallback for punctuations #515

Closed cykerway closed 4 years ago

cykerway commented 4 years ago

Code:

\documentclass[]{article}
\usepackage[AutoFallBack=true]{xeCJK}

\setmainfont{DejaVu Serif}
\setCJKmainfont{FreeSerif}
\setCJKfallbackfamilyfont{\CJKrmdefault}{
    {AR PL UMing CN},
    {Noto Serif CJK KR},
}

\begin{document}

にほんご?한국어!简体中文:繁體中文;English。

\CJKfamilydefault == rm

\end{document}

Result:

CJK and English characters are displayed corrrectly, but all punctuations are tofu.

a

qinglee commented 4 years ago

FreeSerif is not a valid CJK font. So please replace it by AR PL UMing CN in your code.

\documentclass[]{article}
\usepackage[AutoFallBack=true]{xeCJK}

\setmainfont{DejaVu Serif}
\setCJKmainfont{AR PL UMing CN}
\setCJKfallbackfamilyfont{\CJKrmdefault}{Noto Serif CJK KR}

\begin{document}

にほんご?한국어!简体中文:繁體中文;English。

\CJKfamilydefault == rm

\end{document}

You can also assign the font of punctuations individually via option PunctFamily.

cykerway commented 4 years ago

No, you didn't get my point. I know FreeSerif is not a CJK font and that is the reason I put it there.

My point is, I have installed 2 fallback fonts in case FreeSerif is not enough. But these fallback fonts are not working as expected. In practice, the CJK main font is set by my users, and my job is to provide sane fallbacks in case my users misconfigure. As you can see, these fallbacks didn't successfully guard my users, giving them tofu.

I may consider PunctFamily but I hope puncts can go along with main font fallbacks, so that users don't feel discrepancy between language characters and puncts.

qinglee commented 4 years ago

I did know your point. But I won't fix this issue since it is an edge case. You can raise a warning to your users in that case.

cykerway commented 4 years ago

God. This isn't an edge case but a true bug. The problem happens because AutoFallBack only redefines \CJKsymbol but not \CJKpunctsymbol. It is the latter one that is being used to output punctuations. It is safe to say the current implementation doesn't have fallbacks for punctuations. That would surprise users.

After I duplicated some functions from \CJKsymbol to \CJKpunctsymbol, the problem disappears. Result from the same program:

image

I already made a patch for this. Not necessarily optimized at its best, but I believe is solving the problem in the right way.