Emacs > YaTeX
YaTeX(野鳥)は Emacs の TeX 用メジャーモードです. TeX mode に比べ機能が大幅に拡張されています. もう一つ,有名な拡張として AUCTeX があり,海外ではこちらがよく使われているようです. 国内では YaTeX の方が人気があり,そのため日本語の情報が Web 上でたくさん見つかります.
YaTeX, TeX mode, AUCTeX では " を入力しようとすると `` が入力されます. `` ではなく " を入力したい場合は C-q " (Ctrl-Q を入力した後で " を入力) とします.
Okular は TeX ファイルをフルパスで指定しないと forward search ができないので,cf がフルパスでない場合は (expand-file-name cf) に修正する必要があります. ただし,2016-01-08 以降では (cf (buffer-file-name)) に変更されて cf はフルパスになったため,この修正は必要ありません.
Okular の format "%s '%s.pdf#src:%d' '%s'" の設定は間違いで,format "%s '%s.pdf#src:%d %s'" に修正する必要があります.
~/.emacs.d/init.el に yatexprc.el の YaTeX-preview-jump-line を修正したものを再設定します.
(with-eval-after-load 'yatexprc (defun YaTeX-preview-jump-line () "Call jump-line function of various previewer on current main file" (interactive) (save-excursion (save-restriction (widen) (let*((pf (or YaTeX-parent-file (save-excursion (YaTeX-visit-main t) (buffer-file-name)))) (pdir (file-name-directory pf)) (bnr (substring pf 0 (string-match "\\....$" pf))) ;(cf (file-relative-name (buffer-file-name) pdir)) (cf (buffer-file-name)) ;2016-01-08 (buffer (get-buffer-create " *preview-jump-line*")) (line (count-lines (point-min) (point-end-of-line))) (previewer (YaTeX-preview-default-previewer)) (cmd (cond ((string-match "Skim" previewer) (format "%s %d '%s.pdf' '%s'" YaTeX-cmd-displayline line bnr cf)) ((string-match "evince" previewer) (format "%s '%s.pdf' %d '%s'" "fwdevince" bnr line cf)) ((string-match "sumatra" previewer) (format "%s \"%s.pdf\" -forward-search \"%s\" %d" previewer bnr cf line)) ((string-match "zathura" previewer) (format "%s --synctex-forward '%d:0:%s' '%s.pdf'" previewer line cf bnr)) ((string-match "qpdfview" previewer) (format "%s '%s.pdf#src:%s:%d:0'" previewer bnr cf line)) ((string-match "okular" previewer) (format "%s '%s.pdf#src:%d %s'" previewer bnr line (expand-file-name cf))) ))) (YaTeX-system cmd "jump-line" 'noask pdir))))))
Emacs 26.1 から switch-to-buffer の仕様が変更されたため想定通りの動作をしない.YaTeX 1.80.3 で修正されたので YaTeX を更新する.
MELPA から YaTeX がインストールできます.
YaTeX リリース版 または YaTeX テスト版 をダウンロードして展開します. 展開したフォルダー名を yatex に変更します.
Emacs を起動して
C-x C-f ~/
で,ホームディレクトリ (~/) の場所を確認します.
yatex フォルダーをコピーして ~/.emacs.d/site-lisp/ にペーストします.(~/.emacs.d/site-lisp/ が無ければ新規に作成します.)
~ └─.emacs.d └─site-lisp └─yatex
~/.emacs.d/init.el に以下の設定を記述します.
(add-to-list 'load-path "~/.emacs.d/site-lisp/yatex")
~/.emacs.d/init.el に設定を記述します.
プレビューと forward search は SumatraPDF を使用します. SumatraPDF を前面に表示したくない場合は SumatraPDF/fwdsumatrapdf の fwdsumatrapdf.exe を使用します. SumatraPDF の inverse search については Emacs#SumatraPDF との連携#inverse search を参照してください.
;; ;; YaTeX ;; (autoload 'yatex-mode "yatex" "Yet Another LaTeX mode" t) (setq auto-mode-alist (append '(("\\.tex$" . yatex-mode) ("\\.ltx$" . yatex-mode) ("\\.cls$" . yatex-mode) ("\\.sty$" . yatex-mode) ("\\.clo$" . yatex-mode) ("\\.bbl$" . yatex-mode)) auto-mode-alist)) (setq YaTeX-inhibit-prefix-letter t) (setq YaTeX-kanji-code nil) (setq YaTeX-latex-message-code 'utf-8) (setq YaTeX-use-LaTeX2e t) (setq YaTeX-use-AMS-LaTeX t) (setq YaTeX-dvi2-command-ext-alist '(("TeXworks\\|texworks\\|texstudio\\|mupdf\\|SumatraPDF\\|Preview\\|Skim\\|TeXShop\\|evince\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|MicrosoftEdge\\|microsoft-edge\\|Adobe\\|Acrobat\\|AcroRd32\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf"))) (setq tex-command "ptex2pdf -u -l -ot \"-kanji=utf8 -no-guess-input-enc -synctex=1\"") ;(setq tex-command "lualatex -synctex=1") ;(setq tex-command "latexmk") ;(setq tex-command "latexmk -e \"$latex=q/uplatex %O -kanji=utf8 -no-guess-input-enc -synctex=1 %S/\" -e \"$bibtex=q/bibtexu %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -e \"$dvipdf=q/dvipdfmx %O -o %D %S/\" -norc -gg -pdfdvi") ;(setq tex-command "latexmk -e \"$lualatex=q/lualatex %O -synctex=1 %S/\" -e \"$bibtex=q/bibtexu %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -norc -gg -pdflua") (setq bibtex-command "latexmk -e \"$latex=q/uplatex %O -kanji=utf8 -no-guess-input-enc -synctex=1 %S/\" -e \"$bibtex=q/bibtexu %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -e \"$dvipdf=q/dvipdfmx %O -o %D %S/\" -norc -gg -pdfdvi") (setq makeindex-command "latexmk -e \"$latex=q/uplatex %O -kanji=utf8 -no-guess-input-enc -synctex=1 %S/\" -e \"$bibtex=q/bibtexu %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -e \"$dvipdf=q/dvipdfmx %O -o %D %S/\" -norc -gg -pdfdvi") (setq dvi2-command "rundll32 shell32,ShellExec_RunDLL SumatraPDF -reuse-instance") ;(setq dvi2-command "texworks") ;(setq dvi2-command "texstudio --pdf-viewer-only") (setq tex-pdfview-command "rundll32 shell32,ShellExec_RunDLL SumatraPDF -reuse-instance") ;(setq tex-pdfview-command "texworks") ;(setq tex-pdfview-command "texstudio --pdf-viewer-only") (setq dviprint-command-format "powershell -Command \"& {$r = Write-Output %s;$p = [System.String]::Concat('\"\"\"',[System.IO.Path]::GetFileNameWithoutExtension($r),'.pdf','\"\"\"');Start-Process Acrobat -ArgumentList ($p)}\"")
(defun fwdsumatrapdf-forward-search () (interactive) (progn (process-query-on-exit-flag (start-process "fwdsumatrapdf" nil "fwdsumatrapdf" (expand-file-name (concat (file-name-sans-extension (or YaTeX-parent-file (save-excursion (YaTeX-visit-main t) buffer-file-name))) ".pdf")) (buffer-name) (number-to-string (save-restriction (widen) (count-lines (point-min) (point))))))))
(add-hook 'yatex-mode-hook '(lambda () (define-key YaTeX-mode-map (kbd "C-c f") 'fwdsumatrapdf-forward-search)))
(add-hook 'yatex-mode-hook '(lambda () (auto-fill-mode -1)))
;; ;; RefTeX with YaTeX ;; ;(add-hook 'yatex-mode-hook 'turn-on-reftex) (add-hook 'yatex-mode-hook '(lambda () (reftex-mode 1) (define-key reftex-mode-map (concat YaTeX-prefix ">") 'YaTeX-comment-region) (define-key reftex-mode-map (concat YaTeX-prefix "<") 'YaTeX-uncomment-region)))
メニュー [YaTeX] キーバインド (setq YaTeX-inhibit-prefix-letter t) 機能 Process -> LaTeX C-c C-t j または C-c C-t C-j upLaTeX (ptex2pdf) Process -> BibTeX C-c C-t b RET bibtexu, biber (upLaTeXmk) Process -> makeindex C-c C-t i RET upmendex (upLaTeXmk) Process -> Preview C-c C-t p RET RET PDF プレビュー Process -> lpr C-c C-t l RET Adobe Acrobat Reader で PDF プレビューまたは印刷 C-c C-g SumatraPDF で forward search C-c f または M-x fwdsumatrapdf-forward-search RET fwdsumatrapdf で forward search
を参照.
~/.emacs.d/init.el に設定を記述します.
プレビューと forward search は Skim を使用します. Skim の inverse search については Emacs#Skim との連携#inverse search を参照してください.
動作未確認です.
;; ;; PATH ;; (setenv "PATH" "/usr/local/bin:/Library/TeX/texbin/:/Applications/Skim.app/Contents/SharedSupport:$PATH" t) (setq exec-path (append '("/usr/local/bin" "/Library/TeX/texbin" "/Applications/Skim.app/Contents/SharedSupport") exec-path)) ;; ;; YaTeX ;; (autoload 'yatex-mode "yatex" "Yet Another LaTeX mode" t) (setq auto-mode-alist (append '(("\\.tex$" . yatex-mode) ("\\.ltx$" . yatex-mode) ("\\.cls$" . yatex-mode) ("\\.sty$" . yatex-mode) ("\\.clo$" . yatex-mode) ("\\.bbl$" . yatex-mode)) auto-mode-alist)) (setq YaTeX-inhibit-prefix-letter t) (setq YaTeX-kanji-code nil) (setq YaTeX-latex-message-code 'utf-8) (setq YaTeX-use-LaTeX2e t) (setq YaTeX-use-AMS-LaTeX t) (setq YaTeX-dvi2-command-ext-alist '(("TeXworks\\|texworks\\|texstudio\\|mupdf\\|SumatraPDF\\|Preview\\|Skim\\|TeXShop\\|evince\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|MicrosoftEdge\\|microsoft-edge\\|Adobe\\|Acrobat\\|AcroRd32\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf"))) (setq tex-command "ptex2pdf -u -l -ot '-synctex=1'") ;(setq tex-command "lualatex -synctex=1") ;(setq tex-command "latexmk") ;(setq tex-command "latexmk -e '$latex=q/uplatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/' -e '$makeindex=q/upmendex %O -o %D %S/' -e '$dvipdf=q/dvipdfmx %O -o %D %S/' -norc -gg -pdfdvi") ;(setq tex-command "latexmk -e '$lualatex=q/lualatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/' -e '$makeindex=q/upmendex %O -o %D %S/' -norc -gg -pdflua") (setq bibtex-command "latexmk -e '$latex=q/uplatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/' -e '$makeindex=q/upmendex %O -o %D %S/' -e '$dvipdf=q/dvipdfmx %O -o %D %S/' -norc -gg -pdfdvi") (setq makeindex-command "latexmk -e '$latex=q/uplatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/' -e '$makeindex=q/upmendex %O -o %D %S/' -e '$dvipdf=q/dvipdfmx %O -o %D %S/' -norc -gg -pdfdvi") (setq dvi2-command "open -a Skim") ;(setq dvi2-command "open -a Preview") ;(setq dvi2-command "open -a TeXShop") ;(setq dvi2-command "/Applications/TeXworks.app/Contents/MacOS/TeXworks") ;(setq dvi2-command "/Applications/texstudio.app/Contents/MacOS/texstudio --pdf-viewer-only") (setq tex-pdfview-command "open -a Skim") ;(setq tex-pdfview-command "open -a Preview") ;(setq tex-pdfview-command "open -a TeXShop") ;(setq tex-pdfview-command "/Applications/TeXworks.app/Contents/MacOS/TeXworks") ;(setq tex-pdfview-command "/Applications/texstudio.app/Contents/MacOS/texstudio --pdf-viewer-only") (setq dviprint-command-format "open -a \"Adobe Acrobat Reader DC\" `echo %s | gsed -e \"s/\\.[^.]*$/\\.pdf/\"`") (add-hook 'yatex-mode-hook '(lambda () (auto-fill-mode -1))) ;; ;; RefTeX with YaTeX ;; ;(add-hook 'yatex-mode-hook 'turn-on-reftex) (add-hook 'yatex-mode-hook '(lambda () (reftex-mode 1) (define-key reftex-mode-map (concat YaTeX-prefix ">") 'YaTeX-comment-region) (define-key reftex-mode-map (concat YaTeX-prefix "<") 'YaTeX-uncomment-region)))
メニュー [YaTeX] キーバインド (setq YaTeX-inhibit-prefix-letter t) 機能 Process -> LaTeX C-c C-t j または C-c C-t C-j upLaTeX (ptex2pdf) Process -> BibTeX C-c C-t b RET bibtexu, biber (upLaTeXmk) Process -> makeindex C-c C-t i RET upmendex (upLaTeXmk) Process -> Preview C-c C-t p RET RET PDF プレビュー Process -> lpr C-c C-t l RET Adobe Acrobat Reader で PDF プレビューまたは印刷 C-c C-g Skim で forward search
~/.emacs.d/init.el に設定を記述します.
fwdevince は Evince/fwdevince にあるものを使用します. Evince の inverse search については Emacs#Evince との連携#inverse search を参照してください.
;; ;; YaTeX ;; (autoload 'yatex-mode "yatex" "Yet Another LaTeX mode" t) (setq auto-mode-alist (append '(("\\.tex$" . yatex-mode) ("\\.ltx$" . yatex-mode) ("\\.cls$" . yatex-mode) ("\\.sty$" . yatex-mode) ("\\.clo$" . yatex-mode) ("\\.bbl$" . yatex-mode)) auto-mode-alist)) (setq YaTeX-inhibit-prefix-letter t) (setq YaTeX-kanji-code nil) (setq YaTeX-latex-message-code 'utf-8) (setq YaTeX-use-LaTeX2e t) (setq YaTeX-use-AMS-LaTeX t) (setq YaTeX-dvi2-command-ext-alist '(("TeXworks\\|texworks\\|texstudio\\|mupdf\\|SumatraPDF\\|Preview\\|Skim\\|TeXShop\\|evince\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|MicrosoftEdge\\|microsoft-edge\\|Adobe\\|Acrobat\\|AcroRd32\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf"))) (setq tex-command "ptex2pdf -u -l -ot '-synctex=1'") ;(setq tex-command "lualatex -synctex=1") ;(setq tex-command "latexmk") ;(setq tex-command "latexmk -e '$latex=q/uplatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/' -e '$makeindex=q/upmendex %O -o %D %S/' -e '$dvipdf=q/dvipdfmx %O -o %D %S/' -norc -gg -pdfdvi") ;(setq tex-command "latexmk -e '$lualatex=q/lualatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/' -e '$makeindex=q/upmendex %O -o %D %S/' -norc -gg -pdflua") (setq bibtex-command "latexmk -e '$latex=q/uplatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/' -e '$makeindex=q/upmendex %O -o %D %S/' -e '$dvipdf=q/dvipdfmx %O -o %D %S/' -norc -gg -pdfdvi") (setq makeindex-command "latexmk -e '$latex=q/uplatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/' -e '$makeindex=q/upmendex %O -o %D %S/' -e '$dvipdf=q/dvipdfmx %O -o %D %S/' -norc -gg -pdfdvi") ;(setq dvi2-command "xdg-open") (setq dvi2-command "evince") ;(setq dvi2-command "atril") ;(setq dvi2-command "okular --unique") ;(setq dvi2-command "zathura -x \"emacsclient --no-wait +%{line} %{input}\"") ;(setq dvi2-command "qpdfview --unique") ;(setq dvi2-command "texworks") ;(setq dvi2-command "texstudio --pdf-viewer-only") ;(setq tex-pdfview-command "xdg-open") (setq tex-pdfview-command "evince") ;(setq tex-pdfview-command "atril") ;(setq tex-pdfview-command "okular --unique") ;(setq tex-pdfview-command "zathura -x \"emacsclient --no-wait +%{line} %{input}\"") ;(setq tex-pdfview-command "qpdfview --unique") ;(setq tex-pdfview-command "texworks") ;(setq tex-pdfview-command "texstudio --pdf-viewer-only") (setq dviprint-command-format "wine64 cmd /c start Acrobat.exe `echo %s | sed -e \"s/\\.[^.]*$/\\.pdf/\"`")
(with-eval-after-load 'yatexprc (defun YaTeX-preview-jump-line () "Call jump-line function of various previewer on current main file" (interactive) (save-excursion (save-restriction (widen) (let*((pf (or YaTeX-parent-file (save-excursion (YaTeX-visit-main t) (buffer-file-name)))) (pdir (file-name-directory pf)) (bnr (substring pf 0 (string-match "\\....$" pf))) ;(cf (file-relative-name (buffer-file-name) pdir)) (cf (buffer-file-name)) ;2016-01-08 (buffer (get-buffer-create " *preview-jump-line*")) (line (count-lines (point-min) (point-end-of-line))) (previewer (YaTeX-preview-default-previewer)) (cmd (cond ((string-match "Skim" previewer) (format "%s %d '%s.pdf' '%s'" YaTeX-cmd-displayline line bnr cf)) ((string-match "evince" previewer) (format "%s '%s.pdf' %d '%s'" "fwdevince" bnr line cf)) ((string-match "sumatra" previewer) (format "%s \"%s.pdf\" -forward-search \"%s\" %d" previewer bnr cf line)) ((string-match "zathura" previewer) (format "%s --synctex-forward '%d:0:%s' '%s.pdf'" previewer line cf bnr)) ((string-match "qpdfview" previewer) (format "%s '%s.pdf#src:%s:%d:0'" previewer bnr cf line)) ((string-match "okular" previewer) (format "%s '%s.pdf#src:%d %s'" previewer bnr line (expand-file-name cf))) ))) (YaTeX-system cmd "jump-line" 'noask pdir))))))
(add-hook 'yatex-mode-hook '(lambda () (auto-fill-mode -1)))
;; ;; RefTeX with YaTeX ;; ;(add-hook 'yatex-mode-hook 'turn-on-reftex) (add-hook 'yatex-mode-hook '(lambda () (reftex-mode 1) (define-key reftex-mode-map (concat YaTeX-prefix ">") 'YaTeX-comment-region) (define-key reftex-mode-map (concat YaTeX-prefix "<") 'YaTeX-uncomment-region)))
メニュー [YaTeX] キーバインド (setq YaTeX-inhibit-prefix-letter t) 機能 Process -> LaTeX C-c C-t j または C-c C-t C-j upLaTeX (ptex2pdf) Process -> BibTeX C-c C-t b RET bibtexu, biber (upLaTeXmk) Process -> makeindex C-c C-t i RET upmendex (upLaTeXmk) Process -> Preview C-c C-t p RET RET PDF プレビュー Process -> lpr C-c C-t l RET Adobe Acrobat Reader で PDF プレビューまたは印刷 C-c C-g Evince で forward search
Okular で forward search
zathura で forward search
qpdfview で forward search
さまざまな機能がありますので、まずは少しだけ。
(setq YaTeX-inhibit-prefix-letter t) を使用してください. (setq YaTeX-inhibit-prefix-letter nil) は,非推奨 (deprecated) です. t と nil ではキーバインドが異なります(前者だと C-c C-t letter,後者だと C-c t letter になる).
(setq YaTeX-inhibit-prefix-letter t)
Linux Mint, Debian GNU/Linux, Vine Linux に収録されている YaTeX の最新版はデフォルトで t となっており,YaTeX の作者も t を推奨しています (YaTeX ML [yatex:04567] を参照). 変更の理由は YaTeX が使用していたキーバインドがユーザー向けに予約されていた C-c letter に設定されていたためと思われます.
https://github.com/emacs-jp/elisp-manual-ja/blob/master/tips.texi#L172-L198 より
- 読者のメジャーモードでは、 C-c letter をキーとして定義しないこと。 これらのキー列はユーザー向けに予約済みである。 それらだけがユーザー向けに予約されたキー列であり、 それらを禁止しないこと。
かわりに、C-c のあとにコントロール文字か数字文字か特定の句読点文字が続く キー列を定義する。 これらのキー列は、メジャーモード用に予約してある。
Emacs のすべてのモードをこの慣習に従うように変換するのは たいへんな作業量であった。 この慣習を捨てさるとその作業をむだにしてしまい、ユーザーにも不便である。
メニュー [YaTeX] キーバインド (setq YaTeX-inhibit-prefix-letter t) 機能 Process -> LaTeX C-c C-t j または C-c C-t C-j タイプセット Process -> LaTeX+PDF C-c C-t d latex + dvipdfmx Process -> Kill LaTeX C-c C-t k タイプセットを中断 Process -> Preview C-c C-t p RET RET プレビュー Process -> BibTeX C-c C-t b RET BibTeX Process -> makeindex C-c C-t i RET MakeIndex Process -> lpr C-c C-t l RET LPR (印刷) C-c C-g forward search C-c ' エラー行にジャンプ M-x yatex 親ファイルの再設定
メニュー [YaTeX] キーバインド (setq YaTeX-inhibit-prefix-letter t) 補完 Environment -> リストから選択 C-c C-b SPC begin 型補完 Environment region -> リストから選択 C-c B SPC 指定領域に対して begin 型補完 Section type -> リストから選択 C-c C-s section 型補完 Section type region (long name) -> リストから選択 C-c S 指定領域に対して section 型補完 C-c C-e end 補完
補完を使わないと
\begin{itemize} \item AUCTeX \item YaTeX \end{今度からはちゃんと ^C b を使いましょう}
と言われます.
begin 型補完を使うのを忘れた場合は
\begin{itemize} \item AUCTeX \item YaTeX
の時に end 補完を使うと
\end{itemize}
を補完してくれます.
入力 タイプセット方式 M-x set-variable RET tex-command RET "latexmk" RET latexmk M-x set-variable RET tex-command RET "pdflatex -synctex=1" RET pdflatex M-x set-variable RET tex-command RET "lualatex -synctex=1" RET lualatex M-x set-variable RET tex-command RET "xelatex -synctex=1" RET xelatex
M-x describe-variable RET tex-command RET
詳細は Yet Another tex-mode for Emacs - Table of Contents をご覧下さい.
ヘッダー部分に用途別に追加してみました.テンプレートとしても使えるかもしれません.
%% -*- coding: utf-8-unix -*- %#!ptex2pdf -u -l -ot "-kanji=utf8 -no-guess-input-enc -synctex=1" hogehoge % #!tasklist /fi "IMAGENAME eq Acrobat.exe" /nh | findstr "Acrobat.exe" > nul && taskkill /im Acrobat.exe & ptex2pdf -u -l hogehoge && start Acrobat hogehoge.pdf %#BIBTEX bibtexu hogehoge %#MAKEINDEX upmendex hogehoge %#LPR if exist "C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" ("C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /p hogehoge.pdf) else "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /p hogehoge.pdf % #LPR acroread.bat /p hogehoge.pdf
\documentclass[uplatex,dvipdfmx,ja=standard]{bxjsarticle} \begin{document} Welcom to YaTeX World! \end{document}
%%% Local Variables: %%% TeX-master: "hogehoge" %%% End:
PDF ファイルでの印刷が多くなってきているので,LPR も PDF ファイルに対応させてみました. パスの通ったところに,acroread.bat というファイル名で以下のスクリプトを保存します.
@echo off REM USAGE: acroread.bat [options] filename if exist "C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" ( "C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" %1 %2 %3 %4 %5 %6 %7 %8 %9 ) else ( "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" %1 %2 %3 %4 %5 %6 %7 %8 %9 )
あくまで一例です。 ぜひ修正、加筆お願いします。
(add-to-list 'load-path "~/.emacs.d/site-lisp/yatex")
(setq auto-mode-alist (append '(("\\.tex$" . yatex-mode)) auto-mode-alist)) (autoload 'yatex-mode "yatex" "Yet Another LaTeX mode" t)
または
(setq auto-mode-alist (cons (cons "\\.tex$" 'yatex-mode) auto-mode-alist)) (autoload 'yatex-mode "yatex" "Yet Another LaTeX mode" t)
YaTeX-kanji-code を nil 以外にすると指定した文字コード以外の TeX ファイルや sty ファイルも指定した文字コードで保存されてしまうので nil を指定することをおすすめします.
YaTeX 1.80 で YaTeX-kanji-code のデフォルトが nil に変更されました.
;;; nil: Do not care (Preserve coding-system) -> ファイルの文字コードを変更せずに保存する ;;; 0: no-converion -> Emacs 内部で使用されている文字コードで保存される(Emacs 23 以降では utf-8-emacs) ;;; 1: Shift JIS (Shift_JIS) -> Shift_JIS で保存される ;;; 2: JIS (ISO-2022-JP) -> ISO-2022-JP で保存される ;;; 3: EUC (EUC-JP) -> EUC-JP で保存される ;;; 4: UTF-8 -> UTF-8 で保存される (setq YaTeX-kanji-code nil)
(setq YaTeX-latex-message-code 'utf-8)
(if (eq system-type 'windows-nt) (setq tex-command "ptex2pdf -u -l -ot \"-kanji=utf8 -no-guess-input-enc -synctex=1\"") (setq tex-command "ptex2pdf -u -l -ot \"-synctex=1\""))
(if (eq system-type 'windows-nt) (setq tex-command "lualatex -synctex=1") (setq tex-command "lualatex -synctex=1"))
(if (eq system-type 'windows-nt) (setq tex-command "latexmk -e \"$latex=q/uplatex %O -kanji=utf8 -no-guess-input-enc -synctex=1 %S/\" -e \"$bibtex=q/bibtexu %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -e \"$dvipdf=q/dvipdfmx %O -o %D %S/\" -norc -gg -pdfdvi") (setq tex-command "latexmk -e '$latex=q/uplatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/' -e '$makeindex=q/upmendex %O -o %D %S/' -e '$dvipdf=q/dvipdfmx %O -o %D %S/' -norc -gg -pdfdvi"))
(if (eq system-type 'windows-nt) (setq tex-command "latexmk -e \"$lualatex=q/lualatex %O -synctex=1 %S/\" -e \"$bibtex=q/bibtexu %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -norc -gg -pdflua") (setq tex-command "latexmk -e '$lualatex=q/lualatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/' -e '$makeindex=q/upmendex %O -o %D %S/' -norc -gg -pdflua"))
(setq bibtex-command "bibtexu")
(setq bibtex-command "biber --bblencoding=utf8 -u -U --output_safechars")
(setq makeindex-command "upmendex")
(setq YaTeX-dvi2-command-ext-alist '(("TeXworks\\|texworks\\|texstudio\\|mupdf\\|SumatraPDF\\|Preview\\|Skim\\|TeXShop\\|evince\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|MicrosoftEdge\\|microsoft-edge\\|Adobe\\|Acrobat\\|AcroRd32\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf")))
(setq dvi2-command "rundll32 shell32,ShellExec_RunDLL SumatraPDF -reuse-instance")
(if (eq system-type 'darwin) (setq dvi2-command "/Applications/TeXworks.app/Contents/MacOS/TeXworks") (setq dvi2-command "texworks"))
(if (eq system-type 'darwin) (setq dvi2-command "/Applications/texstudio.app/Contents/MacOS/texstudio --pdf-viewer-only") (setq dvi2-command "texstudio --pdf-viewer-only"))
(setq dvi2-command "mupdf")
(if (eq system-type 'windows-nt) (setq dvi2-command "powershell -Command \"& {$p = [System.String]::Concat('\"\"\"',[System.IO.Path]::GetFileName($args),'\"\"\"');Start-Process firefox -ArgumentList ('-new-window',$p)}\"") (setq dvi2-command "firefox -new-window"))
(if (eq system-type 'windows-nt) (setq dvi2-command "powershell -Command \"& {$p = [System.String]::Concat('\"\"\"',[System.IO.Path]::GetFullPath($args),'\"\"\"');Start-Process chrome -ArgumentList ('--new-window',$p)}\"") (setq dvi2-command "chromium --new-window"))
(setq dvi2-command "open -a Preview")
(setq dvi2-command "open -a Skim")
(setq dvi2-command "open -a TeXShop")
(setq dvi2-command "evince")
(setq dvi2-command "atril")
(setq dvi2-command "okular --unique")
(setq dvi2-command "zathura -x \"emacsclient --no-wait +%{line} %{input}\"")
(setq dvi2-command "qpdfview --unique")
(setq tex-pdfview-command "rundll32 shell32,ShellExec_RunDLL SumatraPDF -reuse-instance")
(if (eq system-type 'darwin) (setq tex-pdfview-command "/Applications/TeXworks.app/Contents/MacOS/TeXworks") (setq tex-pdfview-command "texworks"))
(if (eq system-type 'darwin) (setq tex-pdfview-command "/Applications/texstudio.app/Contents/MacOS/texstudio --pdf-viewer-only") (setq tex-pdfview-command "texstudio --pdf-viewer-only"))
(setq tex-pdfview-command "mupdf")
(if (eq system-type 'windows-nt) (setq tex-pdfview-command "powershell -Command \"& {$p = [System.String]::Concat('\"\"\"',[System.IO.Path]::GetFileName($args),'\"\"\"');Start-Process firefox -ArgumentList ('-new-window',$p)}\"") (setq tex-pdfview-command "firefox -new-window"))
(if (eq system-type 'windows-nt) (setq tex-pdfview-command "powershell -Command \"& {$p = [System.String]::Concat('\"\"\"',[System.IO.Path]::GetFullPath($args),'\"\"\"');Start-Process chrome -ArgumentList ('--new-window',$p)}\"") (setq tex-pdfview-command "chromium --new-window"))
(setq tex-pdfview-command "open -a Preview")
(setq tex-pdfview-command "open -a Skim")
(setq tex-pdfview-command "open -a TeXShop")
(setq tex-pdfview-command "evince")
(setq tex-pdfview-command "atril")
(setq tex-pdfview-command "okular --unique")
(setq tex-pdfview-command "zathura -x \"emacsclient --no-wait +%{line} %{input}\"")
(setq tex-pdfview-command "qpdfview --unique")
デフォルトでは YaTeX-use-AMS-LaTeX の値は t です. AMS-LaTeX がうまく動作しない場合は YaTeX をロードする前に設定してみてください.(参照 その1, その2)
(setq YaTeX-use-LaTeX2e t) (setq YaTeX-use-AMS-LaTeX t)
(add-hook 'yatex-mode-hook '(lambda () (require 'font-latex) (font-latex-setup)))
(add-hook 'yatex-mode-hook 'turn-on-reftex)
または
(add-hook 'yatex-mode-hook '(lambda () (reftex-mode t)))
YaTeX の comment region, uncomment region, insert parens region のキーバインドを優先させる場合は以下のようにします.(参照 YaTeXとRefTeXの共存)
(add-hook 'yatex-mode-hook '(lambda () (reftex-mode 1) (define-key reftex-mode-map (concat YaTeX-prefix ">") 'YaTeX-comment-region) (define-key reftex-mode-map (concat YaTeX-prefix "<") 'YaTeX-uncomment-region) (define-key reftex-mode-map (concat YaTeX-prefix ")") 'YaTeX-insert-parens-region)))
on の場合
(add-hook 'yatex-mode-hook '(lambda () (auto-fill-mode t) (setq fill-column 70)))
off の場合
(add-hook 'yatex-mode-hook '(lambda () (auto-fill-mode -1)))
;(setq YaTeX-use-font-lock t) ; section color ;(setq YaTeX-hilit-sectioning-face '(light時のforecolor/backcolor dark時の forecolor/backcolor)) ;(setq YaTeX-hilit-sectioning-face '(white/snow3 snow1/snow3)) (add-hook 'yatex-mode-hook '(lambda () (require 'font-latex) (font-latex-setup) (progn (modify-syntax-entry ?% "<" (syntax-table)) (modify-syntax-entry 10 ">" (syntax-table)) (make-variable-buffer-local 'outline-level) (setq outline-level 'latex-outline-level) (make-variable-buffer-local 'outline-regexp) (setq outline-regexp (concat "[ \t]*\\\\\\(documentstyle\\|documentclass\\|chapter\\|" "section\\|subsection\\|subsubsection\\|paragraph\\)" "\\*?[ \t]*[[{]") ))))
(add-hook 'yatex-mode-hook '(lambda () (outline-minor-mode t))) (setq-default outline-level 'outline-level)
(defun latex-outline-level () (save-excursion (looking-at outline-regexp) (let ((title (buffer-substring (match-beginning 1) (match-end 1)))) (cond ((equal (substring title 0 4) "docu") 20) ((equal (substring title 0 4) "para") 15) ((equal (substring title 0 4) "chap") 0) ((equal (substring title 0 4) "appe") 0) (t (length title))))))
(add-hook 'yatex-mode-load-hook (function (lambda () (YaTeX-define-key "w" 'sdic-describe-word) (YaTeX-define-key "\C-w" 'YaTeX-switch-mode-menu))))
(setq YaTeX-math-sign-alist-private '( ("q" "Q" "(Q)") ("z" "Z" "ZZ") ("t""text""text") ("qu" "quad" "__") ("qq" "qquad" "____") ("ls" "varlimsup" "___\nlim") ("li" "varliminf" "lim\n---") ("il" "varinjlim" "lim\n-->") ("pl" "varprojlim" "lim\n<--") ("st" "text{ s.t. }" "s.t.") ("bigop" "bigoplus" "_\n(+)~") ("bigot" "bigotimes" "_\n(x)\n ~") ))
; ~/.LaTeX-templateは新規ファイル作成時に自動挿入するファイル名 (setq YaTeX-template-file "~/.LaTeX-template")
なぜか,\textbf{...}以外の\textXX{...}のフォント変更がうまく働いていないようなので少々 ~/.emacs.d/init.el に追加。ついでに\emph{...}にも対応。
;ここはすでにyatex19.elに記述されてる ;(add-to-list 'YaTeX-hilit-patterns-alist ; '(YaTeX-19-region-section-type "\\\\textbf\\>" bold)) (add-to-list 'YaTeX-hilit-patterns-alist '(YaTeX-19-region-section-type "\\\\textgt\\>" bold)) (add-to-list 'YaTeX-hilit-patterns-alist '(YaTeX-19-region-section-type "\\\\textit\\>" italic)) (add-to-list 'YaTeX-hilit-patterns-alist '(YaTeX-19-region-section-type "\\\\textsl\\>" italic)) (add-to-list 'YaTeX-hilit-patterns-alist '(YaTeX-19-region-section-type "\\\\emph\\>" italic)) (add-to-list 'YaTeX-hilit-patterns-alist '(YaTeX-19-region-section-type "\\\\texttt\\>" tt))
(setq YaTeX-inhibit-prefix-letter t) (setq YaTeX-dvi2-command-ext-alist '(("TeXworks\\|texworks\\|texstudio\\|mupdf\\|SumatraPDF\\|Preview\\|Skim\\|TeXShop\\|evince\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|MicrosoftEdge\\|microsoft-edge\\|Adobe\\|Acrobat\\|AcroRd32\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf"))) (setq dvi2-command "rundll32 shell32,ShellExec_RunDLL SumatraPDF -reuse-instance") (setq tex-pdfview-command "rundll32 shell32,ShellExec_RunDLL SumatraPDF -reuse-instance")
を設定して C-c C-g を入力すれば SumatraPDF で forward seasrch ができます.
(defun fwdsumatrapdf-forward-search () (interactive) (progn (process-query-on-exit-flag (start-process "fwdsumatrapdf" nil "fwdsumatrapdf" (expand-file-name (concat (file-name-sans-extension (or YaTeX-parent-file (save-excursion (YaTeX-visit-main t) buffer-file-name))) ".pdf")) (buffer-name) (number-to-string (save-restriction (widen) (count-lines (point-min) (point))))))))
(add-hook 'yatex-mode-hook '(lambda () (define-key YaTeX-mode-map (kbd "C-c f") 'fwdsumatrapdf-forward-search)))
fwdsumatrapdf は SumatraPDF/fwdsumatrapdf にあるものを使用します. forward search は C-c f または M-x fwdsumatrapdf-forward-search RET をタイプします.
(setq YaTeX-inhibit-prefix-letter t) (setq YaTeX-dvi2-command-ext-alist '(("TeXworks\\|texworks\\|texstudio\\|mupdf\\|SumatraPDF\\|Preview\\|Skim\\|TeXShop\\|evince\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|MicrosoftEdge\\|microsoft-edge\\|Adobe\\|Acrobat\\|AcroRd32\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf"))) (setq dvi2-command "open -a Skim") (setq tex-pdfview-command "open -a Skim")
を設定して C-c C-g を入力すれば Skim で forward seasrch ができます.
Evince/fwdevince をインストールして
(setq YaTeX-inhibit-prefix-letter t) (setq YaTeX-dvi2-command-ext-alist '(("TeXworks\\|texworks\\|texstudio\\|mupdf\\|SumatraPDF\\|Preview\\|Skim\\|TeXShop\\|evince\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|MicrosoftEdge\\|microsoft-edge\\|Adobe\\|Acrobat\\|AcroRd32\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf"))) (setq dvi2-command "evince") (setq tex-pdfview-command "evince")
を設定して C-c C-g を入力すれば Evince で forward seasrch ができます.
Evince の inverse search については Emacs#Evince との連携#inverse search を参照してください.
(setq YaTeX-inhibit-prefix-letter t) (setq YaTeX-dvi2-command-ext-alist '(("TeXworks\\|texworks\\|texstudio\\|mupdf\\|SumatraPDF\\|Preview\\|Skim\\|TeXShop\\|evince\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|MicrosoftEdge\\|microsoft-edge\\|Adobe\\|Acrobat\\|AcroRd32\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf"))) (setq dvi2-command "okular --unique") (setq tex-pdfview-command "okular --unique") (with-eval-after-load 'yatexprc (defun YaTeX-preview-jump-line () "Call jump-line function of various previewer on current main file" (interactive) (save-excursion (save-restriction (widen) (let*((pf (or YaTeX-parent-file (save-excursion (YaTeX-visit-main t) (buffer-file-name)))) (pdir (file-name-directory pf)) (bnr (substring pf 0 (string-match "\\....$" pf))) ;(cf (file-relative-name (buffer-file-name) pdir)) (cf (buffer-file-name)) ;2016-01-08 (buffer (get-buffer-create " *preview-jump-line*")) (line (count-lines (point-min) (point-end-of-line))) (previewer (YaTeX-preview-default-previewer)) (cmd (cond ((string-match "Skim" previewer) (format "%s %d '%s.pdf' '%s'" YaTeX-cmd-displayline line bnr cf)) ((string-match "evince" previewer) (format "%s '%s.pdf' %d '%s'" "fwdevince" bnr line cf)) ((string-match "sumatra" previewer) (format "%s \"%s.pdf\" -forward-search \"%s\" %d" previewer bnr cf line)) ((string-match "zathura" previewer) (format "%s --synctex-forward '%d:0:%s' '%s.pdf'" previewer line cf bnr)) ((string-match "qpdfview" previewer) (format "%s '%s.pdf#src:%s:%d:0'" previewer bnr cf line)) ((string-match "okular" previewer) (format "%s '%s.pdf#src:%d %s'" previewer bnr line (expand-file-name cf))) ))) (YaTeX-system cmd "jump-line" 'noask pdir))))))
を設定して C-c C-g を入力すれば Okular で forward seasrch ができます.
(setq YaTeX-inhibit-prefix-letter t) (setq YaTeX-dvi2-command-ext-alist '(("TeXworks\\|texworks\\|texstudio\\|mupdf\\|SumatraPDF\\|Preview\\|Skim\\|TeXShop\\|evince\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|MicrosoftEdge\\|microsoft-edge\\|Adobe\\|Acrobat\\|AcroRd32\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf"))) (setq dvi2-command "zathura -x \"emacsclient --no-wait +%{line} %{input}\"") (setq tex-pdfview-command "zathura -x \"emacsclient --no-wait +%{line} %{input}\"") (with-eval-after-load 'yatexprc (defun YaTeX-preview-jump-line () "Call jump-line function of various previewer on current main file" (interactive) (save-excursion (save-restriction (widen) (let*((pf (or YaTeX-parent-file (save-excursion (YaTeX-visit-main t) (buffer-file-name)))) (pdir (file-name-directory pf)) (bnr (substring pf 0 (string-match "\\....$" pf))) ;(cf (file-relative-name (buffer-file-name) pdir)) (cf (buffer-file-name)) ;2016-01-08 (buffer (get-buffer-create " *preview-jump-line*")) (line (count-lines (point-min) (point-end-of-line))) (previewer (YaTeX-preview-default-previewer)) (cmd (cond ((string-match "Skim" previewer) (format "%s %d '%s.pdf' '%s'" YaTeX-cmd-displayline line bnr cf)) ((string-match "evince" previewer) (format "%s '%s.pdf' %d '%s'" "fwdevince" bnr line cf)) ((string-match "sumatra" previewer) (format "%s \"%s.pdf\" -forward-search \"%s\" %d" previewer bnr cf line)) ((string-match "zathura" previewer) (format "%s --synctex-forward '%d:0:%s' '%s.pdf'" previewer line cf bnr)) ((string-match "qpdfview" previewer) (format "%s '%s.pdf#src:%s:%d:0'" previewer bnr cf line)) ((string-match "okular" previewer) (format "%s '%s.pdf#src:%d %s'" previewer bnr line (expand-file-name cf))) ))) (YaTeX-system cmd "jump-line" 'noask pdir))))))
を設定して C-c C-g を入力すれば zathura で forward seasrch ができます.
(setq YaTeX-inhibit-prefix-letter t) (setq YaTeX-dvi2-command-ext-alist '(("TeXworks\\|texworks\\|texstudio\\|mupdf\\|SumatraPDF\\|Preview\\|Skim\\|TeXShop\\|evince\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|MicrosoftEdge\\|microsoft-edge\\|Adobe\\|Acrobat\\|AcroRd32\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf"))) (setq dvi2-command "qpdfview --unique") (setq tex-pdfview-command "qpdfview --unique")
を設定して C-c C-g を入力すれば qpdfview で forward seasrch ができます.
yatexadd.elのYaTeX:includegraphicsの最後を下記のように変更
(if (string= "" str) "[clip]" (concat "[" str ",clip]")) ;
yatexhks.elにカスタマイズした関数を記述しておけばYaTeXの入力支援に利用できる. 例えば,enumitemパッケージのenumerate環境でresumeオプションを使うか常に問う場合は次のような関数を記述しておけばよい.
(defun YaTeX:enumerate () ((let (op (if y-or-n-p "resume オプションを使いますか? ") "resume")) (if (> (length op) 0) (concat "[" op "]"))))
普段は upLaTeX (ptex2pdf) を使っていても,投稿先のスタイルシートによっては pdfLaTeX を前提としているものがあります. TeX ソースの先頭行に例えば,
%#!pdflatex
と書いておくと、普段はタイプセットの時に upLaTeX (ptex2pdf) で処理されていても,この場合だけ pdfLaTeX で処理してくれます.
記述例をいくつかあげると,Windows では
%#!ptex2pdf -u -l -ot "-kanji=utf8 -no-guess-input-enc -synctex=1" hogehoge
としたり,macOS, Linux では
%#!ptex2pdf -u -l -ot "-synctex=1" hogehoge
としたりできます.
yatex: tags を参照.