1

2nd post on Stack Exchange, not 100% sure this is the correct place to post, but I'll move it if it needs to be moved.

I've been trying to learn how to type up my Chinese documents in LaTeX (I use ShareLaTeX), but almost nothing seems to work. Although I have all of the proper Chinese fonts installed on the computer, it continues giving me errors, even when I tried to run the document that ShareLateX itself used for an example.

Below are some documents and the errors/problems they cause.

\documentclass{article}
\usepackage{CJK}
\usepackage[utf8]{inputenc}

\begin{document}

\title{Title}
\author{Author}
\date{February 2015}


\begin{CJK}{UTF8}{gbsn}


你好\\
文章内容\\
Something\\
再见\\

\end{CJK}

\end{document}

This gives out a document that is the closest I've had to success, but it doesn't print out in proper formatting (namely, the Title, Author and Date are all absent) and it doesn't have the usual margins.

The next one was also stolen from an example

\documentclass{ctexart}

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

\begin{document}

\tableofcontents

\begin{abstract}
这是在文件的开头的介绍文字.本文的主要话题的简短说明.
\end{abstract}

\section{ 前言 }
在该第一部分中的一些额外的元素可以被添加。巴贝尔包将采取的翻译服务.

\section{关于数学部分}
在本节中的一些数学会使用数学模型含中文字符显示。

這是一個傳統的中國文字

\end{document}

It returns the following error messages and fails to compile. All issues are in main.tex unless otherwise stated

Compile Error
Undefined Control Sequence (line 3)
LaTeX Error: Missing \begin[document} (line 3)
Undefined Control Sequence (line 5)
Improper Alphabetic Constant (output.toc, line 1)
Missing = inserted for \ifnum (output.toc, line 1)
Missing number, treated as 0 (out..., line 1)
Bad character code (-30). (out..., line 1)
Undefined control sequence (line 12)
Package CJK Error: Invalid Character Code (line 12)
Undefined Control Sequence (line 15)
Undefined Control Sequence (line 15)
Undefined Control Sequence (line 16)
Undefined Control Sequence (line 16)
Undefined Control Sequence (line 19)
Undefined Control Sequence (line 21)
dfTeX error: pdflatex (file simsun.ttc): cannot open TrueType font file for reading

Optimally, I'd like to use the KaiTi font, but for now I'll just settle for being able to created a document in the first place. :)

LaTeX, ShareLaTeX, Chinese

4
  • Welcome to TeX.SX! you need \maketitle after the \date line in order for the top matter to be output. Feb 13, 2015 at 16:46
  • Thank you! In all of my other documents, I like to have my Date below my Author below my Title. How would I go about doing that if I put the \date line first? Thanks,
    – CBlumey
    Feb 13, 2015 at 16:49
  • the order of the items in the top matter is almost always determined by the document class being used; the content of the items is saved, and then output in the predetermined order by \maketitle, regardless of the order in which you input them. i believe the order you mention is the default for article. i'm not familiar with ctexart so i can't say anything about that. Feb 13, 2015 at 17:00
  • In the second example, maybe you need \usepackage{xeCJK}. I don't have ctexart.cls but the following works here for xelatex: \documentclass{article} \usepackage{xeCJK} \setCJKmainfont{simsun.ttc} \setCJKsansfont{simhei.ttf} \setCJKmonofont{simfang.ttf} \begin{document} ... \end{document} Feb 13, 2015 at 23:26

1 Answer 1

3

Compile it using XeLaTeX (default is pdfLaTeX). Took me waaay too long to figure this out.

To do this, go to the menu (top left corner), scroll down to Settings, change compiler from "pdfLaTeX" to "XeLaTeX". The instructions from ShareLaTeX's documentation should now work fine.

0

You must log in to answer this question.

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