5

A basic document with Chinese text works fine:

\documentclass{article}
\usepackage{CJKutf8}
\title{标题}
\begin{document}
    \begin{CJK}{UTF8}{gkai}
        \maketitle
        (text)
    \end{CJK}
\end{document}

When I add a table of contents and 1 section with Chinese text, it does not compile:

\documentclass{article}
\usepackage{CJKutf8}
\begin{document}
    \begin{CJK}{UTF8}{gkai}
        \tableofcontents
        \section{第一章}
        (text)
    \end{CJK}
\end{document}

Package inputenc Error: Unicode char \u 8:第 not set up for use with LaTeX.

When I create an index entry with Chinese text, it also does not compile:

\documentclass{article}
\usepackage{CJKutf8}
\usepackage{makeidx}
\makeindex
\begin{document}
    \begin{CJK}{UTF8}{gkai}
        (text) \index{nihao@ 你好 nihao}
        \printindex
    \end{CJK}
\end{document}

! Package inputenc Error: Unicode char \u 8:你 not set up for use with LaTeX.

See the inputenc package documentation for explanation. Type H for immediate help. ...

l.3 ...reak or to continue without it.} \GenericError {(inputenc)...

What am I doing wrong?

1 Answer 1

10

From package documentation CJKutf8.txt:

If you get the error message: `\CJK... undefined' or other `... undefined ...' messages and you can't find an error, try inserting \newpage, \clearpage, or \cleardoublepage (the latter for two-column printing) before saying \end{CJK} or \end{CJK*}. This can happen if LaTeX 2e writes headers, footers, or index entries (both \index and \printindex) of a page containing CJK characters after closing the CJK environment. ...

A similar error message from CJKutf8.sty (with the same solution) is

Package inputenc Error:
Unicode char \u 8: XXX not set up for use with LaTeX

So adding a \clearpage just before \end{CJK} in your code worked for me.

Alternatively, consider using the ctex package:

\documentclass{article}
\usepackage[UTF8]{ctex}

\begin{document}
        \tableofcontents
        \section{第一章}
        (text)
\end{document}

Or use xeCJK with XeLaTeX:

\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{STSong}

\begin{document}
        \tableofcontents
        \section{第一章}
        (text)
\end{document}
1
  • ctex package just simply add a \clearpage before \end{CJK*}. It is an old bug of CJK package for years and we have nothing more to do.
    – Leo Liu
    Nov 17, 2011 at 17:35

You must log in to answer this question.

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