0

The ctex bundle provides Mapping = fullwidth-stop to convert ordinary Chinese periods (。) to fullwidth periods (.). (Not to be confused with halfwidth periods (.).)

However, this only works for one font.

\documentclass[UTF8, fontset = fandol]{ctexart}

\setCJKmainfont{FandolSong}[%
  Mapping = fullwidth-stop
]

\begin{document}

天地玄黄,宇宙洪荒。盖此身发,四大五常。

\kaishu
天地玄黄,宇宙洪荒。盖此身发,四大五常。

\end{document}

enter image description here

The kaishu font is not altered. Of course I can do it separately for kaishu, but then I also have to do for fangsong, heiti, etc. I would like to do it for all fonts in one place.

The documentation mentions \addCJKfontfeatures. I tried to use it:

\documentclass[UTF8, fontset = fandol]{ctexart}

\addCJKfontfeatures{Mapping = fullwidth-stop}

\begin{document}

天地玄黄,宇宙洪荒。盖此身发,四大五常。

\kaishu
天地玄黄,宇宙洪荒。盖此身发,四大五常。

\end{document}

However, this didn't function:

enter image description here

\addCJKfontfeatures* didn't help either. What is the correct way to use \addCJKfontfeatures? How to set the mapping for all fonts in one place?

muzimuzhi Z
  • 26,474
L. F.
  • 796

1 Answers1

1

This works

% cancel CJK font declarations at class loading
\documentclass[fontset=none]{ctexart}

% change default CJK font features
\defaultCJKfontfeatures{Script=CJK, Mapping=fullwidth-stop}
% declare CJK fonts, with new default features applied
\ctexset{fontset=fandol}

\begin{document}
天地玄黄,宇宙洪荒。盖此身发,四大五常。

\kaishu
天地玄黄,宇宙洪荒。盖此身发,四大五常。
\end{document}

enter image description here

From the documentation of package xeCJK,

  • \addCJKfontfeatures only affects the currently used font, so after you change to a new font by \kaishu, new font feature disappears.
  • \defaultCJKfontfeatures affects every following font declarations, hence is what you need.

By the way, option Mapping is defined in fontspec package, then package xeCJK inherits it and provides four mapping files (including the one OP used), finally ctex bundle loads xeCJK to declare CJK fonts.

muzimuzhi Z
  • 26,474
  • Excellent! This seems like the canonical solution. Just to make sure I understood correctly: I think \addCJKfontfeatures, which does "临时增加当前使用的CJK字体的选项" per doc, doesn't work because there is no "当前使用的CJK字体" in the preamble. Moving it inside the document makes it work, but the changes cease to apply when the font is changed. Am I right? If that is right, then everything makes sense to me now :) – L. F. Mar 11 '20 at 04:33
  • @L.F. Yes, you are right. – muzimuzhi Z Mar 11 '20 at 04:36
  • Just curious: is there a way to retroactively add features to the fonts already loaded, thereby avoiding the need for fontseting separately? – L. F. Mar 16 '20 at 04:16
  • It is possible but currently not implemented. 1. Font features are stored in (internal) font changing commands only. So, to add feature is to redefine commands. 2. xeCJK does not keep a defined-font-changing list, hence it did not know the name list of declared font changing commands. 3. Both restrictions are inherited from fontspec. – muzimuzhi Z Mar 16 '20 at 07:32
  • The command name and font features of current font can be retrieved by \expandafter\string\the\font and \fontname\font, respectively (see this answer). This is how \addCJKfontfeatures works. – muzimuzhi Z Mar 16 '20 at 07:36
  • When using this solution, it gives many "Undefined control sequence." errors for math, even I remove the defaultCJKfontfeatures command. Any idea why this happens? I'm using ctexbook documentclass. – Yijun Yuan Oct 15 '20 at 05:44
  • @YijunYuan My answer need xetex engine. Which engine do you use? Perhaps you can post a new question with more info. – muzimuzhi Z Oct 15 '20 at 14:31