💡 参考文章见Ref,感谢提供思路!
🗺️当前这篇博文地址:https://myoontyee.github.io/article/485df768.html
⚠️警告:博客文章禁止一切形式的非授权非法转载!
⚠️Attention: All forms of unauthorized illegal reposts are prohibited !

创建时间:2022年4月25日11:31:01
最新更新:2022年4月26日09:53:09


Problem Description:WSL2 + Visual Studio Code + LaTeX configuration tutorial

核心思路

  • TeX Live
  • 同步字体
  • Visual Studio Code里装拓展LaTeX Workshop
  • 配置拓展
  • 做测试

环境

  • Windows 10 21H2
  • WSL 2
  • Ubuntu 20.04 LTS on Windows
  • Visual Studio Code 1.66.2
  • TeX Live 2022
  • LaTeX Workshop v8.25.0

安装Tex Live

  • 进入华为云镜像,选install-tl-unx.tar.gz这个安装

  • 下载下来以后,先解压这个install-tl-unx.tar.gz,得到install-tl-20220424这样一个文件夹

    • 根据你下载的版本不同,后面的数字也会不同
  • 然后打开bashWSLbash),进对应目录(解压install-tl-unx.tar.gz的目录,这里是进入到install-tl-20220424里头)

  • bash内输入如下指令进行在线安装

    • 看到下图信息后,输入I,按回车
1
./install-tl -repository https://mirrors.huaweicloud.com/CTAN/systems/texlive/tlnet/
  • 添加到环境变量,在bash内输入如下信息

    • 先进/usr/local/texlive看看下面的数字文件夹是啥,我装的是2022版本所以是2022
1
2
cd /usr/local/texlive/2022/bin/x86_64-linux
./tlmgr path add
  • bash内输入如下信息安装缺少的库+更新
1
2
apt-get install build-essential
tlmgr update --self --all

同步字体

  • bash内输入如下指令安装fontconfig
1
apt install fontconfig
  • 创建本地配置,在bash内输入如下指令
1
vi /etc/fonts/local.conf
  • 配置写入,在上一步操作完成后把下面信息复制粘贴进去
    • 然后ESC:wq保存
1
2
3
4
5
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/mnt/c/Windows/Fonts</dir>
</fontconfig>
  • bash内输入如下指令刷新字体缓存
1
fc-cache -fv

WSL + Visual Studio Code安装插件

  • 先在对应目录打开Remote - WSL,启动WSL环境,后在拓展中找到LaTeX Workshop安装

Visual Studio Code配置

  • Visual Studio Code内按F1,输入setjson,选择打开设置(json)

    • F1这个快捷键冲突的话,就按Ctrl+Shift+P
  • "latex-workshop.intellisense.biblatexJSON.replace": {},语句下方添加如下语句,然后保存

    • 注意一定要在最外侧的大括号{}内添加
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.latex.tools": [
{
"name": "texify",
"command": "texify",
"args": [
"--synctex",
"--pdf",
"--tex-option=\"-interaction=nonstopmode\"",
"--tex-option=\"-file-line-error\"",
"%DOC%.tex"
]
},
{
// 编译工具和命令
"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": "PDFLaTeX",
"tools": [
"pdflatex"
]
},
{
"name": "XeLaTeX",
"tools": [
"xelatex"
]
},
{
"name": "latexmk",
"tools": [
"latexmk"
]
},
{
"name": "BibTeX",
"tools": [
"bibtex"
]
},
{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
{
"name": "xelatex -> bibtex -> xelatex*2",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
}
],

做个测试

  • Visual Studio Code的项目文件夹内新建一个test.tex,输入以下内容,然后Build LaTeX project,再View LaTeX PDF file
    • Build LaTeX project是下图那个绿色三角形
    • View LaTeX PDF file是下图绿色三角形旁边那个
  • 得到如下图所示图像时,表示配置成功!
1
2
3
4
5
6
%! TeX program = pdflatex
\documentclass{article}

\begin{document}
press ctrl+b to complie, press ctrl+alt+v to view pdf
\end{document}

Ref