5

What do I need to write documents in a CJK language? I'm getting no linebreaks at all on Japanese text. (overfull hboxes, text going off-page)

Here is a (mostly) stripped-down test:

\documentclass[a4paper]{article}

\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage{CJK}

\defaultfontfeatures{Mapping=tex-text}
\setmainfont[Mapping=tex-text]{VL Gothic}

\begin{document}
\begin{CJK}{UTF8}{VL Gothic}
すべての人間は、生れながらにして自由であり、かつ、尊厳と権利とについて平等である。人間は、理性と良心とを授けられており、互いに同胞の精神をもって行動しなければならない。
\end{CJK}
\end{document}

I'm not sure I'm using the CJK package correctly -- it seems to make no difference. What am I doing wrong?

I am using XeLaTeX.

2
  • This was supposed to have the tags: cjk japanese, but I'm not allowed to create new tags.
    – hhaamu
    Jan 10, 2011 at 20:26
  • I have added a {cjk} tag. I don't think a {japanese} tag is needed, as we don't have any tags for other languages either.
    – Caramdir
    Jan 10, 2011 at 22:38

2 Answers 2

3

Use xeCJK instead if you're using XeLaTeX. Also, use \setCJKmainfont for VL Gothic, reserving \setmainfont for selecting a font for non-CJK characters. The CJK environment is not required when using xeCJK.

The following works for me:

\documentclass[a4paper]{article}

\usepackage{xeCJK}

\setmainfont[Mapping=tex-text]{Helvetica}
\setCJKmainfont{VL Gothic}

\begin{document}
This is some English text.
すべての人間は、生れながらにして自由であり、かつ、尊厳と権利とについて平等である。人間は、理性と良心とを授けられており、互いに同胞の精神をもって行動しなければならない。
\end{document}
2
  • 1
    Is that a minimal setting for CJK languages?
    – yannisl
    Jan 11, 2011 at 1:31
  • 1
    @Yiannis As a matter of fact, fontspec, xunicode and xltxtra are not required. I've edited my answer accordingly.
    – imnothere
    Jan 11, 2011 at 11:44
2

You should not combine CJK with XeLaTeX. CJK is designed for LaTeX, you need to install the fonts for TeX system, which is not very easy. xeCJK is a xe-version of CJK, used mainly by simplified Chinese.

XeLaTeX support instinct CJK fonts itself. xeCJK is of course more sophiscated.

\documentclass[a4paper]{article}%save as utf-8, run xelatex
\usepackage{fontspec}

\setmainfont[Mapping=tex-text]{MS P明朝}%I changed the font
\XeTeXlinebreaklocale "ja" % linebreak, otherwise all will in one line
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt  

\begin{document}
すべての人間は、生れながらにして自由であり、かつ、尊厳と権利とについて平等である。人間 は、理性と良心とを授けられており、互いに同胞の精神をもって行動しなければならない。

\end{document} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .