Tag Archives: Chinese support

Three ways of latex supporting Chinese

Cjkutf8ctex’s utf8 option (I use) xelatex compilation

We know that latex generally uses CJK and CTeX macro package to support Chinese editing. The default encoding of CJK and CTeX is GBK, while the silent encoding under windows is GBK. Therefore, CJK and CTeX can directly support Chinese latex compilation without special configuration, just save the file with GBK encoding. But if the character encoding of the file is changed to UTF-8, which is more common now, how should it be operated? There are three ways to use it.

CJKutf8

CJK has two basic macro packages: CJK and cjkutf8. The latter is oriented to UTF-8 encoding, and its general usage is as follows:

\usepackage{CJKutf8}
\begin{document}
\begin{CJK}{UTF8}{}

\end{CJK}
\end{document}

%test.tex
\documentclass{article}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK}{UTF8}{gbsn}
This is an example of CJKutf8, and the font used is gbsn.
\end{CJK}
\end{document}

The output result can be obtained by compiling tex file with pdflatex.

Utf8 option of CTeX (I use it)

Cjkutf8 above only provides two kinds of fonts, so the choice is too small. We can directly use utf8 option to make CTeX support UTF-8 encoding. CTeX’s rich fonts and Chinese settings can better edit latex Chinese text, and its syntax format is as follows:

\documentclass[UTF8]{article}
\usepackage{CTEX}
\begin{document}

\end{document}

Or, use ctexart directly

\documentclass[UTF8]{ctexart}
\begin{document}

\end{document}

% ctex_test.tex
\documentclass[UTF8]{ctexart}
\begin{document}
This is a CTEX utf-8 encoding example, {\kaishu is shown here in italic}, {\songti is shown here in Song}, {\heiti is shown here in bold}, {\fangsong is shown here in imitation Song}.
\end{document}

Xelatex compilation

Xetex is a tex typesetting engine that uses Unicode. It supports Unicode natively and its input file is UTF-8 by default. Xetex can directly use fonts installed in the operating system without additional configuration. Xelatex is a typesetting engine that uses latex. It also has the advantages of xetex. If you use xelatex * *. Tex directly under the command, the corresponding PDF file will be generated. Here is a simple example of how to compile CTeX with xelatex (also save the Tex file in UTF-8 format)

% xelatex_test.tex
\documentclass{article}
\usepackage{CTEX}
\begin{document}
This is a CTEX utf-8 encoding example, {\kaishu is shown here in italic}, {\songti is shown here in Song}, {\heiti is shown here in bold}, {\fangsong is shown here in imitation Song}.
\end{document}

Mingyan’s students found that compared with the CTeX code in Item 2 above, this product lacks a utf8 option! Well, on the surface, it looks like this, but if you just put xelatex_ test.tex Compile with pdflatex, the system will report an error. This is because without the utf8 option, pdflatex silently processes the Tex file according to the GBK encoding, and this file is encoded with UTF-8, which will cause decoding failure. If you directly compile with xelatex, it will be compiled successfully, because the default input file of xelatex is UTF-8 encoding. Switch to the directory where the Tex file is located, and directly compile the Tex file with xelatex: xelatex xelatex_ test.tex The following output results can be obtained,