texの環境構築2
コメントでYaTexが便利ということを教えてもらいました。ありがとうございます。
さっそく、インストールしてみました。
インストールしてから気づいたのですが、ubuntuでもpackageが用意されているみたいです。*1
download
http://www.yatex.org/yatex1.73.tar.gzここからファイルを落としてくる。
installの方法を調べる。
展開してできたディレクトリの中を見てみると,"install"というファイルがあることに気づく。
そこにかかれているとおりに実行する。
installに書かれているとおりに作業を行う。
.emacsの設定とmake installをすれば良いらしい。
.emacsの設定
(setq auto-mode-alist (cons (cons "\\.tex$" 'yatex-mode) auto-mode-alist)) (autoload 'yatex-mode "yatex" "Yet Another LaTeX mode" t) (setq load-path (cons (expand-file-name "~/src/emacs/yatex") load-path)) ;~/src/emacs/yatexがyatexの展開先 ;;このpathの追加はmake installをするならいらないような気がする。
make installの前にmakefileを修正する。
現在の環境ではemacsではなく、emacs-snapshotになっている点などをもとにmakefileを修正した。
makefile
# Edit these variables to be suitable for your site PREFIX = /usr/share #ここを修正 ## emacs-snapshot #新しくこんな感じの欄を作った。 EMACS = emacs-snapshot EMACSDIR = ${PREFIX}/${EMACS}
make installする前にbytecompileをした。
make
make bytecompile && sudo make install
make installを実行すると、EMACSDIRで設定した辺りに*.elと*.elcのファイルがコピーされるみたい。
元々、pathの通っているところに置かれるので、make installをすればload-pathの設定を.emacsに追加する必要はないような気がした。
あと、実際に使う上でhelpとかを楽に使いたかったのでanythingを作成した。
anythingを使うように変更
以下の2つを作成した。
- YaTeX-help/anything
- ほとんどanythingとのinterfaceを作るだけ
- YaTeX-do-completion/anything
- 元の関数の定義を一部変更
- buffer-substring->buffer-substring-no-properties
- 候補が複数あったときに、display-listにしていた部分をanythingに渡すようにする。
(defun YaTeX-help/anything () (interactive) (let ((source `((name . "YaTeX Help") (candidates . YaTeX-help-entries) (action . (lambda (command) (setq YaTeX-help-saved-config (current-window-configuration)) (or (YaTeX-refer-help command YaTeX-help-file) (YaTeX-refer-help command YaTeX-help-file-private) (YaTeX-enrich-help command))))))) (anything (list source) (current-word)))) (defun YaTeX-do-completion/anything () "Try completion on LaTeX command preceding point." (interactive) (if (or (eq (preceding-char) ? ) (eq (preceding-char) ?\t) (eq (preceding-char) ?\n) (bobp)) (message "Nothing to complete.") ;Do not complete (let* ((end (point)) (limit (point-beginning-of-line)) (completion-begin (progn (re-search-backward "[ \t\n]" limit 1) (point))) (begin (progn (goto-char end) (if (re-search-backward YaTeX-completion-begin-regexp completion-begin t) (1+ (point)) nil)))) (goto-char end) (cond ((null begin) (message "I think it is not a LaTeX sequence.")) (t (mapcar 'YaTeX-sync-local-table '(tmp-section-table tmp-env-table tmp-singlecmd-table)) (let*((pattern (buffer-substring-no-properties begin end)) (all-table (append section-table user-section-table tmp-section-table env-table user-env-table tmp-env-table singlecmd-table user-singlecmd-table tmp-singlecmd-table)) ;; First, ;; search completion without backslash. (completion (try-completion pattern all-table))) (if (eq completion nil) ;; Next, ;; search completion with backslash (setq completion (try-completion (buffer-substring-no-properties (1- begin) end) all-table nil) begin (1- begin))) (cond ((null completion) (message (concat "Can't find completion for '" pattern "'")) (ding)) ((eq completion t) (message "Sole completion.")) ((not (string= completion pattern)) (delete-region begin end) (insert completion) ) (t (message "Making completion list...") (let ((cands (all-completions pattern all-table))) (if (null (cdr cands)) (insert (car cands)) (anything `(((name . "YaTex completion") (candidates . ,cands) (action . (lambda (c) (delete-region begin end) (insert c)))))))))))))))) ;;.emacsに追加した設定 (add-hook 'yatex-mode-hook (lambda () (when (or (not (boundp 'YaTeX-help-entries)) (null YaTeX-help-entries)) (autoload 'YaTeX-help-entries "yatexhlp" "prepare for using YaTeX-help/anything." t) (setq YaTeX-help-file "/usr/share/emacs-snapshot/site-lisp/YATEXHLP.jp") (setq YaTeX-help-entries (YaTeX-help-entries)) ) (define-key YaTeX-mode-map "\C-hf" 'YaTeX-help/anything) (define-key YaTeX-mode-map "\C-c\C-j" 'YaTeX-do-completion/anything) ))