hanshandiaozhe 2020-02-16
本人手头电脑是Win10 Home版全新安装的系统,由于不想在新系统盘里面安装TexLive导致固态硬盘不断扩大,所以,考虑安装Ubuntu做为WSL,然后把TexLive安装在Ubuntu,并通过VS Code调用Ubuntu命令来写Latex的方法来写一些论文。在此,提供一个思路给大家借鉴。
这个过程其实直接参照微软的标准过程就可以了,大致步骤总结如下:
wsl --set-default-version 2
来把默认的WSL版本升级到WSL2这个过程安装稍微要长一点,保持耐心就好,步骤如下:
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
)sudo apt install fontconfig
sudo fc-cache -f -v
来扫描字体目录并生成字体信息的缓存最后就可以来利用Ubuntu的TexLive环境来在VS Code里编译生成PDF文件了。下面着重讲讲VS Code的配置(对VS Code小白比较适用,高手勿喷)。
{ "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的配置是重点。