This is one of the easiest ways to type Chinese characters in LaTeX on Mac, using the default TeXShop editor. (If you know of an easier way, please let me know in the comments below!)
I have tried for hours, experimenting with different packages, before “discovering” the following steps. Hope it helps!
Step 1) Add “\usepackage{ctex}” to the beginning of the document. This will load the main package ctex.
Step 2) It is very important to save the LaTeX file in UTF-8 format, otherwise all Chinese characters will appear as question marks. The preferred way to do this is via:
TeXShop > Preferences > Encoding = Unicode (UTF-8). (see image below)
This will “permanently” set the format as UTF-8 by default. If you don’t do this, an annoying thing that can happen is that your TeX file reverts to “non-UTF8” upon saving. That means, the Chinese characters may appear correctly at first, but once you re-save the file, all Chinese characters become question marks again.
Alternatively, if you don’t want to set UTF-8 as default, you may add the following line to the very first line of the TeX document:
% !TEX encoding = UTF-8 Unicode
This will make TeXShop remember to save it in UTF-8 format every time.
Step 3) Just type Chinese characters directly into the LaTeX file. No “wrapper” is needed around the Chinese characters.
Step 4) When you compile the document, be sure to compile it by XeLaTeX. You can select this option next to the “Typeset” button. If you compile it using normal LaTeX, you will get the following error:
“Critical ctex error:”fontset-unavailable
CTeX fontset `fandol’ is unavailable in current mode.”
For Windows users, I suppose the above steps still work. I have not tried it personally though. Other packages may work only for Windows/Mac specifically since each system have different preloaded Chinese fontsets.
Hyperref Problems with Chinese TeX
A known problem is that hyperref does not work well with xetex or xeLaTeX. This may be a problem if you are using xeLaTeX in conjunction with Hyperref. The proposed solution is to use the option
\usepackage[xetex]{hyperref}
Note that if you have multiple options for hyperref, xetex should be the first of all the options.
TeXShop opens Chinese documents showing Gibberish
This is quite common, especially if your Mac or Windows system is not set with Chinese as primary language. A proposed solution (there may be a better solution) is to:
- Set the primary language of your Mac / Windows as Chinese. The entire system, including all your taskbars, icons should be in Chinese.
- Open the TeX file containing Chinese characters with Notepad/TextEdit, not TeXShop. Ideally, the Chinese characters should display ok there.
- Copy and paste the entire file from NotePad to TeXShop.
- Add the line % !TEX encoding = UTF-8 Unicode at the start of your TeX document to ensure that the Chinese characters will continue to stay there after closing of the document.
Reblogged this on Math Online Tom Circle.
LikeLike