Emacs > YaTeX
YaTeX(野鳥)は Emacs の TeX 用メジャーモードです. TeX mode に比べ機能が大幅に拡張されています. もう一つ,有名な拡張として AUCTeX があり,海外ではこちらがよく使われているようです. 国内では YaTeX の方が人気があり,そのため日本語の情報が Web 上でたくさん見つかります.

YaTeX, TeX mode, AUCTeX では " を入力しようとすると `` が入力されます. `` ではなく " を入力したい場合は C-q " (Ctrl-Q を入力した後で " を入力) とします.
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\\|papers\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|msedge\\|Adobe\\|Acrobat\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf")))
(setq tex-command "lualatex -synctex=1")
;(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 \"$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 bibtex-command "bibtexu")
(setq makeindex-command "upmendex")
(setq dvi2-command (concat "\"C:/Users/" (getenv "USERNAME") "/AppData/Local/SumatraPDF/SumatraPDF.exe\" -reuse-instance"))
(setq tex-pdfview-command (concat "\"C:/Users/" (getenv "USERNAME") "/AppData/Local/SumatraPDF/SumatraPDF.exe\" -reuse-instance"))
(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 LuaLaTeX Process -> BibTeX C-c C-t b RET bibtexu Process -> makeindex C-c C-t i RET upmendex 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\\|papers\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|msedge\\|Adobe\\|Acrobat\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf")))
(setq tex-command "lualatex -synctex=1")
;(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 '$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 bibtex-command "bibtexu")
(setq makeindex-command "upmendex")
(setq dvi2-command "open -a Skim")
(setq tex-pdfview-command "open -a Skim")
(setq dviprint-command-format "open -a \"Adobe Acrobat\" `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 LuaLaTeX Process -> BibTeX C-c C-t b RET bibtexu Process -> makeindex C-c C-t i RET upmendex 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 に設定を記述します.
;;
;; 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\\|papers\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|msedge\\|Adobe\\|Acrobat\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf")))
(setq tex-command "lualatex -synctex=1")
;(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 '$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 bibtex-command "bibtexu")
(setq makeindex-command "upmendex")
(setq dvi2-command "okular --unique")
(setq tex-pdfview-command "okular --unique")
(setq dviprint-command-format "wine64 cmd /c start Acrobat.exe `echo %s | sed -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 LuaLaTeX Process -> BibTeX C-c C-t b RET bibtexu Process -> makeindex C-c C-t i RET upmendex 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 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 -*-
%#!lualatex -synctex=1 hogehoge
% #!tasklist /fi "IMAGENAME eq Acrobat.exe" /nh | findstr "Acrobat.exe" > nul && taskkill /im Acrobat.exe & lualatex 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 rundll32 shell32,ShellExec_RunDLL Acrobat /p hogehoge.pdf
% #LPR acroread.bat /p hogehoge.pdf
\documentclass{jlreq}
\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 ( rundll32 shell32,ShellExec_RunDLL Acrobat %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)
(setq tex-command "lualatex -synctex=1")
(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"))
(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 -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 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\\|papers\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|msedge\\|Adobe\\|Acrobat\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf")))
(setq dvi2-command (concat "\"C:/Users/" (getenv "USERNAME") "/AppData/Local/SumatraPDF/SumatraPDF.exe\" -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 "okular --unique")
(setq dvi2-command "zathura -x \"emacsclient --no-wait +%{line} %{input}\"")
(setq dvi2-command "qpdfview --unique")
(setq tex-pdfview-command (concat "\"C:/Users/" (getenv "USERNAME") "/AppData/Local/SumatraPDF/SumatraPDF.exe\" -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 "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 をロードする前に設定してみてください.
(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\\|papers\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|msedge\\|Adobe\\|Acrobat\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf")))
(setq dvi2-command (concat "\"C:/Users/" (getenv "USERNAME") "/AppData/Local/SumatraPDF/SumatraPDF.exe\" -reuse-instance"))
(setq tex-pdfview-command (concat "\"C:/Users/" (getenv "USERNAME") "/AppData/Local/SumatraPDF/SumatraPDF.exe\" -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\\|papers\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|msedge\\|Adobe\\|Acrobat\\|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 ができます.
(setq YaTeX-inhibit-prefix-letter t)
(setq YaTeX-dvi2-command-ext-alist
'(("TeXworks\\|texworks\\|texstudio\\|mupdf\\|SumatraPDF\\|Preview\\|Skim\\|TeXShop\\|papers\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|msedge\\|Adobe\\|Acrobat\\|acroread\\|pdfopen\\|xdg-open\\|open\\|start" . ".pdf")))
(setq dvi2-command "okular --unique")
(setq tex-pdfview-command "okular --unique")
を設定して 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\\|papers\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|msedge\\|Adobe\\|Acrobat\\|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 "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\\|papers\\|atril\\|xreader\\|okular\\|zathura\\|qpdfview\\|Firefox\\|firefox\\|chrome\\|chromium\\|msedge\\|Adobe\\|Acrobat\\|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 "]"))))
普段は LuaLaTeX を使っていても,投稿先のスタイルシートによっては pdfLaTeX を前提としているものがあります. TeX ソースの先頭行に例えば,
%#!pdflatex
と書いておくと、普段はタイプセットの時に LuaLaTeX で処理されていても,この場合だけ pdfLaTeX で処理してくれます.
記述例をあげると,
%#!lualatex -synctex=1 hogehoge
としたりできます.