打造最高效的科研环境之Emacs插件们

-1 修改日志

[1] 以上插件,在CentOS7 (内核 3.10.0-514.16.1.el7.x86_64)上的 Emacs 25.2 中同样安装成功。

0 盲人摸象

作为初学者,迫切的需求就是直接上手Emacs并打造包含自动补全命令在内的科研环境。

和网上众多的插件安装的教程相比,我认为找到一个与自己需求匹配的Emacs配置环境来得更方便。

本例中,在实测了两个AucTex和CDlatex插件的安装无果之后,转而寻找现成的配置。

比如Github上的这个设计,支持

  • C/C++
  • Matlab
  • Markdown/LaTeX
  • Haskell

与我的需求高度重合,克隆一份相应的配置简直是再方便不过了!也省去了一个个安装的麻烦,也无需解决各个依赖关系,对新手是再适合不过了!

1 更新Emacs配置

本机环境:

$ uname -r
Linux She 2.6.32-573.el6.x86_64

安装的Emacs版本:

$ emacs --version
GNU Emacs 24.5.1
Copyright (C) 2015 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

下载相应的Emacs配置文件:https://github.com/xyguo/emacs.d,选择“Download ZIP”下载压缩包,解压之后,将相应的文件放置到~/.emacs.d/文件夹中。

如果不存在~/.emacs.d/文件夹,上述下载-解压-复制的工作还可以用以下的一句命令来完成:

$ git clone https://github.com/xyguo/emacs.d.git ~/.emacs.d

在终端执行命令,使得配置的Emacs环境立即生效:

$ emacs --debug-init

至此,一个同样的环境被安装完毕,支持命令自动补全,Matlab | Python | C | Latex等语言的语法高亮。

剩下的工作就是如何熟悉这个环境,尤其是快捷键的操作,稍作练习,我相信能很快上手。

2 手动安装package(包)

具体内容译自这里。手动安装package,就是要解决两个问题:(1) LaTex 采用的是什么样的树结构?(2) 应该把一个package中的文件放到哪个目录下? 解决完这两个问题,package 也就安装好了。

两个问题的答案:

(1) 使用以下命令找到 TexLive 的树目录所在位置(若有疑问,可参考这里):

$ kpsewhich -var-value TEXMFLOCAL
/usr/local/texlive/texmf-local
$ echo $TEXMF
/usr/local/texlive/texmf-local

package 的各个文件,都需要放到这个树目录下,但是具体位置还需要根据树目录的规则,也就是第 (2) 个问题的答案来决定。

如果环境变量 $TEXMF 并不存在,则需要设置相应的环境变量,设置方法请参见另一篇博客:《[CentOS] 环境变量设置的三种方法》。

(2) 根据 TexLive 树目录的规则,package 的文档按以下规则来放置(若有疑问,可参考这里):

We assume here that you have decided what tree to put your files in, after reading “choosing a TDS tree”. We will therefore write $TEXMF for it, and you need to substitute the tree you decided on.

The basic idea is to imitate the directory structure in your existing tree(s). Here are some examples of where various sorts of files should go:

.sty, .cls or .fd: $TEXMF/tex///
.mf:   $TEXMF/fonts/source///
.tfm:  $TEXMF/fonts/tfm///
.vf:   $TEXMF/fonts/vf///
.afm:  $TEXMF/fonts/afm///
.pfb:  $TEXMF/fonts/type1///
.ttf:  $TEXMF/fonts/truetype///
.otf:  $TEXMF/fonts/opentype///
.pool, .fmt, .base or .mem: $TEXMF/web2c

and for modern systems (those distributed in 2005 or later, using TDS v1.1 layouts):

.map:  $TEXMF/fonts/map///
.enc:  $TEXMF/fonts/enc///

实际上,自 TexLive 2015 起,minted package 就已经被打包在 TexLive 安装程序中,不需要再单独安装。

这里以 minted package 为例,介绍手动安装的过程。minted 包是一个用于给程序代码自动着色的包,它的官方网址位于:https://www.ctan.org/pkg/minted

GitHub 上可以下载它完整的 package,下载之后进入到相应的目录中,将 minted.sty 文件按照上述树目录的规则拷贝到 $TEXMF/tex 目录下,再运行 texhash 命令更新即可。

$ cd ~/Documents/
[She@localhost Documents]$ git clone https://github.com/gpoore/minted.git
正克隆到 'minted'...
remote: Counting objects: 602, done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 602 (delta 19), reused 26 (delta 12), pack-reused 565
接收对象中: 100% (602/602), 6.01 MiB | 725.00 KiB/s, done.
处理 delta 中: 100% (395/395), done.

[She@localhost Documents]$ sudo cp ./minted/source/minted.sty $TEXMF/tex 
[sudo] password for She: 

[She@localhost Documents]$ su
密码:
[root@localhost Documents]# texhash
texhash: Updating /usr/local/texlive/2017/texmf-config/ls-R... 
texhash: Updating /usr/local/texlive/2017/texmf-dist/ls-R... 
texhash: Updating /usr/local/texlive/2017/texmf-var/ls-R... 
texhash: Updating /usr/local/texlive/texmf-local/ls-R... 
texhash: Done.
[root@localhost Documents]# exit
exit
[She@localhost Documents]$ 

从页面上的 Download 链接可以下载到一个压缩包,包括以下几个文档:

Makefile
minted.dtx
minted.ins
minted.pdf
README

安装和使用详见 minted.pdf 文档,需要注意的是,minted 包需要首先安装 Python 的 pygments 组件,安装完成之后,将  文档拷贝到 $TEXMF 目录下的

minted 会生成一些编译的临时文件,比较乱
可以把这些临时文件输出到特定文件夹
usepackage[outputdir=build]{minted}

如果不想留临时文件:
usepackage[cache=false, outputdir=build]{minted}

小尾巴:auto-complete 自动补全插件的下载地址为: https://github.com/auto-complete/auto-complete

许多常用的插件,都可以在GitHub中下载到,这个网址要经常访问,上面有好多宝贝待挖掘。

原文地址:https://www.cnblogs.com/snake553/p/4948523.html