It turned to be not so trivial to setup Chinese for Latex in a Linux System. Hope this will help some souls.
CTEX Installation if not already
1 2 3 |
sudo tlmgr install -repository http://mirrors.concertpass.com/tex-archive/systems/texlive/tlnet ctex texdoc ctex #for more info |
Windows Fonts for Chinese
LaTeX 随笔漫谈(1)- LaTeX 下的中文支持总结 – 若为自由故 路径:~/texlive/texmf-local/tex/latex/local/mychinesefont.sty~ English: Top 10 LaTeX Fonts
Copy fonts from one of your Windows System
cp Windows font to /usr/share/fonts/mschinese The following is the list of my windows fonts:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
AdobeFangsongStd-Regular.otf AdobeFanHeitiStd-Bold.otf AdobeHeitiStd-Regular.otf AdobeKaitiStd-Regular.otf AdobeMingStd-Light.otf AdobeSongStd-Light.otf Dengb.ttf Dengl.ttf Deng.ttf fonts.dir fonts.scale mingliub.ttc msjhbd.ttc msjhl.ttc msjh.ttc msyhbd.ttc msyhl.ttc msyh.ttc simfang.ttf simhei.ttf simkai.ttf simli.ttf simplex_.ttf simsunb.ttf simsun.ttc simyou.ttf |
Note:
- 隶书和幼圆这两种字体Windows系统里没有,而在安装微软Office时会安装。 If you do not have it you can download the 6 fonts from here.
-
About Windows old and new
Adapted from here.
在字体定义文件 ctex-xecjk-winfonts.def 中,楷体和仿宋不是使用字体全名,而是使用字体文件名表示的。如楷书是: \setCJKfamilyfont{zhkai}{[simkai.ttf]} 之所以这样是因为在 Windows XP 中楷书和仿宋是 GB2313 字符集的,只有 6000 多个汉字,楷体字体全名是 KaiTiGB2312;而在 Windows Vista 以后和版本则是 GBK 大字库的,有 20000 多个汉字,字体全名是 KaiTi。为了避免为微软的不同操作系统版本写不同的配置文件(这样更麻烦,而且 Windows 用户是大多数),就把它直接用没有变化过的字体文件名表示。
-
字体族名
123456789fc-list -f "%{family}\n" :lang=zh-----------Times New Roman:style=Normal,obyčejné,Standard,Κανονικά,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,thường,Arrunta宋体,SimSun:style=Regular黑体,SimHei:style=Normal,obyčejné,Standard,Κανονικά,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta在 fontspec 或 xeCJK 中使用的字体族名是上面列表中冒号前的部分。例如可以使用
123\setmainfont{Times New Roman}\setCJKmainfont{SimSun} % 或者 \setCJKmainfont{宋体}fontspec 和 xeCJK 也可以使用字体的文件名访问字体。例如 Windows 下的宋体也可以使用命令:
12\setCJKmainfont{simsun.ttc}
Prep the Chinese fonts for Tex
1 2 3 4 5 6 7 8 |
chmod 644 * mkfontscale mkfontdir fc-cache -fsv mktexlsr texhash fc-list :lang-zh |grep kai |
Share Tex font for system-wide use
Assuming you have suitable privileges, proceed as follows. Copy the texlive-fontconfig.conf file to /etc/fonts/conf.d/09-texlive.conf.
1 2 3 |
sudo cp TEXMFSYSVAR/fonts/conf/texlive-fontconfig.conf /etc/fonts/conf.d/09-texlive.conf fc-cache -fsv. |
Generate Chinese documents with template ElegantPaper – Life Savior
ElegantLaTeX/ElegantPaper: Elegant LaTeX Template for Working Papers
使用LATEX工作室提供的方正字体 (https://pan.baidu.com/s/1BgbQM7LoinY7m8yeP25Y7Q),提取码为:njy9进 行安装。
copy cls file to file:///home/tan/texlive/texmf-local/tex/latex/local/elegantpaper.cls. Verify fine the tex file can produce pdf.
Incorporate into a org-mode as a org-latex classes Export Org-mode in Chinese to PDF with custom latex class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
(with-eval-after-load 'ox-latex ;; http://orgmode.org/worg/org-faq.html#using-xelatex-for-pdf-export ;; latexmk runs pdflatex/xelatex (whatever is specified) multiple times ;; automatically to resolve the cross-references. (setq org-latex-pdf-process '("latexmk -xelatex -quiet -shell-escape -f %f")) (add-to-list 'org-latex-classes '("elegantpaper" "\\documentclass[lang=cn]{elegantpaper} [NO-DEFAULT-PACKAGES] [PACKAGES] [EXTRA]" ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))) (setq org-latex-listings 'minted) (add-to-list 'org-latex-packages-alist '("" "minted"))) |
change options in org-mode:
1 2 3 4 5 6 |
#+LATEX_CLASS: elegantpaper #+LATEX_CLASS_OPTIONS: [lang=cn,chinesefont=founder] #+LATEX_COMPILER: xelatex #+OPTIONS: prop:;TODO: #+LATEX_CLASS_OPTIONS: [lang=cn,chinesefont=founder] |
In my case, it works with chinesefont=founder, or no setting. It does NOT work with modified nofont setting 字体设置 · ElegantLaTeX/ElegantPaper Wiki.
Cross your finger and pray hard
In my case, the windowsnew and ubuntu config file is working without any modification needed; but I have no luck with adobe and fandol fonts.
Test it out
1 2 3 4 5 6 7 8 |
\documentclass[fontset = none]{ctexart} \ctexset{fontset = windowsnew} \begin{document} \huge 在文档类选项中声明 \verb|fontset = none|,随后在导言区用 \verb|\ctexset| 指定字体。 \end{document} |
OCT
About the Author:
Beyond 8 hours - Computer, Sports, Family...