4

when I try to incorporate some Chinese characters into an article complied by Xelatex, something goes wrong. The Chinese characters don't show up. My code is as below,

\documentclass[12pt]{article}
\usepackage{CJKutf8}
\usepackage{fontspec}


\begin{document}
\begin{CJK}{UTF8}{bkai}
        \begin{titlepage}
    \centering
    {  經濟系  \\
Department 
    \centering
    \thispagestyle{empty}       
\end{titlepage}
\end{CJK}
\end{document}

Thanks for any help!

3
  • Missing character: There is no 經 in font [lmroman17-regular]:mapping=tex-text;!. (It's a bug / design flaw in (Xe)TeX that this is only logged to the log file, and cannot be made an error: see Getting xetex to complain when a character is missing.) You need to specify a font for those characters. (Also btw you have a missing }) Jun 23, 2017 at 6:19
  • But how can I specify a font?
    – Carl
    Jun 23, 2017 at 6:23
  • Basically the CJKutf8 package is not meant for XeLaTeX. Either you can remove \fontspec and compile with pdflatex, or remove the CJKutf8 package and maybe use xeCJK. I can post an answer that seems to work for me, but as I can't read Chinese I'm not sure if it's right :-) Have you seen this question? Jun 23, 2017 at 6:41

3 Answers 3

5

The main problem in the above is that the CJKutf8 package (and babel) are meant for pdflatex, not xelatex. Here is an absolutely minimal way of using (occasional) Chinese characters in XeLaTeX:

\documentclass{article}
\usepackage{fontspec}
\newfontfamily\cjkfont{Noto Sans CJK SC} % Or any appropriate font you have
\begin{document}
{\cjkfont 經濟系} Department
\end{document}

This produces:

Result

But if you're going to be writing a lot of Chinese you probably want to do a lot more, for which you can use the more sophisticated approaches described at the question How does one type Chinese in LaTeX?

3
  • Thanks for your help. But it return an error, Undefined control sequence. \newfontfamily\cjkfont
    – Carl
    Jun 23, 2017 at 7:12
  • @ChYh Are you sure you compiled the same file as above, and with xelatex? The command \newfontfamily is defined by the package fontspec, so after \usepackage{fontspec} you shouldn't have any problem using it. Jun 23, 2017 at 15:22
  • @ChYh Did it work? (If the above file doesn't compile you can edit the full output into the question.) Jun 26, 2017 at 3:23
0

In default the Chinese font is not set. You can simply use \documentclass{ctexart}, which help you set up fonts and many other stuff.

1
  • Please, can you add a minimal working example of the your solution?
    – Sebastiano
    Apr 5, 2020 at 10:53
0

You can also use the xeCJK package, though it requires the XeLaTeX engine. As in the answer from @ShreevatsaR, if the character is rarer, you may need to change the font.

\documentclass{article}

\usepackage{xeCJK}
\setCJKmainfont{Noto Sans CJK TC}

\begin{document}
This tests the traditional Chinese character 錄. 

It has Unicode ID 37636. 
\end{document}

On Overleaf, at time of writing, this example will only work with the font change line, as the default Chinese font is Fandol, which doesn't have 錄. Note the directive \setCJKmainfont instead of \setmainfont.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .