LoginSignup
5
8

More than 5 years have passed since last update.

EmacsでもLaTeXが書きたい!

Last updated at Posted at 2017-10-14

この時期になると卒業論文や修士論文(LaTeX)をEmacsで書きはじめる方がいらっしゃると思いますので,参考になればと思い書きました.あくまで最低限の設定かと思いますので,良い拡張などありましたらコメントください.

General

  • EmacsのLaTeX-modeで基本はOk
  • 便利にするため下記をinit.elに記述
(require 'tex)
(TeX-global-PDF-mode t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(add-hook 'LaTeX-mode-hook 'visual-line-mode)
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
(setq TeX-PDF-mode t)

Compile

普段TeXShop使ってる人はTypeSetとかのコマンドでいけるけど,EmacsだとMakefileを叩くしかない

  • compileしたいtexファイルと同一階層でM-x compile.Makefileを探してmake -kしてくれる(もしくはC-c C-cTex-command-masterを起動できる)
  • M-x compileを少し拡張した関数をivyの作者abo-aboさんがstackoverflowに書いていたので,こちらを記述しても良いかも
(defun desperately-compile ()
  "Traveling up the path, find a Makefile and `compile'."
  (interactive)
  (with-temp-buffer
    (while (and (not (file-exists-p "Makefile"))
                (not (equal "/" default-directory)))
      (cd ".."))
    (when (file-exists-p "Makefile")
      (compile "make -k"))))
  • Compilation bufferが開くが,それが鬱陶しい人は以下をinit.elに記述.別frameでcompile logが出力されるようになる(macならCmd+wでそのwindowをkillできる).

(setq special-display-buffer-names '("*compilation*"))

View

  • Adobeのpdf viewerなどはファイルの変更を検知して自動でreloadしてくれない.
  • そのためSkimを導入するといい.変更を検知してreloadしてくれる(preferenceをいじる必要あり)
  • make後に自動でcompileしたpdfファイルを開く・フォーカスしてほしいので,Makefileのallのあとにopen -a Skim [YOUR_PDF_NAME]が実行されるよう記述(以下が私のMakefileの一部)
all: pdf
pdf: &(OUTPUT).pdf
$(OUTPUT).pdf: $(TARGET).dvi out2uni
    dvipdfmx -o $(OUTPUT).pdf $(TARGET).dvi
    open -a Skim $(OUTPUT).pdf # open pdf by skim

  • latex-preview-pane-modeなどもありましたが,こちらはpdfを閲覧するのには重すぎたので割愛.
5
8
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
8