LaTeX supports many worldwide languages by means of some special packages. This article explains how to typeset Chinese documents on Overleaf.

# Introduction

The recommended approach is to use the XƎLaTeX or LuaLaTeX compilers, as they support UTF-8 directly and allows more flexibility to work with TrueType and OpenType fonts. See this article to learn how to change the compiler in Overleaf.

\documentclass{ctexart}

\begin{document}

\tableofcontents

\begin{abstract}

\end{abstract}

\section{前言}

\section{关于数学部分}

\end{document}


The ctexart document class here is provided by the ctex bundle, which implements common Chinese typesetting practices. We discuss further details about the ctex classes below.

# The ctex Bundle 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, ctexbook and ctexbeamer.

\documentclass{ctexart}


The ctexart class (and other ctex classes) provides Chinese localisation, much like babel. 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 as 摘要 and 目录.

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

\setCJKmainfont{BabelStone Han}


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{}. You can refer to the list of Chinese fonts available on Overleaf here.

Notice that the last line in the example at the introduction is actually using Traditional Chinese characters. This is accomplished by the Fandol font (the default) because this font includes them. So, with the right font, you can actually typeset your document in both simplified and traditional Chinese. If you use a traditional- or simplified-only font, though, then characters whose glyphs are not available would not show up in the output PDF.

You may sometimes be using a different document class e.g. memoir or a thesis .cls provided by your university, but would still like like to use the ctex bundle. You can load the ctex package in this case:

\documentclass{UniThesis}
\usepackage{ctex}


# xeCJK with XeLaTeX

If the complete localisation ctex classes and package feels like an overkill and you just want to typeset some Chinese characters, you can use the xeCJK package.

\documentclass{article}
\usepackage{xeCJK}
\begin{document}

\section{前言}

\section{关于数学部分}

\end{document}


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

# CJKutf8 with pdfLaTeX

The CJKutf8 package can also be used to generate a document with pdfLaTeX. Chinese (and Japanese/Korean) text must be placed inside a CJK environment, so this is usually only convenient 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*}

\bigskip  %% Just some white space

You can also insert Latin text in your document

\bigskip  %% Just some white space

\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 bsmi or bkai for traditional characters.