LaTeX安装和配置(mac平台)

LaTeX安装和配置(mac平台)

准备写人工智能领域的论文了,安装配置一下LaTeX。

主要是mactex的安装以及vscode的配置。

LaTeX(LATEX,音译“拉泰赫”)是一种基于TEX的排版系统,由美国计算机学家莱斯利·兰伯特(Leslie Lamport)在20世纪80年代初期开发,利用这种格式,即使使用者没有排版和程序设计的知识也可以充分发挥由TeX所提供的强大功能,能在几天、甚至几小时内生成很多具有书籍质量的印刷品。对于生成复杂表格和数学公式,这一点表现得尤为突出。因此它非常适用于生成高印刷质量的科技和数学类文档。这个系统同样适用于生成从简单的信件到完整书籍的所有其他种类的文档。

下载mactex

官网下载(使用迅雷):https://www.tug.org/mactex/

清华镜像站:https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/mac/mactex/

安装mactex

安装完毕后launchpad会出现两个app,LaTeXiT是配置用的,TeXshop是编辑器。

不过自带的编辑器TeXshop过于简陋,故而使用VScode来配置LaTeX写作环境。

查看文档

安装完成后就可以使用以下命令来查看中文的LaTeX简明文档了(一百多页)。

1
texdoc lshort-china

然后另存到常用目录下。

使用vscode

安装插件

  1. LaTeX workshop
  2. LTex

配置settings.json

vscode在settings.json文件中添加:

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOC%"
]
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
{
"name": "xelatex",
"tools": [
"xelatex"
]
},
{
"name": "latexmk",
"tools": [
"latexmk"
]
},

{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
{
"name": "xelatex->bibtex->xelatex->xelatex",
"tools": [
"xelatex",
"bibtex",
"xelatex",
]
}
],

"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk"
],


//下面这段是语法检查模块
//{
"ltex.enabled": true, // 启用插件
"ltex.language": "en-US",// 设置语言,这里是德语
// 要英语就下载对应 English Support,然后这里填 en, 或者 en-US,en-GB 等*/
"ltex.de.dictionary": ["Niubility", "Zhihu"],
//注意根据要对应语言,ltex.<LANGUAGE>.dictionary
"ltex.environments.ignore": [
"lstlisting",
"verbatim"
],
"ltex.commands.ignore": [
"\\documentclass[]{}",
"\\renewcommand*{}[]{}"
],
//}语法检查功能在这里结束
}

如果需要配置skim(在skim设置中的sync标签下,PDF-TeX Sync support下的preset选择vscode即可。),则settings.json添加如下配置:

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
{
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOC%"
]
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
{
"name": "xelatex",
"tools": [
"xelatex"
]
},
{
"name": "latexmk",
"tools": [
"latexmk"
]
},

{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
{
"name": "xelatex->bibtex->xelatex->xelatex",
"tools": [
"xelatex",
"bibtex",
"xelatex",
]
}
],

"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk"
],


//下面这段是语法检查模块
//{
"ltex.enabled": true, // 启用插件
"ltex.language": "en-US",// 设置语言,这里是德语
// 要英语就下载对应 English Support,然后这里填 en, 或者 en-US,en-GB 等*/
"ltex.de.dictionary": ["Niubility", "Zhihu"],
//注意根据要对应语言,ltex.<LANGUAGE>.dictionary
"ltex.environments.ignore": [
"lstlisting",
"verbatim"
],
"ltex.commands.ignore": [
"\\documentclass[]{}",
"\\renewcommand*{}[]{}"
],
"editor.fontSize": 18,
//}语法检查功能在这里结束



"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.synctex.command": "/Applications/Skim.app/Contents/SharedSupport/displayline",
"latex-workshop.view.pdf.external.synctex.args": [
"-r",
"%LINE%",
"%PDF%",
"%TEX%"
],
"latex-workshop.view.pdf.external.viewer.command": "/Applications/Skim.app/Contents/MacOS/Skim",
"latex-workshop.view.pdf.external.viewer.args": [
"%PDF%"
],


}

使用sublime text

安装插件

安装插件:LaTeX Tools

设置skim支持

在skim设置中的sync标签下,PDF-TeX Sync support下的preset选择sublime text即可。

开始写LaTeX

新建扩展名为.tex的文档就可以开始写LaTeX了。

1
touch article.tex

使用XeLaTeX编译

为了解决pdfLaTeX无法支持中文的问题,需要在Tex文档头部加上:

1
2
%!TEX program = xelatex
\usepackage[UTF8]{ctex}

编译的时候也要选择XeLaTeX。

sublime text使用cmd + B即可编译。

随机弹出pdf预览(需要完成设置skim)。

使用shift + cmd并点击skim中的内容可以跳至sublime text对应代码。

使用Texpad

Texpad是一款mac平台的LaTeX编辑器,使用起来更为专注和方便。

关键在于不用配置,省心。

测试

1
2
3
4
5
6
7
8
9
10
11
12
%!TEX program = xelatex
\usepackage[UTF8]{ctex}
\documentclass{article}
\usepackage{fontspec, xunicode, xltxtra}
\setmainfont{Hiragino Sans GB}
\title{标题}
\author{}
\begin{document}
\maketitle{}
\section{段落}
内容,内容,内容,内容,内容,内容,内容,内容,内容,内容,内容,内容。
\end{document}

效果:
preview

LaTeX辅助工具

  1. LaTeX官方中文文档:https://gcore.jsdelivr.net/gh/herotiga/cdn/pdf/lshort-zh-cn.pdf
  2. 妈咪叔LaTeX帮助文档:https://latexlive.com/help
  3. mactex官网:https://www.tug.org/mactex/
  4. LaTeX公式编辑器:https://latexlive.com/
  5. xFormula(mac):https://apps.apple.com/cn/app/id1477136751
  6. LaTeX表格代码生成器:https://www.tablesgenerator.com/
  7. 网页版LaTeX:https://www.overleaf.com/

评论