Mac下LaTeX安装与配置 —— 亲测有效 (Sublime和VScode)

mac2026-04-05  6

文章目录

参考文章安装软件配置记录设置中文环境(不需%!TEX program = xelatex)20.03.07 最新VScode-latex配置方法反向搜索

参考文章

部署MAC上的Sublime Text+LaTex中文环境(好文)Mac上安装Sublime Text3和LaTex环境macOS + Sublime Text + Latex 环境配置有哪些好的 LaTeX 编辑器?官方How to Use LaTeX in Sublime Text on Mac

安装软件

mactexLaTex Tools — sublime text3skim

配置记录

mactex 安装截图 brew cask install mactex (文件较大,最好开启代理下载) 用sublime按ctrl + B时记得先调成LaTeX(因为没调这个,浪费了我很多时间) 测试代码(按ctrl + B会自动跳出skim预览界面) %!TEX program = xelatex \documentclass{article} \usepackage{fontspec, xunicode, xltxtra} \setmainfont{Hiragino Sans GB} %支持中文 \title{My First Document} \author{Wilson79} \date{\today} \begin{document} \maketitle{第一章} \section{Introduction} This is where you will write your content. 这里是是你写代码的内容 \end{document} 配置成功截图(支持中文) 更加方便地可以设置Build System为Automatic,然后系统会自动识别你的文件类型,第一次按ctrl + B会让你选一个,如下面第二张图所示,以后该文件类型就都是用这个System build了

设置中文环境(不需%!TEX program = xelatex)

上文中的测试代码开头加上%!TEX program = xelatex,那是因为在没设置前,你必须要加这句代码才能进行编译,如果想每次不加这句话也能编译请看下面的设置在SublimeText3里打开LaTeXTools.sublime-settings(通过Browse Packages去找) 在builder_settings里添加下面的两行代码即可,以后就不需要在开头加上%!TEX program = xelatex了,一劳永逸 "program" : "xelatex", "command" : ["latexmk", "-cd", "-e", "$pdflatex = 'xelatex -interaction=nonstopmode -synctex=1 %S %O'", "-f", "-pdf"],

另外注意之前应该有"builder": "default"(我改为了basic,不改也行)

当然如果觉得修改设置看起来很复杂,可以在每篇文档前增加%!TEX program = xelatex,这会强制使用xelatex,也是解决中文的一个方法。

20.03.07 最新VScode-latex配置方法

Official Document:https://github.com/James-Yu/LaTeX-Workshop/wiki

知乎——使用VSCode编写LaTeX

Mac系统如何配置VSCode作为LaTex的编译环境

settings.json中的配置文件如下

"latex-workshop.latex.tools": [ { "name": "xelatex", "command": "xelatex", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "-pdf", "%DOC%" ] }, { "name": "latexmk", "command": "latexmk", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "-pdf", "%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": "xelatex", "tools": [ "xelatex" ] }, { "name": "pdflatex -> bibtex -> pdflatex*2", "tools": [ "pdflatex", "bibtex", "pdflatex", "pdflatex" ] } ]

常用功能

正向搜索 在这里设置快捷键

Snippet 参考配置 如:@/ + tab触发模版frac

latex-workshop.latex.autoClean.run 自动清理辅助文件 https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#latex-workshoplatexautocleanrun

反向搜索

在 macOS 上配置 VSCode 与 Skim 的 LaTeX 正反跳转 反向搜索只要按我下面这样配置就行了,不用像上面文章里说的那么复杂地添加displayline 脚本


添加下面代码即可

"latex-workshop.view.pdf.viewer": "external", "latex-workshop.view.pdf.external.synctex": { "command": "/Applications/Skim.app/Contents/SharedSupport/displayline", "args": [ "-r", "%LINE%", "%PDF%", "%TEX%" ] },

设置Skim中Sync为VScode就可以支持反向搜索 Skim:cmd + shift + 鼠标 (PDF->LaTeX) VScode: cmd + shift + K (LaTeX->PDF) 在快捷键中设置


Vscode LaTeX 支持鼠标悬停公式预览 安装插件Rainbow Brackets 可以使得公式中的左右括号更加清楚。

最新回复(0)