4

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.

  • 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 ;) – yo' 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
  • @manuzhang Do you see the problem on the very first run or only after more than one run? I wonder if changing the graphic type is simply co-incidental, and what you are actually seeing is an issue with the section name, which is not available in the .aux file in the first pass. – Joseph Wright Nov 12 '12 at 8:50
4

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>}
  • @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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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