Visual Studio Code 配置 LaTex | 笔记

1. 安装 TeX Live

1.1 下载

这里选择下载 iso 镜像包

1.2 安装配置

改位置 高级 便携式 便携式切换完成 取消勾选安装 TeXworks ,这个编辑器太老,使用 VSCOde 即可 可选择语言包(这里默认,不进行设置) 安装很慢,耐心等待,很多小文件包,目测安装不需要网络,大概花了1小时30分钟左右

1.3 配置 Windows 环境变量

经过测试,发现安装后,并不会自动配置环境变量,需要自己手动配置 设置环境变量 路径如下
1
D:\Program Files\texlive\2022\bin\win32

1.3 测试

1
2
3
4
tex -v
latex -v
xelatex -v
pdflatex -v
2. 安装 VSCode 扩展: LaTeX Workshop Visual Studio Code Marketplace

2.1 VSCode 设置

参考: Settings - Install · James-Yu/LaTeX-Workshop Wiki 注意: 实测,此步可省,直接使用也可以 VSCode 设置

参考设置 示例1

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
"latex-workshop.view.pdf.viewer": "tab",
"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"
]
}
],
"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"
]

参考设置 示例2

参考: https://pastebin.com/wmkTDxv7
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
"latex-workshop.latex.tools": [
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"-outdir=%OUTDIR%",
"%DOCFILE%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
{
"name": "PDFLaTeX",
"tools": [
"pdflatex"
]
},
{
"name": "XeLaTeX",
"tools": [
"xelatex"
]
},
{
"name": "BibTeX",
"tools": [
"bibtex"
]
},
{
"name": "LaTeXmk",
"tools": [
"latexmk"
]
},
{
"name": "xelatex -> bibtex -> xelatex*2",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
},
{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}
],
"latex-workshop.latex.recipe.default": "lastUsed",
3. LaTex 的编译测试 在本地新建一个文件夹并新建一个 .tex 结尾的文件,例如新建一个 test-latex.tex 文件,文件内容如下:
test-latex.tex
1
2
3
4
5
6
7
8
\documentclass[a4paper, 11pt]{article}
\title{This is a Title}
\author{yiyun}
\date{\today}
\begin{document}
\maketitle
This is the context of the article.
\end{document}
Q&A 补充

中文字符 编译失败

参考: 【LaTeX】环境配置以及中文支持 - 简书 Chinese - Overleaf, 在线LaTeX编辑器

方法1: LuaLaTeX + {ctexart}

示例1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
\documentclass{ctexart}

\begin{document}

\tableofcontents

\begin{abstract}
这是简介及摘要。
\end{abstract}

\section{前言}

\section{关于数学部分}
数学、中英文皆可以混排。You can intersperse math, Chinese and English (Latin script) without adding extra environments.

這是繁體中文。

\end{document}

示例2

1
2
3
4
5
6
7
8
\documentclass[a4paper, 11pt]{ctexart}
\title{中文标题}
\author{yiyun}
\date{\today}
\begin{document}
\maketitle
这是文章内容
\end{document}

中英文问题

参考: 来打造一个舒适的Latex环境吧~_短短的路走走停停的技术博客_51CTO博客 如果你写英文的话,推荐用pdfTeX(因为现在很多外文期刊用的都是pdfTeX程序编译)。 写中文的话,推荐用XeTeX,就这么简单咯。 来自 @梦飞翔

推荐模板

@梦飞翔 写笔记 推荐 elegant book/note 系列模板 @云游君 elegant 可以 我课程论文也是用的这个

1. ElegantLaTeX

ElegantLaTeX 参考 感谢帮助! Install · James-Yu/LaTeX-Workshop Wiki 重要 Windows下使用VSCode + LaTeX Workshop + Tex Live搭建LaTex编译环境_wangqingchuan92的博客-CSDN博客 LaTeX快速入门指南 | 文艺数学君