2014年11月5日水曜日

xyzzy + katexとSumatraPDFとlatexmk

Windows上でのLatex環境をSublime Textに移行しようと思いつつ,xyzzyで引っ張っています.dviを捨ててlatexmkでタイプセット→SumatraPDFでプレビューするようにしたら快適になりました.

latexmkの設定

texliveに標準で付属しているので,texliverな人はインストールはされているはず.latexmkの設定ファイル .latexmkrc を%USERPROFILE%直下に置く..latexmkrcのサンプル:
#!/usr/bin/perl
$latex         = 'platex -src-specials -interaction=nonstopmode -synctex=1 -kanji=utf8 -guess-input-enc %O %S';
$bibtex        = 'pbibtex %O %B';
$dvipdf        = 'dvipdfmx -I 24 %O %S';
$pdf_mode      = 3;
$pdf_previewer = 'C:/apps/SumatraPDF/SumatraPDF.exe -reuse-instance';

xyzzyの設定

tex, katex関連の基本設定は省略.C-c t j でlatexmk,C-c p でpdfをSumatraPDFでプレビューするようにsiteinit.lに設定を追記.byte compile と再読み込みを忘れないように(M-x: byte-compile-file → ダンプファイル削除してxyzzy起動).
;;typesetter
(setq elisp::tex-command "latexmk -pdfdvi")
;;Run preview by C-c p
(defun sumatrapdf-forward-search ()
  (interactive)
  (let* ((tex-file (get-buffer-file-name))
         (pdf-file (concat (car (split-string (get-buffer-file-name) "\\.")) ".pdf"))
         (line (format nil "~D" (current-line-number)))
         (cmd "rundll32 shell32,ShellExec_RunDLL SumatraPDF")
         (args))
    (setq args (concat "-reuse-instance \"" pdf-file "\" -forward-search \"" tex-file "\" " line))
    (message (concat cmd " " args))
    (call-process (concat cmd " " args)
                  :exec-directory (directory-namestring tex-file))))

(add-hook 'elisp::katex-mode-hook
          #'(lambda ()
       (define-key elisp::*KaTeX-mode-map* '(#\C-c #\p)  'sumatrapdf-forward-search)))

SumatraPDFの設定

SumatraPDF上でダブルクリックするとソースの対応行へ移動するように設定.SumatraPDFのメニューバー > 設定 > オプション > 逆順検索コマンドラインの設定にて:
C:\apps\xyzzy\xyzzycli.exe -g %l "%f"

参考