Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

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}
share|improve this answer
    
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 '11 at 17:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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