xeCJK breaks non-Chinese characters

\documentclass{article}
\usepackage{fontspec}
\usepackage{xeCJK}
\setCJKmainfont{AR PL UMing CN}
\begin{document}

something…

x’s

\end{document}


gives me the following output:

obviously the three dots are displayed too high, and after the apostrophe an extra space is inserted.

Commenting out the two xeCJK-related lines:

Curiously commenting out fontspec in the version without xeCJK will leave out the three dots and the apostrophe. I guess some non-standard characters have been used here which are then taken care of by xeCJK? And my best solution would be to replace them with alternatives such as ... and '. Only that I'm afraid that this only is the tip of the iceberg, and in a more than 300 pages book there will be more surprises which I might not spot as easily as I did these two, and the logfile doesn't tell me anything about it either. And the whole story just for eight words in Chinese characters... How do I best fix this?

In fact in my log file I have three instances of something like

LaTeX Font Warning: Font shape EU1/ARPLUMingCN(0)/m/sc' undefined
(Font)              using EU1/ARPLUMingCN(0)/m/n' instead on input line 292.


there apparently not being any it/sl/sc shapes for the CJK font, but that doesn't help me much either. Can I increase the verbosity of xelatex to report change of font in the log file?

• The two characters U+2026 (HORIZONTAL ELLIPSIS) and U+2019 (RIGHT SINGLE QUOTATION MARK) indeed trigger switching to the CJK font. – egreg Oct 13 '15 at 16:30
• No problem with the ellipsis if you use \dots instead of … – erik Oct 13 '15 at 16:48

The characters U+2026 (HORIZONTAL ELLIPSIS) and U+2019 (RIGHT SINGLE QUOTATION MARK) indeed trigger switching to the CJK font because they are assigned to character class 3. Reassigning them to class 0 seems to solve the issue:

\documentclass{article}
\usepackage{fontspec}
\usepackage{xeCJK}
\setCJKmainfont{SimSun}

\AtBeginDocument{%
\XeTeXcharclass^^^^2026=0
\XeTeXcharclass^^^^2019=0
}

\begin{document}

something…else

x’s

x's

\end{document}


However, you can use ' (undirected quote) for getting the right single quotation mark (or apostrophe), because the default mapping does the change which happens after XeTeX has performed the jobs related to the character classes.

You can disable the automatic font switching by using \makexeCJKinactive and reenabling it with \makexeCJKactive (or closing a group in which you have set the former command).

\documentclass{article}
\usepackage{fontspec}
\usepackage{xeCJK}
\setCJKmainfont{SimSun}

\makexeCJKinactive % it's active by default

\begin{document}

something…else

x’s

x's

\makexeCJKactive

something…else

\end{document}


If you use xeCJK just to typeset a few Chinese words, you could define a command

\NewDocumentCommand{\textzh}{m}{%
\begingroup\makexeCJKactive#1\endgroup
}


but in this case using xeCJK seems like a sledgehammer, because declaring a font family with fontspec and defining a similar command to the above would do more easily:

\newfontfamily{\zhfont}{SimSun}% or whatever
\DeclareTextFontCommand{\textzh}{\normalfont\zhfont}


In both cases, \textzh{<Chinese text>} will switch to the Chinese font.

• That works for these two characters. Only how do I find out which other ones are also affected by this problem? – muk.li Oct 13 '15 at 16:58
• @muk.li I guess you find them in the documentation for xeCJK. But you have to know Chinese, I'm afraid. – egreg Oct 13 '15 at 17:03
• There's no switch to increase the verbosity level of xelatex to report font changes so I could grep my logfile for where it switches to Chinese font? – muk.li Oct 13 '15 at 17:06
• @muk.li You can add \showoutput, that will give font information for any run of characters (which is how I discovered the issue). You can also do \makexeCJKinactive for disabling automatic switching and \makexeCJKactive for reenabling it. – egreg Oct 13 '15 at 17:10
• @muk.li I've extended my answer. – egreg Oct 13 '15 at 17:17