13

When combining Chinese, Japanese and Korean text in a document, is there a way to define individual fonts for the respective characters? Especially for Korean, since few fonts support Cn/Jp AND Korean. Right now I'm using a little workaround by wrapping all Korean text in \texttt{} and setting the font with \setCJKmonofont.

\usepackage{xeCJK}
\setCJKmainfont{Hiragino Mincho Pro} % for Cn & Jp
\setCJKmonofont{AppleMyungjo} % for Kr

\newcommand\cn[1]{\textnormal{#1}}
\newcommand\jp[1]{\textnormal{#1}}
\newcommand\kr[1]{\texttt{#1}}
Leo Liu
  • 77,365
estolua
  • 577

2 Answers2

16

Well, you can freely use \setCJKfamilyfont to define as many fonts as you need. And you can use \CJKfamily to change the font. This is quite similar to the way you have used.

On the other hand, current xeCJK does not have the ability to define different fonts for Chinese, Japanese and Korean individually. In fact, the three languages shares a lot of characters, and it is impossilbe to distinguish which language it is automatically.

An alternative solution is, use fallback option of xeCJK to define a main font (for Chinese & Japanese) and its fallback font (for Korean). For example,

\documentclass{article}
\usepackage[fallback]{xeCJK}[2011/05/01 v2.3.19]
% Fonts available on windows
\setCJKmainfont{SimSun}
\setCJKfallbackfamilyfont{\CJKrmdefault}{Batang}

\begin{document}
你好

こんにちは

여보세요
\end{document}

However, for serious typesetting, the result using fallback font option is questionable. Some glyphs looks quite different among the three countries. A glyph in a Chinese font may be wrong in Korean or Japanese, and vice versa. Thus, a proper way is still change the font manually:

\documentclass{article}
\usepackage{xeCJK}[2011/05/20 v2.4.1]
\setCJKfamilyfont{zhrm}{SimSun}
\setCJKfamilyfont{jarm}{MS Mincho}
\setCJKfamilyfont{korm}{Batang}

\newcommand\Chinese{\CJKfamily{zhrm}\CJKnospace}
\newcommand\Japanese{\CJKfamily{jarm}\CJKnospace}
\newcommand\Korean{\CJKfamily{korm}\CJKspace}

\begin{document}
{\Chinese 你好}

{\Japanese こんにちは}

{\Korean 여보세요}
\end{document}

Update

For newer xeCJK (ver 3.x), you can set different fonts for different sub CJK blocks:

\documentclass{article}
\usepackage{xeCJK}[2012/04/08 v3.0.0]

\xeCJKDeclareSubCJKBlock{Kana}{"3040 -> "309F, "30A0 -> "30FF, "31F0 -> "31FF, "1B000 -> "1B0FF}
\xeCJKDeclareSubCJKBlock{Hangul}{"1100 -> "11FF, "3130 -> "318F, "A960 -> "A97F, "AC00 -> "D7AF, "D7B0 -> "D7FF}

\setCJKmainfont{SimSun}
\setCJKmainfont[Kana]{MS Mincho}
\setCJKmainfont[Hangul]{Batang}

\begin{document}
你好

こんにちは

여보세요
\end{document}
Leo Liu
  • 77,365
  • This works, but I get square boxes for the Korean text using Baekmuk Batang (ttf-baekmuk package in Arch Linux). Curiously, if I use the \setCJKmainfont[Mapping=tex-text]{Baekmuk Batang} command by itself, XeTeX can output the correct glyphs just fine --- I would use this command all the time, if it weren't for the restriction that it can only be in the preamble. – Linus Arver May 19 '13 at 04:02
  • Also, if I comment out the Chinese and Japanese parts of your sample document, the Korean text is displayed properly; the moment I add in the Japanese parts, I get square boxes for the Korean text. From what I can tell, I am using "xeCJK.dtx 399 2013-01-11 14:57:50Z sobenlee". – Linus Arver May 22 '13 at 03:42
  • @opert: See my update. – Leo Liu May 22 '13 at 05:15
  • Thanks. The updated example works great, but is there a way to get fine-grained manual font-switching like in your original example? I would love to manually switch fonts like that --- e.g., it would come in handy if I want to use 3 different Korean serif fonts along with 2 different Japanese serifs for certain parts of the document. It is not clear to me how to achieve something like this with your updated example. – Linus Arver May 22 '13 at 14:18
  • @opert: I also updated the second example to fix the problem, you can certainly switch the fonts manually. I'm sorry that there is only a manual in Chinese available for the current version. We don't have much time for that. Anyway, there're examples in the doc directory of xeCJK package. – Leo Liu May 22 '13 at 15:00
  • Oops, I just noticed that. Yes, all of your examples work just fine (although, it would be even better if you could somehow enable the [Mapping=tex-text] option with those manual font declarations). I was not aware that xeCJK comes with example documents --- thanks for the heads up! – Linus Arver May 22 '13 at 16:01
  • Um, I just realized that those manual declarations work just fine with tex-styled-text (e.g., using two backticks + two single-quotes for double-quote pairs). Sorry for the noise. – Linus Arver May 22 '13 at 20:14
  • @Liu: you should definitely translate the manual. How about asking a professional translator for a quote, and then start a kickstart project for raising that sum? I will gladly contribute and I'm sure others will do that as well!!! – yannis Aug 30 '19 at 13:50
  • Question: is it possible to choose a different font for non-CJK characters? – yannis Aug 30 '19 at 13:52
  • A tiny tackle for Korean example: "여보세요" does not correspond to こんにちは and 你好. It is used when you receive a call, but you do not know who makes a call to you. (Thus, it corresponds to もしもし in Japanese.) A more appropriate Korean example would be 안녕하세요. – Hanul Jeon Jan 29 '21 at 14:01
2

You can do this with the \babelfont command from babel. I copied this sample text from another user, and apologize for any errors in any of the languages.

This MWE uses the Noto CJK fonts from Google, but you can substitute any other fonts of your choice, for example, the free Hirono Aji Mincho fonts from the hironoaji package for Japanese.

\documentclass{article}
\tracinglostchars=3 % Make it an error if characters are missing.
\usepackage[english]{babel}
\usepackage{parskip}

\babelprovide[import]{japanese} \babelprovide[import]{korean} \babelprovide[import=zh-hant]{chinese} % Or zh-hans for Simplified Chinese

\babelfont{rm} {Noto Serif} \babelfont[chinese]{rm} [Renderer=HarfBuzz]{Noto Serif CJK tc} \babelfont[japanese]{rm} [Renderer=HarfBuzz]{Noto Serif CJK jp} \babelfont[korean]{rm} [Renderer=HarfBuzz]{Noto Serif CJK kr}

\begin{document} Japanese: \foreignlanguage{japanese}{フォントはまた、数学的な形態および他の環境で使用することができるフォントはまた、数学的な形態および他の環境で使用することができる}

Chinese: \foreignlanguage{chinese}{关于数学部分}

Korean: \foreignlanguage{korean}{전체 문서에 대한 기본 정보를 소개 단락.} \end{document}

Noto font sample

Davislor
  • 44,045