轻量级文本编辑工具Sublime扩展LaTeX编译功能教程
LaTeX是写论文必备的一个神器,它可以将我们从格式、排版、以及参考文献等琐碎工作中解脱出来。
但是,如何配置一个得心应手的编辑器对于新手来说不算特别友好。
如果动手能力不是很强,推荐直接使用免费的线上LaTeX神器Overleaf
Tip:注册的时候网速比较慢,有条件的翻一下
接下来就开始我们轻量级工具升级的教程了
下载并安装软件
Sublime本身是不具备编译LaTeX和生成PDF的功能的,我们需要下另外两个工具
安装以上三个软件
安装LaTeXTools
LaTeXTools是Sublime中的插件,为Sublime提供接口,使Sublime可以调用MiKTeX的引擎和Sumatra的输出
按下快捷键Ctrl+Shift+P,选择Package Control Install Package->安装插件,输入LaTeXTools,回车安装
选择安装插件的时候多半会报这个错误,这是由于sublime自带的channel文件太老了
我们需要下载一个新的channel文件,并写在配置中
源文件:https://packagecontrol.io/channel_v3.json
百度网盘链接:https://pan.baidu.com/s/1OzE8yYNeVHpYFl7d2t2iRw
提取码:hb4d
下载channel_v3.json文件后,修改配置,选择 首选项->插件设置->Package Control->设置-默认
将下面的channels地址改为下载的channel_v3.json的文件路径
如下图为我的文件路径
这里将debug设置为true,使用Ctrl+~键可以查看调试信息(之后会在软件下方看到调试信息)
保存配置文件后,再次按下快捷键Ctrl+Shift+P,选择Package Control Install Package->安装插件,弹出新的执行命令框,输入LaTeXTools,回车确认
安装成功后会弹出Package Control Messages的文件
更改LaTeXTools配置文件
选择 首选项->浏览插件
进入文件夹界面后,进入LaTexTools文件夹,修改LaTeXTools.sublime-settings文件,相似名字的文件有很多,注意区分。我们需要填下以下属性:
texpath 是 MiKTeX的路径
distro 是引擎的类型
Sumatra 是SumatraPDF的路径
这是原文件的内容
下图是修改后我的配置
保存文件后,重新打开sublime就可以用sublime编译执行LaTeX了
测试
我们创建一个TeX文件1.tex并用sublime打开,复制以下TeX的代码demo到文件中
% This is a small sample LaTeX input file (Version of 10 April 1994)
%
% Use this file as a model for making your own LaTeX input file.
% Everything to the right of a % is a remark to you and is ignored by LaTeX.
% The Local Guide tells how to run LaTeX.
% WARNING! Do not type any of the following 10 characters except as directed:
% & $ # % _ { } ^ ~ \
\documentclass{article} % Your input file must contain these two lines
\begin{document} % plus the \end{document} command at the end.
\section{Simple Text} % This command makes a section title.
Words are separated by one or more spaces. Paragraphs are separated by
one or more blank lines. The output is not affected by adding extra
spaces or extra blank lines to the input file.
Double quotes are typed like this: ``quoted text''.
Single quotes are typed like this: `single-quoted text'.
Long dashes are typed as three dash characters---like this.
Emphasized text is typed like this: \emph{this is emphasized}.
Bold text is typed like this: \textbf{this is bold}.
\subsection{A Warning or Two} % This command makes a subsection title.
If you get too much space after a mid-sentence period---abbreviations
like etc.\ are the common culprits)---then type a backslash followed by
a space after the period, as in this sentence.
Remember, don't type the 10 special characters (such as dollar sign and
backslash) except as directed! The following seven are printed by
typing a backslash in front of them: \$ \& \# \% \_ \{ and \}.
The manual tells how to make other symbols.
\end{document} % The input file ends with this command.
按下Ctrl+B进行编译,当弹出MiKTeX软件需要安装依赖包时,选择确定进行安装
之后会将为TeX生成PDF,每次编译后都会更新该窗口
到此我们的任务就完成了
本文侧重点为扩展Sublime的LaTeX功能,文中并没有过多展示LaTeX的强大之处,LaTeX是十分容易上手的排版编辑工具,配置好编辑器后,可以在各种会议期刊处下载LaTeX的模板进行修改尝试。
只需要一行代码引入会议要求模板,就可以自动调整pdf样式。利用参考文献管理工具一键复制出BibTex结构化文本粘到bib文件中,可以按照引用标签顺序自动排列。各种便利的功能都可以在改写会议模板tex文件过程中体会到LaTeX编辑的强大。
之前提到过TeX编译引擎,其实市面上常用的引擎还有TexLive,想把MiKTeX换TexLive,可以参考这篇博客。同样的其它轻量级文本编辑工具也可以实现类似的功能,比如VScode等,其它的组装策略可以参考这篇知乎的配置部分。