12FF5B8

hico_horiuchiの技術系な覚え書き.

yatex-modeでPDFプレビュー

TeX→DVI→PDFに変換するshell scriptは作ってたが、Emacsで編集中にコマンド打つのが面倒なので、関数作ってキーを当ててみた。

shell script

以下のtex2pdf.shを、~/binとかPATHの通ったディレクトリに置いておく。

#!/bin/sh
if [ -e $1 ]
then
    NAME=`basename $1 .tex`
    platex $NAME.tex
    dvipdfmx $NAME.dvi
    if [ -e $NAME.aux ] ; then rm $NAME.aux; fi
    if [ -e $NAME.dvi ] ; then rm $NAME.dvi; fi
    if [ -e $NAME.log ] ; then rm $NAME.log; fi
    if [ -e $NAME.nav ] ; then rm $NAME.nav; fi
    if [ -e $NAME.out ] ; then rm $NAME.out; fi
    if [ -e $NAME.snm ] ; then rm $NAME.snm; fi
    if [ -e $NAME.toc ] ; then rm $NAME.toc; fi
    if [ -e $NAME.vrb ] ; then rm $NAME.vrb; fi
    "/c/Program Files/Adobe/Reader 11.0/Reader/AcroRd32.exe" $NAME.pdf
else
    echo $1: No such file or directory
fi

途中で生成されるファイルを削除したり、ビューアがAdobe Readerだったりするので注意。

elisp

以下のtex-pdf-preview関数を、init.elとかに書いておく。
C-c C-cでtex2pdf.shが実行されて、Adobe ReaderでPDFが開く。

;; C-c C-cでPDFプレビュー
(add-hook-fn 'yatex-mode-hook
  (define-key YaTeX-mode-map "\C-c\C-c" 'tex-pdf-preview))
(defvar tex2pdf-path "c:/usr/local/scripts/tex2pdf.sh")
(defun tex-pdf-preview ()
  (interactive)
  (if (buffer-modified-p) (save-buffer))
  (if (get-process "tex2pdf") (delete-process "tex2pdf"))
  (start-process "tex2pdf" "tex2pdf" "sh" "tex2pdf.sh" buffer-file-name))