# Turning Chinese line breaks on and off

I am typesetting a document in Chinese with spaces between words, for the purpose of making it easier for learners. Because of this, I am typesetting most of my document with no line-breaks between words. Because Chinese words are generally pretty short, this will generally not cause any big problems.

However, in some parts of my document, I will need to use Chinese line breaks, as defined by \XeTeXlinebreaklocale "zh" (or similar) to avoid over-filled boxes. Basically, those are regular paragraphs of Chinese text, which will not break at all without this option turned on. However, this appears to be a document specific parameter that I can not easily change in only parts of the document.

Any ideas for how I can deal with this problem?

I added to my comment below that I would like to type Chinese text without spaces, as "我喜欢学中文", in which case line breaks would use a Chinese locale, as well as space delimited Chinese (non-standard) "我 喜欢 学 中文", in which case no line breaks are allowed in the middle of words (or possibly only allowed with very high tolerance).

If I just turn on \XeTeXlinebreaklocale "zh" (or use a CJK package, I believe), all words will be broken according to Chinese rules, in which case I risk getting the "中文" in "我 喜欢 学 中文" broken over two lines.

If you use more than one paragraph Chinese, use our xeCJK package.

For totally Chinese document, use our documents or packages in ctex bundle. It is based on xeCJK.

I have explained this topic in a previous question:

How does one type Chinese in LaTeX?

Of course xeCJK solve the problem about line breaking. You don't need \XeTeXlinebreaklocale with xeCJK; and xeCJK does not change the \XeTeXlinebreaklocale either.

You don't need to care about the line break locale if you use

\XeTeXlinebreaklocale "zh"


it does nothing to do with western languages as far as I know. Similarly, using xeCJK you also don't need to turn off it. Non-CJK text would be untouched. With xeCJK, it is much easier to set the fonts for Chinese without changing western texts, and you'll get better result for puncuations.

For completeness only, I'll say that you can use \makexeCJKactive and \makexeCJKinactive to turn on and off the functions of xeCJK.

Note: xeCJK is not completely compatible with polyglossia package for some of the languages. If you meet more problems, ask more questions or contact me. (I am currently the main maintainer of xeCJK.)

For updated question, see this previous question:

How to write spaces between Korean words with XeCJK?

You can use space and nospace options in xeCJK, and \CJKspace and \CJKnospace option, just like CJK package do.

I think it is not suggested to suppress line breaks between Chinese characters even if you use \CJKspace to allow spaces between Chinese characters. If you insist, you can change the definition of \CJKglue to empty. You can read the document of xeCJK if you are not sure about the options and commands.

After all, an example:

\documentclass{article}
\usepackage{xeCJK}[2011/05/20]
\setCJKmainfont{SimSun}
\begin{document}

\CJKspace

\end{document}

• Please note that I would like to typeset Chinese next both with and without line breaks within words. E.g. space-delimited Chinese text of the type "我 喜欢 学 中文" should never line-break at all within words, while another paragraph with the tex "我喜欢学中文" should use regular Chinese line breaks. Does the CJK package cover this situation? – Carl Johan Feb 7 '12 at 1:08
• @Carl: Sure. You can use space option in xeCJK, or use \CJKspace and \CJKnospace to turn on and off this feature. See this: How to write spaces between Korean words with XeCJK? – Leo Liu Feb 7 '12 at 10:12