spacemacs latex

In theprevious post, I introduced several useful tips for editing LaTeX file using Vim. In a nutshell, there are shortcuts ( = and gq family), commands and plugins. In addition, I also introduced latexmk tool in the texlive . By using -pvc flag, the PDF file will automatically generated once you save a tex file. However, long time ago, I change my main editor from Vim to Emacs, more specifically, Spacemacs. If you are interested in the reasons why I turned to Spacemacs. This post will give you enough answers. I will mainly focus on the experience of editing LaTeX files in Spacemacs.

Spacemacs

First of all, what’s is Spacemacs ? It is an Emacs advanced Kit focused on Evil: The best editor is neither Emacs nor Vim, it’s Emacs and Vim! Briefly speaking, you can get the powerful functions of Emacs along with the efficient editing experience of Vim. For me, the selling point may be the great documents. You don’t need to searching in the internet and hope to find posts from experienced users. The documents of Spacmeacs is like a real software manual including various introductions and handful examples. I recommend you to read through the features section in the documents . Here is an official screenshot.

There are plenty of configuration layers in the Spacemacs. For LaTeX editing, two layers are enough. They are auto-completion and latex . If you include these layers in the .spacemacs file. It will automatically load related packages when you open an tex file. The first layer, auto-completion is for auto-completion. For example, you can simply type a e and then M-/ to expand to \emph{} command in LaTeX. Besides tex file, this layer can serve other functions when editing other kinds of files. Let’s mainly look into latex layer.

AucTeX

The core of latex layer is actually auctex package. This package is extremely powerful. I am sure I can’t list all functions in one post. I will list the most useful functions in my view.

Build and View

The keybingings of build is SPC m b and view is SPC m v . If you press build keybinding, it will build your tex file using latex and generate a pdf file. By default, it will use pdflatex . However, I use xelatex sometimes to build beamer source code. To do this, add a local variable in the end of a tex file can tell auctex to build as xetex.

Lisp

%%% Local Variables:
%%% coding: utf-8
%%% mode: latex
%%% TeX-master: t
%%% TeX-command-extra-options: "-shell-escape"
%%% TeX-engine: xetex
%%% End:

By typing the view key binding, you can open the pdf file and tex file side by side to preview the result. I recommend to use Skim in OS X and Okular in Linux. Because both of them can sync pdf and tex file at runtime. Add following lines in the dot file to automatically select preview.

Lisp

(cond
   ((string-equal system-type "darwin")
    (progn (setq TeX-view-program-selection '((output-pdf "Skim")))))
   ((string-equal system-type "gnu/linux")
    (progn (setq TeX-view-program-selection '((output-pdf "Okular"))))))

Sync

Sometimes, when you editing a long tex file or beamer presentation, you want to know the correlation between pdf file and tex file. The sync function provided by auctex can help you jump from tex to pdf and pdf to tex. Add the following lines into the dot file

Lisp

(setq TeX-source-correlate-mode t)
  (setq TeX-source-correlate-start-server t)
  (setq TeX-source-correlate-method 'synctex)
  (setq TeX-view-program-list
        '(("Okular" "okular --unique %o#src:%n%b")
          ("Skim" "displayline -b -g %n %o %b")))

After that, when you type SPC m v the pdf viewer will highlight the line which you are editing with yellow color. Furthermore, you can press shift and command together and click on the pdf file, it will automatically jump to corresponding line in the tex file. This is quite useful when you editing a beamer presentation and want to jump to a page in the middle.

Misc

In addition to previous random thoughts, Spacemacs supports keybinding in Vim such as = and gq to format a paragraph. Moreover syntax checking is also a optional layer in the dot file. For auctex , there are still a lot of features . For example, you can preview equation and formula in side source code. You can also easily insert \cite{} and search keywords in bib file. It can generate WYSIWYG inline previews of mathematics, figures, and other constructs which are hard to grasp in plain source view by means of the preview-latex subsystem.

At last, this is just an introduction.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值