[Tex/LaTex] inserting png introduces inputenc error

input-encodingspdfpdftexpngunicode

I want to write an article in Chinese, which needs to insert pictures.

It's fine when I insert pictures as .pdf but the following problem occurs if .png is inserted:

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

That is a Chinese character.

I compile with pdflatex and here is the snippet that is related to the issue:

\documentclass[12pt, a4paper]{article}

\usepackage{listings}
\usepackage{graphicx}
\usepackage{CJKutf8}
\usepackage[bookmarks=true, unicode=true, colorlinks=true, linkcolor=blue]{hyperref}
\lstset{basicstyle=\large, showstringspaces=false}

\begin{document}
\begin{CJK}{UTF8}{gbsn}

\cleardoublepage
\pdfbookmark[1]{\contentsname}{toc}
\tableofcontents
\newpage

\section{实验设计}
\begin{figure}[ht]
\centering
\includegraphics[width=0.9\textwidth]{schema}
\end{figure}

...

schema is the picture name.

I have to work around this because the .pdf picture will take up the whole page.

Update:

It appears to me that the problem has nothing to do with inputenc package.
Although the problem seem to have been solved yesterday after I included the package, it has been weirdly compiling successfully even I exclude it (looking back, it's because I added more characters).

LaTeX complains again after I change the picture floating option, i.e.

\begin{figure}[!h]
\centering
\includegraphics[width=0.9\textwidth]{schema}
\end{figure}

Now I guess it's owing to the way Chinese characters mingle with pictures.

Something I forgot to mention thus far:

The problem appears on second run and the error is in the *.toc file and it goes away after \tableofcontents is commented out.

Any thoughts or solutions on this?

One more thing:

moving to xelatex has solved the problem to some extent. One more issue is the bookmark is not printed correctly in Chinese character. I've googled a lot but found no satisfactory solution yet. I'm afraid I have to move back if that cannot be handled.

Best Answer

It seems that the package inputenc is missing. Just add the line

\usepackage[utf8]{inputenc}

to the preamble.

Update:

The problem is in fact related to the generation of the table of contents, as reflected in the updated question. It seems that pdflatex does not read the *.toc files with proper encoding. A solution is to use xelatex. The following example compiles on my Linux installation.

\documentclass[11pt]{article}

\usepackage{xltxtra}
\usepackage{xunicode}
\usepackage{xeCJK}
\usepackage{fontspec}

\setCJKmainfont{SimHei}

\begin{document}

\tableofcontents

\section{汉语}

汉语.

重要!

\section{English}

English.

\end{document}

Bold Font

You need to pass the BoldFont option to xeCJK package, that is, \usepackage[BoldFont]{xeCJK}. This is not a real bold font, however, as it is composed from the main font.

You can specify which bold font you want in many ways. For instance,

\setCJKmainfont[BoldFont={<appropriate bold font>}]{<appropriate main font>}