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.

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.

share|improve this question
2  
Have you tried to use \usepackage[utf8]{inputenc} as well? –  guillem Nov 12 '12 at 6:46
    
@guillem Wow, that works! But how could the format of picture affect the unicode parsing? –  manuzhang Nov 12 '12 at 7:42
    
@guillem Make you comment into an answer, because it seems to be the correct answer ;) –  tohecz Nov 12 '12 at 8:05
    
@manuzhang: does it work when no picture is added? it looks like the parser does not know what to do when it reads the first hanzi. I can't explain why png does not work in your case, I did not have issues including jpg pictures in a beamer presentation with hanzi in it. –  guillem Nov 12 '12 at 8:45
    
@tohecz: done, thanks for reminding ;) –  guillem Nov 12 '12 at 8:45
show 10 more comments

1 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>}
share|improve this answer
    
thanks! all compiles fine except the Chinese bookmark –  manuzhang Nov 13 '12 at 11:10
    
@manuzhang Oh! Now that you mention it, I recall having some issues with bookmarks also; don't remember if I solved it, though. Will take a look. –  guillem Nov 13 '12 at 11:36
    
another thing is that \textbf doesn't affect Chinese character –  manuzhang Nov 13 '12 at 12:00
    
@manuzhang see updated answer –  guillem Nov 13 '12 at 13:49
add comment

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.