本人手头电脑是Win10 Home版全新安装的系统,由于不想在新系统盘里面安装TexLive导致固态硬盘不断扩大,所以,考虑安装Ubuntu做为WSL,然后把TexLive安装在Ubuntu,并通过VS Code调用Ubuntu命令来写Latex的方法来写一些论文。在此,提供一个思路给大家借鉴。
Windows 10安装WSL2和Ubuntu 18.04
这个过程其实直接参照微软的标准过程就可以了,大致步骤总结如下:
- 去控制面板开启Virtual Machine Platform和Windows Subsystem for Linux(WSL)
- 在Win10的Settings里面开启Windows Insider Program的Slow模式(需要微软账户)
- 检查并且更新Win10系统版本到新的版本
- 打开Win10里面个人比较喜欢的命令行工具输入
wsl --set-default-version 2
来把默认的WSL版本升级到WSL2 - 去Microsoft Store安装并且下载Ubuntu 18.04 app
- 下载并且等到安装完毕就可以了
在Ubuntu 18.04安装TexLive 2019
这个过程安装稍微要长一点,保持耐心就好,步骤如下:
- 到清华的开源软件镜像站下载TexLive的安装器https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/tlnet/install-tl.zip(如果你想下载完整版的.iso文件也可以的,我没有试过这个怎么安装的,请自行尝试)
- 解压以后进入解压后的文件夹并执行这个命令来安装
sudo ./install-tl -repository https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/tlnet/
(在选项里面选择allow execution of restricted list of programs via \write18
和create all format files
,然后选择set up for portable installation
) - 等待一段时间后,安装好的TexLive在/usr/local/texlive这个目录
- 安装字体配置器以备以后安装字体使用
sudo apt install fontconfig
- 如果需要配置字体,随时把想要的字体文件(.otf,.ttf等)拷贝到/usr/share/fonts下面,然后运行
sudo fc-cache -f -v
来扫描字体目录并生成字体信息的缓存
VS Code配置TexLive的运行环境并编译生成PDF文件
最后就可以来利用Ubuntu的TexLive环境来在VS Code里编译生成PDF文件了。下面着重讲讲VS Code的配置(对VS Code小白比较适用,高手勿喷)。
- 首先要安装VS Code的扩展程序叫做Latex Workshop(VS Code运行Latex必须的扩展),安装完在VS Code最左边会看到一个Tex字样的图标
- 点击这个Tex图标,然后按Ctrl+Shift+P来打开Preferences: Open Settings (JSON),输入以下内容:
{
"editor.wordWrap": "on",
"workbench.startupEditor": "newUntitledFile",
// 对应Clean up auxiliary files命令需要清楚的临时文件类型
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.bcf",
"*.cut",
"*.dvi",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.xml",
"*.pdf",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk",
"*.gz"
],
// 这个viewer的配置好像不太需要,因为在对应的View Latex PDF命令里面可以选浏览方式
"latex-workshop.view.pdf.viewer": "tab",
// 重点:这决定了下面的recipes调用不同TeX命令具体的执行方式
"latex-workshop.latex.tools": [
{
"name": "latex",
"command": "wsl",
"args": [
"-u",
"YOUR LINUX USERNAME",
"/absolute/path/to/your/latex",
"-src",
"-interaction=nonstopmode",
"%DOCFILE%.tex"
]
},
{
"name": "pdflatex",
"command": "wsl",
"args": [
"-u",
"YOUR LINUX USERNAME",
"/absolute/path/to/your/pdflatex",
"-synctex=1",
"-interaction=nonstopmode",
"-aux-directory=build",
"%DOCFILE%.tex"
]
},
{
"name": "xelatex",
"command": "wsl",
"args": [
"-u",
"YOUR LINUX USERNAME",
"/absolute/path/to/your/xelatex",
"-synctex=1",
"-interaction=nonstopmode",
"%DOCFILE%.tex"
]
},
{
"name": "lualatex",
"command": "wsl",
"args": [
"-u",
"YOUR LINUX USERNAME",
"/absolute/path/to/your/lualatex",
"-synctex=1",
"-interaction=nonstopmode",
"%DOCFILE%.tex"
]
},
{
"name": "dvips",
"command": "wsl",
"args": [
"-u",
"YOUR LINUX USERNAME",
"/absolute/path/to/your/dvips",
"-o",
"%DOCFILE%.ps",
"%DOCFILE%.dvi"
]
},
{
"name": "dvipng",
"command": "wsl",
"args": [
"-u",
"YOUR LINUX USERNAME",
"/absolute/path/to/your/dvipng",
"-T",
"tight",
"-D",
"120",
"%DOCFILE%.dvi"
]
},
{
"name": "ps2pdf",
"command": "wsl",
"args": [
"-u",
"YOUR LINUX USERNAME",
"/absolute/path/to/your/ps2pdf",
"%DOCFILE%.ps"
]
},
{
"name": "dvipdf",
"command": "wsl",
"args": [
"-u",
"YOUR LINUX USERNAME",
"/absolute/path/to/your/dvipdfm",
"%DOCFILE%.dvi"
]
},
{
"name": "bibtex",
"command": "wsl",
"args": [
"-u",
"YOUR LINUX USERNAME",
"/absolute/path/to/your/bibtex",
"%DOCFILE%.aux"
]
},
{
"name": "biber",
"command": "wsl",
"args": [
"-u",
"YOUR LINUX USERNAME",
"/absolute/path/to/your/biber",
"%DOCFILE%.bcf"
]
}
],
// 这个会生成在Commands里面的recipe
"latex-workshop.latex.recipes": [
{
"name": "latex",
"tools": [
"latex"
]
},
{
"name": "pdftex",
"tools": [
"pdflatex"
]
},
{
"name": "xelatex",
"tools": [
"xelatex"
]
},
{
"name": "luatex",
"tools": [
"lualatex"
]
},
{
"name": "dvips",
"tools": [
"dvips"
]
},
{
"name": "dvipng",
"tools": [
"dvipng"
]
},
{
"name": "ps2pdf",
"tools": [
"ps2pdf"
]
},
{
"name": "dvipdf",
"tools": [
"dvipdf"
]
},
{
"name": "bibtex",
"tools": [
"bibtex"
]
},
{
"name": "biber",
"tools": [
"biber"
]
}
]
}
至此环境已经准备完毕,重启以下VS Code,下面就是怎么打开你的Tex文件,然后点击刚才左侧的Tex图标,并且调出Commands窗口,在Build LaTeX Project下面的Recipe就可以利用不同的Tex命令来编译生成PDF文件了。纵观整个过程,这个settings.json的配置是重点。
来源:oschina
链接:https://my.oschina.net/u/4394125/blog/3310809