SUMMARY OF CTEX LEARNING -- CTEX小结(.cls与.sty文件的编写)

1. How to write .cls & .sty file:

1.1 Difference between CLASS file and STYLE file in CTEX:

Class file (.cls) is used to define document classes with definitions of page margin, document style, and various options that user can pass to the class to configure the structure of this kind of document. For instance, the built-in classes include article, book, report, etc.

Style file (.sty) is used to define a kind of style, such as the font and size of book title, title of each section and subsection, the space between lines.

The golden rule you should obey to decide whether it should be a class or a style goes as follows:

If the commands could be used with any document class, then make
them a package; and if not, then make them a class.

1.2 How to write a CLASS

The class file composed of mainly four sections: Identification, Resources Required, Option Declaration, and Style definition.

1.2.1 Identification

Identification is used as an ID for the class you are about to compose.
the very command used here is:
\ProvidesPackage {package_name} [<date> <introduction>]

e.g. \ProvidesPackage{digilentTrans}[2010/06/09 Translation Template]

1.2.2 Load a Package

We can use function “\RequirePackage” to load a style package or use “\LoadClass” to load a class file.
\documentclass is also available here, so that we can refer to external files for document properties.

1.2.3 Option Declaration

It is recommended to use function “\DeclareOption [option_name] {function}”
Here, we can specify the function when certain option is passed to this class. Moreover, we may pass the option to the class package we are about to load. The function “\PassOptionsToClass” helps in this situation.

We may use \DeclareOption* to define the default behavior when certain option is passed onto this class.

1.2.4 Style Definition

Style definition usually means define or redefine a series of macros to modify the character, paragraph, document attributes. We may redefine “\title” function to change the position, font, style, size, color, etc. of the title.

If the command is new, it is recommended to use “\newcommand [command_name] [<num>] {function}”
where <num> is the number of parameters the command can take. In “function” part, “#1” stands for the first variable, “#2” the second, and so on. if the command has been defined in the package included or by default, we should use \renewcommand. If we want to access the old command in renewed command, we should write “\gdef \@command_name \par”

2. Problems concerning Chinese characters in CTEX

2.1 Commands of CTEX

CTeX is the package that support Chinese characters. You may type “$ ctex” under command line to see the options.

It is better to use “-pdflatexmx” while using chinese characters, as italic style is not available for chinese characters if you use other options.

2.2 Chinese Characters

CTeX includes a package for chinese characters called “CJK”. There are other packages for Chinese characters, while CJK is the one commonly used and is default in CTeX classes.

To use a CJK package, you should first include CJK in your .tex file as follows:
\include {CJK}

To use CJK font in document, before the text you may write:
\begin {CJK*} {GBK} {song}

This command stands for using CJK package GBK character map, font SongTi.
in GBK, the following fonts are available: song – SongTi, hei – HeiTi, kai – KaiTi, fs – FangSong.

We can use GB instead of BGK. Here we have more fonts:
gcfang – FangSong, gckai – KaiTi, gchei – HeiTi, gcsong – SongTi, gcwei – WeiBei, gchw – ZongYi, gcdls – LiShu.

\bfseries stands for bold style, \textsl stands for italic style.

2.3 CTEX classes

CTEX provides several document classes that support Chinese Language. ctexart is the article class with chinese support, ctexbook is the book class with Chinese support, ctexreport is the report class with chinese support. It is more convenient to use these classes while writing chinese documents. the reference for CTeX can be found at

(Please include a link to this page while coping this article to other website or forum, Thanks!)



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s