记一次用Sublime Text 4 配置LaTeX写作环境
软件下载
- texlive;下载地址
- sublime text 4,2021更新的最新版;下载地址
- ImageMagick,用来显示公式和图片预览;下载地址
- ghostscript,该软件texlive自带,如果公式预览出问题再来下载;下载地址
- sumatraPDF,预览PDF用的,很轻量级很简洁。下载地址
配置sublime text
- 安装package control
Ctrl + Shift + P 打开命令面板输入package control 查找install package control 并安装。 - 安装与配置 LaTeXtools
Ctrl + Shift + P 打开命令面板输入pc install
打开install package,这里可以搜索所有需要安装的插件(汉化包,主题,配色方案等等),包括LaTextools。然后配置LaTeXtools:
preference -> package settings -> Latexlools
打开settings default和settings user,将default内容复制到user中;- 修改user中的设置:搜索Windows,其中texpath是texlive和其他软件的寻址地址,也可以直接将它们加入系统环境变量,然后这里只填$PATH;distro 填texlive;sumatra填sumatraPDF的安装路径。
"windows": {
// Path used when invoking tex & friends; "" is fine for MiKTeX
// For TeXlive 2011 (or other years) use
// "texpath" : "C:\\texlive\\2011\\bin\\win32;$PATH",
"texpath" : "E:\\texlive\\2021\\bin\\win32;$PATH",
// TeX distro: "miktex" or "texlive"
"distro" : "texlive",
// Command to invoke Sumatra. If blank, "SumatraPDF.exe" is used (it has to be on your PATH)
"sumatra": "E:\\SumatraPDF\\SumatraPDF.exe",
// Command to invoke Sublime Text. Used if the keep_focus toggle is true.
// If blank, "subl.exe" or "sublime_text.exe" will be used.
"sublime_executable": "",
// how long (in seconds) to wait after the jump_to_pdf command completes
// before switching focus back to Sublime Text. This may need to be
// adjusted depending on your machine and configuration.
"keep_focus_delay": 0.5
},
搜索builder_settings,在里面可以如下修改编译链:
"windows" : {
// See README or third-party documentation
"script_commands":[
"xelatex -synctex=1 -interaction=nonstopmode",
"bibtex",
"xelatex -synctex=1 -interaction=nonstopmode",
"xelatex -synctex=1 -interaction=nonstopmode"
]
},
preference -> package settings -> Latexlools -> Check System
检查环境,如果有unavailable的可以检查一下设置的路径与环境变量有没有错误。tips:路径反斜杠需要double。
- 安装和配置LaTeXcwl
安装方法与上述相同,LaTeXcwl是用于LaTeX命令的自动补全的。对于sublime text 4它有一个重要bug:补全命令的斜杠会消失。解决方法参考该博客。
Packages/LaTeXTools/latex_cwl_completions.py
文件中添加
_ST4 = sublime.version() >= '4000'
···
if not _ST4:
#版本大于4000的情况下不执行以下代码
# autocompleting with slash already on line
# this is necessary to work around a short-coming in ST where having a
# keyed entry appears to interfere with it recognising that there is a
# \ already on the line
#
# NB this may not work if there are other punctuation marks in the
# completion
if is_prefixed:
completions = [
(c[0], c[1][1:]) if c[1].startswith("\\") else c
for c in completions
]
配置sumatraPDF的反向定位功能
- 将sumatrapdf 路径添加到环境变量path中,然后cmd运行以下命令(sublime地址需修改):
sumatrapdf -inverse-search "\"E:\Sublime Text\sublime_text.exe\" \"%f:%l\""
或者在sumatraPDF的设置->选项里添加"E:\Sublime Text\sublime_text.exe" "%f:%l"
命令。
公式预览出错
cannot convert pdf to png to preview
这样的错误基本上是因为texlive自带的ghostscript与系统不匹配导致的。Check system里面可以看到ghostscript的路径,E:\texlive\2021\tlpkg\tlgs\bin\gswin64c.exe
如果这里是gswin32c.exe,那需要自己安装一个64位的然后替换以下4个文件。
如果问题还在,请在双击运行gswin64.exe,这里可能会报这样的错:没有gs_init.ps,或者gs_init.ps版本不匹配。
Interpreter revision (****) does not match gs_init.ps revision (****).
这时候你最好把下面这个resouce文件夹都替换成你所安装的版本。
这样基本都没啥问题了。