Class files

LaTeX supports many worldwide languages by means of some special packages. In this article is explained how to import and use those packages to create documents in Chinese.

 Introduction

Chinese language needs a special document class since the encoding and fonts are quite unique. Please note that when using Chinese language fonts, you will need to compile the document in XƎLaTeX. See here to learn how to change the compiler in ShareLaTeX.

\documentclass{ctexart}

\setCJKmainfont{SimSun.ttf}
\setCJKsansfont{SimHei.ttf}
\setCJKmonofont{SimFang.ttf}

\begin{document}

\tableofcontents

\begin{abstract}

\end{abstract}

\section{ 前言 }

\section{关于数学部分}

\end{document}

The document type is a ctexart (Chinese TeX Article), this is the recommended manner of typing Chinese documents, but is not the only one and may have some limitations. The next sections will clearly explain these and other environments for Chinese LaTeX typesetting.

 Simplified Chinese with ctex classes

Modern computer systems allow you to input letters of national alphabets directly from the keyboard. In order to handle characters for Simplified Chinese typesetting you can use the ctex document classes: ctexart, ctexrep and ctexbook.

\documentclass{ctexart}

This document class is pretty much like babel, but for Chinese language. You will not only be able to typeset Chinese characters, but also define elements such as "Abstract" and the "Table of Contents" that will be properly translated. There's a drawback though: The additional parameters that can be passed to the document class definition, such as the paper size, are very limited. Nevertheless, you can define the document size, for instance, by means of the geometry package.

You can import external fonts to your document, either dowloading them to the same directory of your LaTeX file, as in the example, or using system-wide fonts. For instance, if the IPAGothic font is already installed on your system, you can use it in your document with.

\setCJKmainfont{IPAGothic}

Additional fonts for some parts of the document can be established. To set a specific font for elements that use sans font style use \setCJKsansfont{} and for elements that are displayed in monospace font, such as verbatim environments, use the command \setCJKmonofont{}. If external fonts are used your document must be compiled with XƎLaTeX.

Notice that the last line in the example at the introduction is actually using Traditional Chinese characters. This is accomplished by the SimSun font, used in this document, because this font includes them. So, with the right font, you can actually typeset your document in traditional Chinese, just keep in mind that automatic elements will be written with simplified symbols.

 Traditional and Simplified Chinese, the CJK package

As mentioned in the introduction, it's possible to typeset Chinese characters using other packages, you can also use Traditional and Simplified Chinese characters in the same document, you can even add Latin characters.

 XeLaTeX

Other easy way to create Chinese documents is by importing the xeCJK package and setting up your favourite font.

\documentclass{article}

\usepackage{xeCJK}

\setCJKmainfont{simsun.ttf}
\setCJKsansfont{simhei.ttf}
\setCJKmonofont{simfang.ttf}

\begin{document}

\section{前言}

\section{关于数学部分}

\vspace{0.5cm}

\end{document}

The command \usepackage{xeCJK} imports xeCJK, this package allows to use external fonts in your document, these fonts are imported using the same syntax explained in the previous section. Again, if the imported font includes traditional symbols these can be used.

In this case elements are not translated as in the previous example, but sometimes the final rendered document may look a bit more sharp. Also, you can use any document class you want (book, report, article and so on) so your document layout is not constrained to a single document type.

The xeCJK package only works when compiled with XƎLaTeX.

 pdfLaTeX

The CJTK package can also be used to generate a document with pdfLaTeX. You may not be able to use external fonts, but here you can use traditional and simplified characters as well as Latin characters. Perfect for documents in English with bits of Chinese text or vice-versa.

\documentclass{article}
\usepackage{CJKutf8}

\begin{document}

\begin{CJK*}{UTF8}{gbsn}

\section{前言}

\section{关于数学部分}

\end{CJK*}

\vspace{0.5cm} % A white space

\noindent
You can also insert Latin text in your document

\vspace{0.5cm}

\noindent
\begin{CJK*}{UTF8}{bsmi}

\end{CJK*}

\end{document}

The line \usepackage{CJKutf8} imports CJKutf8 which enables utf8 encoding for Chinese, Japanese and Korean fonts.

In this case every block of Chinese text must be typed inside a \begin{CJK*}{UTF8}{gbsn} environment. In this environment UTF8 is the encoding and gbsn is the font to be used. You can use gbsn or gkai fonts for simplified characters, and bmsi or bkai for traditional characters.