Why this UTF-8 error is solved with a simple \clearpage
It happens when latex tries to typeset the page heading. This happens at page shipout time; if the CJK*
environment has ended before the last page ships out, the necessary definitions for doing the typesetting are gone, and you get this error.
You see this clearly if you add \errorcontextlines=99
to your document (outside the CJK*
environment please). Also, the problem goes away with \pagestyle{empty}
(same caveat), further supporting my diagnosis.
You have already found the proper workaround: Add \clearpage
where you did.
Edited to add this version of the workaround – with thanks to egreg in the comments:
\AtBeginDocument{\csname CJK*\endcsname{UTF8}{gbsn}}
\AtEndDocument{\clearpage\csname endCJK*\endcsname}
And then, of course, you remove the CJK*
environment from within the document body.
The problem is that the section command sets a header. The problem is that the the CJK environments ends before the header is typeset and so the chinese chars are no longer set up. Using \clearpage
makes the CJK-environment span two pages so that is is active when the header is typeset, but is clearly only a work-around. The second problem is that the book class headers are set with \Makeuppercase which can do a lot of harm (that's beside other the reason why the error message uses capitals).
\documentclass{book}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}} %no uppercase
\usepackage{CJKutf8}
\begin{document}
\begin{CJK*}{UTF8}{gbsn}
Some Chinese text.
一些中文
\section[\protect\begin{CJK*}{UTF8}{gbsn}一些中文\protect\end{CJK*}]
{一些中文}
Compiling this with pdflatex will generate the following common error:
%! PACKAGE INPUTENC ERROR: UNICODE CHAR \U8:Ɨ� NOT SET UP FOR USE WITH LATEX.
However, when a clearpage command is included at the end of the document
(i.e., to uncomment the line below), then the error will disappear and the
document compiles correctly.
%\clearpage % This is important; otherwise there will be a nasty UTF-8 error.
If we delete section command, the document also compiles correctly
(even without clearpage).
\end{CJK*}
\end{document}