本文总结了在windows 和wsl/Ubuntu平台部署latex环境,在vscode中写文件和编译的过程。

在线版本的overleaf可以免去配置环境,方便进行多人协作。
但是在前期写作阶段,我比较倾向于本地环境,方便修改图片,不用反复上传。可以在初稿完成后,上传至overleaf协作修改。

一共两个步骤:

  • 配置对应系统的tex
  • vscode安装Latex Workshop插件

即可实现一键编译。编译速度上应该是mac>linux>wsl>windows, 所以在windows中可以额外配置wsl的latex环境。

安装Tex

这个环节可能要很长时间,可以选择从国内镜像站下载。安装的过程中可以同步进行下一步操作。

Windows

安装texlive,下载install-tl-windows.exe,一键安装。安装过程需要一段时间,可以放在后台等。同样的网络下,wsl中安装速度比windows快了很多。

Ubuntu

根据texlive网页说明,在terminal中运行,

1
2
3
4
5
6
7
8
cd /tmp # working directory of your choice
Download: wget https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
or: curl -L -o install-tl-unx.tar.gz https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz

zcat < install-tl-unx.tar.gz | tar xf - # note final - on that command line
cd install-tl-2*
perl ./install-tl --no-interaction # as root or with writable destination
# may take several hours to run

安装完成后需要添加路径/usr/local/texlive/YYYY/bin/PLATFORM 到 PATH,以实际屏幕显示的路径进行设置。

1
2
3
4
5
6
7
echo "" >> ~/.bashrc
echo "# --- TeX Live 2025 Configuration from /etc/profile.d/ ---" >> ~/.bashrc
# 下面三行是 /etc/profile.d/texlive.sh 的内容
echo 'export PATH="/usr/local/texlive/2025/bin/x86_64-linux:$PATH"' >> ~/.bashrc
echo 'export MANPATH="/usr/local/texlive/2025/texmf-dist/doc/man:$MANPATH"' >> ~/.bashrc
echo 'export INFOPATH="/usr/local/texlive/2025/texmf-dist/doc/info:$INFOPATH"' >> ~/.bashrc
echo "# --------------------------------------------------------" >> ~/.bashrc

MaxOS

MacTeX

VSCode-Latex Workshop

直接搜Latex Workshop并安装,如果工作目录下或者打开的文件有tex文件,左侧工具栏会显示$\TeX$图标,可以点击编译、清理,也可用右上角的编译按钮。

特点:

  • 每次保存都会自动编译
  • 引用的图片文件有更新,也会自动编译

缺点:

  • 如果报错了,就无法看到文件,但是overlear中还是可以编译。

.gitignore

如果用git管理项目,可以设置ignore内容,参考自github/gitignore
https://github.com/github/gitignore/blob/main/TeX.gitignore

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb

## Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync

# elsarticle (documentclass of Elsevier journals)
*.spl

学习资源

Elsevier的网站有对应的快速入门文档,也有提供的elsartical模板文件。

labeling and referencing

some useful rules while writing a manuscript

elsarticle

下载最新的的文件解压后,当前路径下运行如下命令获得elsarticle.cls,然后根据屏幕提示选择相应文件。

1
latex elsarticle.ins
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
*************************************************************
* *
* To finish the installation you have to move the following *
* file into a directory searched by TeX: *
* *
* elsarticle.cls *
* and *
* elsarticle-*.bst *
* *
* To produce the documentation go to the ../contrib folder *
* and run the file elsdoc.tex through pdfLaTeX *
* or use the Makefile which is far more easier. *
* *
* Happy TeXing! *
* *
*************************************************************