1

So far I successfully used a Chinese font from a file. Now I decided to use the package xeCJK and my setup does not work anymore. Would you please suggest what should I add for xeCJK?

In an example below, if the line \usecjktrue is commented-out, then the file is compiled successfully and I get Chinese letters in pdf. If \usecjktrue is active, then the error message is:

kpathsea: Running mktextfm ukai
...
! I can't find file `ukai'.
...
! fontspec error: "font-not-found"
! The font "ukai" cannot be found.

The code:

\documentclass{article}

\usepackage{polyglossia}
\DeclareFontFamily{EU1}{ukai}{}
\DeclareFontShape{EU1}{ukai}{m}{n}{ <-> "[ukai.ttc]"}{}

\newif\ifusecjk
%\usecjktrue % uncomment to use xeCJK and fail

\ifusecjk
 \usepackage[BoldFont,SlantFont]{xeCJK}
 \setCJKmainfont{ukai}
 \setCJKsansfont{ukai}
 \setCJKmonofont{ukai}
\fi
\begin{document}
\XeTeXlinebreaklocale "zh"\relax
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.5pt \relax
\ifusecjk\else
  \renewcommand\rmdefault{ukai}
  \fontencoding{\encodingdefault}\fontfamily{\rmdefault}\selectfont
\fi

危险
\end{document}
  • Go to this website packages.ubuntu.com/en/source/lucid/ttf-arphic-ukai and download the font ttf-arphic-ukai to your font directory in the system. This should make your problem go away. – Jesse Oct 9 '14 at 12:13
  • The font is in the same directory where the test file is located. The font file is found when xeCJK is not used. – olpa Oct 10 '14 at 7:11
  • No. I don't know what your system is. In my window system, I put the font into the \control panel\font directory, then it compiles fine. – Jesse Oct 10 '14 at 7:17
  • @jesse: even if you uncomment the line "\usecjktrue"? – olpa Oct 10 '14 at 7:27
  • NO, it compiles when \usecjktrue is commented out. It seems that I was directed to the issue of missing font file in the system. – Jesse Oct 10 '14 at 7:40
2

If you read Chinese, you should read the documentation of the xeCJK package.

The xeCJK package could access font file directly. That is, \DeclareFontFamily and \DeclareFontShape are superfluous here.

BTW, the package has already handled the line break issue. \XeTeXlinebreaklocale and \XeTeXlinebreaklocale are also superfluous.

According to your code, a minimal working example could be:

\documentclass{article}

\usepackage[BoldFont,SlantFont]{xeCJK}
\setCJKmainfont{ukai.ttc}

\begin{document}

Some latin letters
危险
Latin letters again
\end{document}
  • Thanks, your answer is very helpful to me. I got error because I didn't use the full file-name with extension, ukai.ttc – Yan King Yin Nov 16 '15 at 8:08
0

It seems that xeCJK uses \fontspec instead of \selectfont:

> \xeCJK@font@rm=macro:
->\fontspec [BoldFont={ukai},BoldFeatures={RawFeature={embolden=4}},ItalicFont=
{ukai},ItalicFeatures={RawFeature={slant=0.17}},BoldItalicFont={ukai},BoldItali
cFeatures={RawFeature={embolden=4,slant=0.17}}]{ukai}.
l.17 \show\xeCJK@font@rm

Quite expensive. With forced change to \selectfont I get what I need:

\documentclass{article}

\usepackage{polyglossia}% get "EU1"
\DeclareFontFamily{EU1}{ukai}{}
\DeclareFontShape{EU1}{ukai}{m}{n}{ <-> "[ukai.ttc]"}{}

\usepackage[BoldFont,SlantFont]{xeCJK}
\setCJKmainfont{ukai}
\setCJKsansfont{ukai}
\setCJKmonofont{ukai}

\begin{document}
\XeTeXlinebreaklocale "zh"\relax
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.5pt \relax

\makeatletter
\show\xeCJK@font@rm
\def\xeCJK@font@rm{\fontfamily{ukai}\selectfont}
\makeatother

Some latin letters
危险
Latin letters again
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.