最简单的做法是使用 ctex
宏包,再使用 XeLaTeX
或者 LuaLaTeX
编译,但是会出现警告:
| Font "FandolSong-Regular" does not contain requested Script "CJK"
|
为了消除这个警告,需要配置 Overleaf 上的中文字体,之后在主文件中指定 fontset 即可。
main.tex |
---|
| \documentclass[fontset=overleaf]{ctexart}
\usepackage{zhlipsum}
\begin{document}
\zhlipsum
\end{document}
|
ctex-fontset-overleaf.def |
---|
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 | % https://sikouhjw.gitee.io/2021/02/14/2021-02-14-fontset-overleaf/
\GetIdInfo$Id: ctex.dtx 81d4c90 2020-10-19 20:24:58 +0800 Qing Lee <sobenlee@gmail.com> $
{Overleaf fonts definition (CTEX)}
\ProvidesExplFile{ctex-fontset-overleaf.def}
{\ExplFileDate}{2.5.5}{\ExplFileDescription}
\ctex_fontset_case:nnnn
{ \ctex_fontset_error:n { ubuntu } }
{
\ctex_zhmap_case:nnn
{
\setCJKmainfont { :2:NotoSerifCJK-Regular.ttc }
[ BoldFont = :2:NotoSerifCJK-Bold.ttc, ItalicFont = gkai00mp.ttf ]
\setCJKsansfont { :2:NotoSansCJK-Regular.ttc }
[ BoldFont = :2:NotoSansCJK-Bold.ttc ]
\setCJKmonofont { :2:NotoSerifCJK-Regular.ttc }
[ BoldFont = :2:NotoSerifCJK-Bold.ttc ]
\setCJKfamilyfont { zhsong } { :2:NotoSerifCJK-Regular.ttc }
[ BoldFont = :2:NotoSerifCJK-Bold.ttc ]
\setCJKfamilyfont { zhhei } { :2:NotoSansCJK-Regular.ttc }
[ BoldFont = :2:NotoSansCJK-Bold.ttc ]
\setCJKfamilyfont { zhkai } { gkai00mp.ttf }
\ctex_punct_set:n { ubuntu }
\ctex_punct_map_family:nn { \CJKrmdefault } { zhsong }
\ctex_punct_map_family:nn { \CJKsfdefault } { zhhei }
\ctex_punct_map_family:nn { \CJKttdefault } { zhsong }
\ctex_punct_map_itshape:nn { \CJKrmdefault } { zhkai }
\ctex_punct_map_bfseries:nn { \CJKsfdefault, zhhei } { zhheib }
\ctex_punct_map_bfseries:nn
{ \CJKrmdefault, \CJKttdefault, zhsong }
{ zhsongb }
}
{
\ctex_load_zhmap:nnnn { rm } { zhhei } { zhsong } { ubuntu }
\ctex_punct_set:n { ubuntu }
\ctex_punct_map_family:nn { \CJKrmdefault } { zhsong }
\ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei }
\ctex_punct_map_itshape:nn { \CJKrmdefault } { zhkai }
}
{ \ctex_fontset_error:n { ubuntu } }
}
{
\ctex_set_upmap_unicode:nnn { upserif }
{ :2:NotoSerifCJK-Regular.ttc } { :2:NotoSerifCJK-Bold.ttc }
\ctex_set_upmap_unicode:nnn { upsans }
{ :2:NotoSansCJK-Regular.ttc } { :2:NotoSansCJK-Bold.ttc }
\ctex_set_upmap_unicode:nnn { upmono }
{ :2:NotoSansMonoCJK-Regular.ttc } { :2:NotoSansMonoCJK-Bold.ttc }
\ctex_set_upmap:nnn { upserifit } { gkai00mp.ttf } { }
\ctex_set_upfamily:nnn { zhsong } { upzhserif } { upzhserifb }
\ctex_set_upfamily:nnn { zhhei } { upzhsans } { upzhsansb }
\ctex_set_upfamily:nnn { zhfs } { upzhmono } { }
\ctex_set_upfamily:nnn { zhkai } { upzhserifit } { }
}
{
\setCJKmainfont { Noto~Serif~CJK~SC } [ ItalicFont = AR~PL~KaitiM~GB ]
\setCJKsansfont { Noto~Sans~CJK~SC }
\setCJKmonofont { Noto~Sans~Mono~CJK~SC }
\setCJKfamilyfont { zhsong } { Noto~Serif~CJK~SC }
\setCJKfamilyfont { zhhei } { Noto~Sans~CJK~SC }
\setCJKfamilyfont { zhkai } { AR~PL~KaitiM~GB }
\setCJKfamilyfont { zhfang } { FandolFang }
}
\NewDocumentCommand \songti { } { \CJKfamily { zhsong } }
\NewDocumentCommand \heiti { } { \CJKfamily { zhhei } }
\NewDocumentCommand \kaishu { } { \CJKfamily { zhkai } }
\NewDocumentCommand \fangsong { } { \CJKfamily { zhfang } }
%%
%%
%% End of file `ctex-fontset-overleaf.def'.
|