[[Emacs]] > TeX mode

*[[TeX mode:http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/textmodes/tex-mode.el]] &aname(tex-mode); [#e09eebbf]

&color(White,#5F2F2F){  ''◆CONTENTS◆''  };&br;

[[TeX mode:http://www.gnu.org/software/emacs/manual/html_node/emacs/TeX-Mode.html#TeX-Mode]] は TeX ファイルを編集・タイプセット・プレビューするための Emacs のメジャーモードです.
Emacs には標準で含まれています.

標準添付ですが,設定すれば十分に使い物になります.
// 私が普段使っている環境は tex-mode に少し手を入れたものです(RefTeX, Helm や auto-complete も一緒に使っています).-- kmaeda
しかし,TeX mode を拡張したものとして,国内では [[YaTeX]],海外では [[AUCTeX]] がよく使われているため,Web 上の情報量もこれらについてのものが多いです.
機能もこれらの方が豊富なので,どれを使用するかは比較検討して下さい.

----
#contents
----

*TeX mode とは [#b759a43a]
*使い方 [#b6d90b9d]

TeX mode は TeX ファイルを編集・タイプセット・プレビューするためのモードです.~
Emacs には標準で [[TeX mode:http://www.gnu.org/software/emacs/manual/html_node/emacs/TeX-Mode.html#TeX-Mode]] が含まれています.~
スニペットが必要な場合は [[YASnippet]] を使ってください.~
>
|COLOR(#FFF):BGCOLOR(#36A):CENTER:~メニュー [TeX]|COLOR(#FFF):BGCOLOR(#36A):CENTER:~キーバインド|COLOR(#FFF):BGCOLOR(#36A):CENTER:~機能|
|TeX File|C-c C-f|タイプセット|
|TeX Kill|C-c C-k|タイプセットを中断|
|BibTeX File|C-c C-i または C-c TAB|Biblatex, BibTeX|
|TeX View|C-c C-v|プレビュー|
|TeX Print|C-c C-p|印刷|
||C-c C-c|ユーザー定義コマンドの実行|
||C-c C-o|\begin{...} ... \end{...} の補完|
||C-c C-e|\end{...} の補完|
||C-c C-u|環境内の \begin{...} の先頭に移動|
||C-M-m|\item を入力|
||C-c C-m または C-c RET|*tex-shell* バッファに RET を入力として送る|
<

-http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/textmodes/tex-mode.el
-http://git.savannah.gnu.org/gitweb/?p=emacs.git;a=blob;f=lisp/textmodes/tex-mode.el;hb=HEAD
C-c C-f によるタイプセットは,設定ファイルにおいて latex-run-command(latex-mode の場合.tex-mode の場合は tex-run-command)にセットされたコマンドが実行されます.
デフォルトのコマンドは latex,つまり欧文用なので,このままでは日本語は出ません.
下の設定例を参考に,ptex2pdf などに変更して下さい.

**License [#g3e59977]
同様に,BibTeX のコマンドのデフォルトは bibtex,プレビューコマンドのデフォルトは xdvi (X Window System), yap (Windows), dvi2tty(それ以外)ですので,適宜変更する必要があります.

GPLv3
プレビューコマンドと印刷コマンドを PDF ビューアに変更する場合は tex-print-file-extension を ".pdf" に設定して tex-dvi-view-command と tex-dvi-print-command をそれぞれ使用する PDF ビューアに設定してください.

**ChangeLog [#fe3d1392]
platex, uplatex, pdflatex, xelatex, lualatex など,複数のコマンドを併用したいときもあると思います.
このような時にはユーザー定義コマンド (tex-compile-commands) に登録しておくと,C-c C-c で選択することができます.

-http://git.savannah.gnu.org/cgit/emacs.git/log/lisp/textmodes/tex-mode.el
ユーザー定義コマンドは C-c C-c C-i または C-c C-c TAB で一覧が表示できます.
一覧の中からマウスでクリックすると実行されます.
キーボードを使用する場合はある程度キーボードで入力して C-i または TAB を入力すると補完されます.

*注意点 [#m2671d0c]

**" を入力しようとすると `` が入力される → C-q " [#y76d0516]
**" を入力しようとすると `` が入力される [#y76d0516]

TeX mode, AUCTeX, YaTeX では " を入力しようとすると `` が入力されます.
`` ではなく " を入力したい場合は ""(" を2回打つ)か C-q " (Ctrl-Q を入力した後で " を入力) とします.

-[[Emacs + YaTeX でダブルクォーテーションを入力:http://tetu1984.hateblo.jp/entry/20090123/1232651566]]

TeX mode, AUCTeX, YaTeX では " を入力しようとすると `` が入力されます.~
`` ではなく " を入力したい場合は C-q " (Ctrl-Q を入力した後で " を入力) とします.~

*設定 [#x084b3ec]

**Windows [#m2df1dd4]

64-bit Windows の場合は~
[[NTEmacs64:https://github.com/chuntaro/NTEmacs64]] または [[emacs-w64:http://emacsbinw64.sourceforge.net/]]~
32-bit Windows の場合は~
[[NTEmacs:http://cha.la.coocan.jp/doc/NTEmacs.html]]~
をインストールします.~
Emacs を起動して~
Emacs を起動して
 C-x C-f ~/
で,ホームディレクトリ (&#x7e;/) の場所を確認します.~
&#x7e;/.emacs.d/ が無ければ新規に作成します.~
&#x7e;/.emacs.d/init.el に設定を記述します.~
fwdsumatrapdf.exe は [[SumatraPDF/fwdsumatrapdf]] の fwdsumatrapdf.exe を使用します.~
でホームディレクトリ (&#x7e;/) の場所を確認します.
&#x7e;/.emacs.d/ が無ければ新規に作成し,&#x7e;/.emacs.d/init.el に設定を記述します.

**Windows での設定例 [#m2df1dd4]

----
 ;;
 ;; TeX mode
 ;;
 (setq auto-mode-alist
       (append '(("\\.tex$" . latex-mode)) auto-mode-alist))
 (setq tex-default-mode 'latex-mode)
 (setq tex-start-commands "\\nonstopmode\\input")
 (setq tex-run-command "ptex2pdf -u -e -ot \"-kanji=utf8 -no-guess-input-enc -synctex=1 -interaction=nonstopmode\"")
 ;(setq tex-run-command "luatex -synctex=1 -interaction=nonstopmode")
 ;(setq tex-run-command "luajittex -synctex=1 -interaction=nonstopmode")
 ;(setq tex-run-command "xetex -synctex=1 -interaction=nonstopmode")
 ;(setq tex-run-command "pdftex -synctex=1 -interaction=nonstopmode")
 (setq latex-run-command "ptex2pdf -u -l -ot \"-kanji=utf8 -no-guess-input-enc -synctex=1 -interaction=nonstopmode\"")
 ;(setq latex-run-command "lualatex -synctex=1 -interaction=nonstopmode")
 ;(setq latex-run-command "luajitlatex -synctex=1 -interaction=nonstopmode")
 ;(setq latex-run-command "xelatex -synctex=1 -interaction=nonstopmode")
 ;(setq latex-run-command "pdflatex -synctex=1 -interaction=nonstopmode")
 (setq tex-bibtex-command "latexmk -e \"$latex=q/uplatex %O -kanji=utf8 -no-guess-input-enc -synctex=1 -interaction=nonstopmode %S/\" -e \"$bibtex=q/upbibtex %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")
 (require 'tex-mode)
 (defun tex-view ()
   (interactive)
   (tex-send-command "rundll32 shell32,ShellExec_RunDLL SumatraPDF -reuse-instance" (tex-append tex-print-file ".pdf")))
 (defun tex-print (&optional alt)
   (interactive "P")
   (if (tex-shell-running)
       (tex-kill-job)
     (tex-start-shell))
   (tex-send-command "pdfopen --r15 --file" (tex-append tex-print-file ".pdf")))
 (setq tex-bibtex-command "latexmk -e \"$latex=q/uplatex %O -kanji=utf8 -no-guess-input-enc -synctex=1 -interaction=nonstopmode %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-print-file-extension ".pdf")
 (setq tex-dvi-view-command "start SumatraPDF -reuse-instance")
 (setq tex-dvi-print-command "start Acrobat")
 (setq tex-compile-commands
       '(("ptex2pdf -u -l -ot \"-kanji=utf8 -no-guess-input-enc -synctex=1 -interaction=nonstopmode\" %f" "%f" "%r.pdf")
         ("uplatex -kanji=utf8 -no-guess-input-enc -synctex=1 -interaction=nonstopmode %f && dvips -Ppdf -z -f %r.dvi | convbkmk -u > %r.ps && ps2pdf.exe %r.ps" "%f" "%r.pdf")
         ("pdflatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("lualatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("luajitlatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("xelatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("latexmk %f" "%f" "%r.pdf")
         ("latexmk -e \"$latex=q/uplatex %%O -kanji=utf8 -no-guess-input-enc -synctex=1 -interaction=nonstopmode %%S/\" -e \"$bibtex=q/upbibtex %%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 %f" "%f" "%r.pdf")
         ("latexmk -e \"$latex=q/uplatex %%O -kanji=utf8 -no-guess-input-enc -synctex=1 -interaction=nonstopmode %%S/\" -e \"$bibtex=q/upbibtex %%O %%B/\" -e \"$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/\" -e \"$makeindex=q/upmendex %%O -o %%D %%S/\" -e \"$dvips=q/dvips %%O -z -f %%S | convbkmk -u > %%D/\" -e \"$ps2pdf=q/ps2pdf.exe %%O %%S %%D/\" -norc -gg -pdfps %f" "%f" "%r.pdf")
         ("latexmk -e \"$pdflatex=q/pdflatex %%O -synctex=1 -interaction=nonstopmode %%S/\" -e \"$bibtex=q/bibtex %%O %%B/\" -e \"$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/\" -e \"$makeindex=q/makeindex %%O -o %%D %%S/\" -norc -gg -pdf %f" "%f" "%r.pdf")
         ("latexmk -e \"$pdflatex=q/lualatex %%O -synctex=1 -interaction=nonstopmode %%S/\" -e \"$bibtex=q/upbibtex %%O %%B/\" -e \"$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/\" -e \"$makeindex=q/upmendex %%O -o %%D %%S/\" -norc -gg -pdf %f" "%f" "%r.pdf")
         ("latexmk -e \"$pdflatex=q/luajitlatex %%O -synctex=1 -interaction=nonstopmode %%S/\" -e \"$bibtex=q/upbibtex %%O %%B/\" -e \"$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/\" -e \"$makeindex=q/upmendex %%O -o %%D %%S/\" -norc -gg -pdf %f" "%f" "%r.pdf")
         ("latexmk -e \"$pdflatex=q/xelatex %%O -synctex=1 -interaction=nonstopmode %%S/\" -e \"$bibtex=q/upbibtex %%O %%B/\" -e \"$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/\" -e \"$makeindex=q/upmendex %%O -o %%D %%S/\" -norc -gg -pdf %f" "%f" "%r.pdf")
         ("latexmk -e \"$latex=q/uplatex %%O -kanji=utf8 -no-guess-input-enc -synctex=1 -interaction=nonstopmode %%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 %f" "%f" "%r.pdf")
         ("latexmk -e \"$lualatex=q/lualatex %%O -synctex=1 -interaction=nonstopmode %%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 %f" "%f" "%r.pdf")
         ((concat "\\doc-view" " \"" (car (split-string (format "%s" (tex-main-file)) "\\.")) ".pdf\"") "%r.pdf")
         ("powershell -Command \"& {$r = Write-Output %r.pdf;$p = [System.String]::Concat('\"\"\"',[System.IO.Path]::GetFileName($r),'\"\"\"');Start-Process SumatraPDF -ArgumentList ('-reuse-instance',$p)}\"" "%r.pdf")
         ("texworks %r.pdf" "%r.pdf")
         ("texstudio --pdf-viewer-only %r.pdf" "%r.pdf")
         ("powershell -Command \"& {$r = Write-Output %r.pdf;$p = [System.String]::Concat('\"\"\"',[System.IO.Path]::GetFileName($r),'\"\"\"');Start-Process firefox -ArgumentList ('-new-window',$p)}\"" "%r.pdf")
         ("powershell -Command \"& {$r = Write-Output %r.pdf;$p = [System.String]::Concat('\"\"\"',[System.IO.Path]::GetFullPath($r),'\"\"\"');Start-Process chrome -ArgumentList ('--new-window',$p)}\"" "%r.pdf")
         ("pdfopen --r15 --file %r.pdf" "%r.pdf")))
         ("start Acrobat %r.pdf" "%r.pdf")))
 
 (defun sumatrapdf-forward-search ()
   (interactive)
   (let* ((ctf (buffer-name))
          (mtf (tex-main-file))
          (pf (concat (car (split-string mtf "\\.")) ".pdf"))
          (ln (format "%d" (line-number-at-pos)))
          (cmd "rundll32 shell32,ShellExec_RunDLL SumatraPDF")
          (args (concat "-reuse-instance \"" pf "\" -forward-search \"" ctf "\" " ln)))
     (message (concat cmd " " args))
     (process-kill-without-query
     (process-query-on-exit-flag
      (start-process-shell-command "sumatrapdf" nil cmd args))))
 
 (add-hook 'latex-mode-hook
           '(lambda ()
              (define-key latex-mode-map (kbd "C-c s") 'sumatrapdf-forward-search)))
 
 (defun fwdsumatrapdf-forward-search ()
   (interactive)
   (let* ((ctf (buffer-name))
          (mtf (tex-main-file))
          (pf (concat (car (split-string mtf "\\.")) ".pdf"))
          (ln (format "%d" (line-number-at-pos)))
          (cmd "fwdsumatrapdf")
          (args (concat "\"" pf "\" \"" ctf "\" " ln)))
     (message (concat cmd " " args))
     (process-kill-without-query
     (process-query-on-exit-flag
      (start-process-shell-command "fwdsumatrapdf" nil cmd args))))
 
 (add-hook 'latex-mode-hook
           '(lambda ()
              (define-key latex-mode-map (kbd "C-c f") 'fwdsumatrapdf-forward-search)))
 
 ;;
 ;; RefTeX with TeX mode
 ;;
 (add-hook 'latex-mode-hook 'turn-on-reftex)
----

**OS X [#g5794e10]
動作未確認です.~
[[Emacs.app:http://www.muskmelon.jp/?page_id=79]] をインストールします.~
Emacs を起動して~
 C-x C-f ~/
で,ホームディレクトリ (&#x7e;/) の場所を確認します.~
&#x7e;/.emacs.d/ が無ければ新規に作成します.~
&#x7e;/.emacs.d/init.el に設定を記述します.~
**macOS での設定例 [#g5794e10]
動作未確認です.

----
 ;;
 ;; PATH
 ;;
 (setenv "PATH"
         (concat (getenv "PATH") ":/usr/texbin"))
 (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))
 
 ;;
 ;; TeX mode
 ;;
 (setq auto-mode-alist
       (append '(("\\.tex$" . latex-mode)) auto-mode-alist))
 (setq tex-default-mode 'latex-mode)
 (setq tex-start-commands "\\nonstopmode\\input")
 (setq tex-run-command "/usr/texbin/ptex2pdf -u -e -ot '-synctex=1 -interaction=nonstopmode'")
 ;(setq tex-run-command "/usr/texbin/luatex -synctex=1 -interaction=nonstopmode")
 ;(setq tex-run-command "/usr/texbin/luajittex -synctex=1 -interaction=nonstopmode")
 ;(setq tex-run-command "/usr/texbin/xetex -synctex=1 -interaction=nonstopmode")
 ;(setq tex-run-command "/usr/texbin/pdftex -synctex=1 -interaction=nonstopmode")
 (setq latex-run-command "/usr/texbin/ptex2pdf -u -l -ot '-synctex=1 -interaction=nonstopmode'")
 ;(setq latex-run-command "/usr/texbin/lualatex -synctex=1 -interaction=nonstopmode")
 ;(setq latex-run-command "/usr/texbin/luajitlatex -synctex=1 -interaction=nonstopmode")
 ;(setq latex-run-command "/usr/texbin/xelatex -synctex=1 -interaction=nonstopmode")
 ;(setq latex-run-command "/usr/texbin/pdflatex -synctex=1 -interaction=nonstopmode")
 (setq tex-bibtex-command "/usr/texbin/latexmk -e '$latex=q/uplatex %O -synctex=1 -interaction=nonstopmode %S/' -e '$bibtex=q/upbibtex %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")
 (require 'tex-mode)
 (defun tex-view ()
   (interactive)
   (tex-send-command "/usr/bin/open -a Skim.app" (tex-append tex-print-file ".pdf")))
 (defun tex-print (&optional alt)
   (interactive "P")
   (if (tex-shell-running)
       (tex-kill-job)
     (tex-start-shell))
   (tex-send-command "/usr/bin/open -a \"Adobe Reader.app\"" (tex-append tex-print-file ".pdf")))
 (setq tex-run-command "ptex2pdf -u -e -ot '-synctex=1 -interaction=nonstopmode'")
 ;(setq tex-run-command "luatex -synctex=1 -interaction=nonstopmode")
 (setq latex-run-command "ptex2pdf -u -l -ot '-synctex=1 -interaction=nonstopmode'")
 ;(setq latex-run-command "lualatex -synctex=1 -interaction=nonstopmode")
 (setq tex-bibtex-command "latexmk -e '$latex=q/uplatex %O -synctex=1 -interaction=nonstopmode %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-print-file-extension ".pdf")
 (setq tex-dvi-view-command "open -a Skim")
 (setq tex-dvi-print-command "open -a \"Adobe Acrobat Reader DC\"")
 (setq tex-compile-commands
       '(("/usr/texbin/ptex2pdf -u -l -ot '-synctex=1 -interaction=nonstopmode' %f" "%f" "%r.pdf")
         ("/usr/texbin/uplatex -synctex=1 -interaction=nonstopmode %f && /usr/texbin/dvips -Ppdf -z -f %r.dvi | /usr/texbin/convbkmk -u > %r.ps && /usr/local/bin/ps2pdf %r.ps" "%f" "%r.pdf")
         ("/usr/texbin/pdflatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("/usr/texbin/lualatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("/usr/texbin/luajitlatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("/usr/texbin/xelatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("/usr/texbin/latexmk %f" "%f" "%r.pdf")
         ("/usr/texbin/latexmk -e '$latex=q/uplatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/upbibtex %%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 %f" "%f" "%r.pdf")
         ("/usr/texbin/latexmk -e '$latex=q/uplatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/upbibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/upmendex %%O -o %%D %%S/' -e '$dvips=q/dvips %%O -z -f %%S | convbkmk -u > %%D/' -e '$ps2pdf=q/ps2pdf %%O %%S %%D/' -norc -gg -pdfps %f" "%f" "%r.pdf")
         ("/usr/texbin/latexmk -e '$pdflatex=q/pdflatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/bibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/makeindex %%O -o %%D %%S/' -norc -gg -pdf %f" "%f" "%r.pdf")
         ("/usr/texbin/latexmk -e '$pdflatex=q/lualatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/upbibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/upmendex %%O -o %%D %%S/' -norc -gg -pdf %f" "%f" "%r.pdf")
         ("/usr/texbin/latexmk -e '$pdflatex=q/luajitlatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/upbibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/upmendex %%O -o %%D %%S/' -norc -gg -pdf %f" "%f" "%r.pdf")
         ("/usr/texbin/latexmk -e '$pdflatex=q/xelatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/upbibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/upmendex %%O -o %%D %%S/' -norc -gg -pdf %f" "%f" "%r.pdf")
       '(("ptex2pdf -u -l -ot '-synctex=1 -interaction=nonstopmode' %f" "%f" "%r.pdf")
         ("lualatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("latexmk %f" "%f" "%r.pdf")
         ("latexmk -e '$latex=q/uplatex %%O -synctex=1 -interaction=nonstopmode %%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 %f" "%f" "%r.pdf")
         ("latexmk -e '$lualatex=q/lualatex %%O -synctex=1 -interaction=nonstopmode %%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 %f" "%f" "%r.pdf")
         ((concat "\\doc-view" " \"" (car (split-string (format "%s" (tex-main-file)) "\\.")) ".pdf\"") "%r.pdf")
         ("/usr/bin/open -a Skim.app %r.pdf" "%r.pdf")
         ("/usr/bin/open -a Preview.app %r.pdf" "%r.pdf")
         ("/usr/bin/open -a TeXShop.app %r.pdf" "%r.pdf")
         ("open -a Skim %r.pdf" "%r.pdf")
         ("open -a Preview %r.pdf" "%r.pdf")
         ("open -a TeXShop %r.pdf" "%r.pdf")
         ("/Applications/TeXworks.app/Contents/MacOS/TeXworks %r.pdf" "%r.pdf")
         ("/Applications/texstudio.app/Contents/MacOS/texstudio --pdf-viewer-only %r.pdf" "%r.pdf")
         ("/usr/bin/open -a Firefox.app %r.pdf" "%r.pdf")
         ("/usr/bin/open -a \"Adobe Reader.app\" %r.pdf" "%r.pdf")))
         ("open -a Firefox %r.pdf" "%r.pdf")
         ("open -a \"Google Chrome\" %r.pdf" "%r.pdf")
         ("open -a \"Adobe Acrobat Reader DC\" %r.pdf" "%r.pdf")))
 
 (defun skim-forward-search ()
   (interactive)
   (let* ((ctf (buffer-name))
          (mtf (tex-main-file))
          (pf (concat (car (split-string mtf "\\.")) ".pdf"))
          (ln (format "%d" (line-number-at-pos)))
          (cmd "/Applications/Skim.app/Contents/SharedSupport/displayline")
          (args (concat ln " " pf " " ctf)))
     (message (concat cmd " " args))
     (process-kill-without-query
     (process-query-on-exit-flag
      (start-process-shell-command "displayline" nil cmd args))))
 
 (add-hook 'latex-mode-hook
           '(lambda ()
              (define-key latex-mode-map (kbd "C-c s") 'skim-forward-search)))
 
 ;;
 ;; RefTeX with TeX mode
 ;;
 (add-hook 'latex-mode-hook 'turn-on-reftex)
----

**Linux [#q1bd16f3]
**Linux での設定例 [#q1bd16f3]

Emacs を起動して~
 C-x C-f ~/
で,ホームディレクトリ (&#x7e;/) の場所を確認します.~
&#x7e;/.emacs.d/ が無ければ新規に作成します.~
&#x7e;/.emacs.d/init.el に設定を記述します.~
fwdevince は [[Evince/fwdevince]] の fwdevince を使用します.~
fwdevince は [[Evince/fwdevince]] にあるものを使用することを想定します.
----
 ;;
 ;; TeX mode
 ;;
 (setq auto-mode-alist
       (append '(("\\.tex$" . latex-mode)) auto-mode-alist))
 (setq tex-default-mode 'latex-mode)
 (setq tex-start-commands "\\nonstopmode\\input")
 (setq tex-run-command "ptex2pdf -u -e -ot '-synctex=1 -interaction=nonstopmode'")
 ;(setq tex-run-command "luatex -synctex=1 -interaction=nonstopmode")
 ;(setq tex-run-command "luajittex -synctex=1 -interaction=nonstopmode")
 ;(setq tex-run-command "xetex -synctex=1 -interaction=nonstopmode")
 ;(setq tex-run-command "pdftex -synctex=1 -interaction=nonstopmode")
 (setq latex-run-command "ptex2pdf -u -l -ot '-synctex=1 -interaction=nonstopmode'")
 ;(setq latex-run-command "lualatex -synctex=1 -interaction=nonstopmode")
 ;(setq latex-run-command "luajitlatex -synctex=1 -interaction=nonstopmode")
 ;(setq latex-run-command "xelatex -synctex=1 -interaction=nonstopmode")
 ;(setq latex-run-command "pdflatex -synctex=1 -interaction=nonstopmode")
 (setq tex-bibtex-command "latexmk -e '$latex=q/uplatex %O -synctex=1 -interaction=nonstopmode %S/' -e '$bibtex=q/upbibtex %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")
 (require 'tex-mode)
 (defun tex-view ()
   (interactive)
   (tex-send-command "xdg-open" (tex-append tex-print-file ".pdf") " &"))
 (defun tex-print (&optional alt)
   (interactive "P")
   (if (tex-shell-running)
       (tex-kill-job)
     (tex-start-shell))
   (tex-send-command "xdg-open" (tex-append tex-print-file ".pdf") " &"))
 (setq tex-bibtex-command "latexmk -e '$latex=q/uplatex %O -synctex=1 -interaction=nonstopmode %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-print-file-extension ".pdf")
 (setq tex-dvi-view-command "evince")
 (setq tex-dvi-print-command "perl -e 'system(\"wine64 cmd /c start Acrobat.exe `basename $ARGV[0]`\")'")
 (setq tex-compile-commands
       '(("ptex2pdf -u -l -ot '-synctex=1 -interaction=nonstopmode' %f" "%f" "%r.pdf")
         ("uplatex -synctex=1 -interaction=nonstopmode %f && dvips -Ppdf -z -f %r.dvi | convbkmk -u > %r.ps && ps2pdf %r.ps" "%f" "%r.pdf")
         ("pdflatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("lualatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("luajitlatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("xelatex -synctex=1 -interaction=nonstopmode %f" "%f" "%r.pdf")
         ("latexmk %f" "%f" "%r.pdf")
         ("latexmk -e '$latex=q/uplatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/upbibtex %%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 %f" "%f" "%r.pdf")
         ("latexmk -e '$latex=q/uplatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/upbibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/upmendex %%O -o %%D %%S/' -e '$dvips=q/dvips %%O -z -f %%S | convbkmk -u > %%D/' -e '$ps2pdf=q/ps2pdf %%O %%S %%D/' -norc -gg -pdfps %f" "%f" "%r.pdf")
         ("latexmk -e '$pdflatex=q/pdflatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/bibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/makeindex %%O -o %%D %%S/' -norc -gg -pdf %f" "%f" "%r.pdf")
         ("latexmk -e '$pdflatex=q/lualatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/upbibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/upmendex %%O -o %%D %%S/' -norc -gg -pdf %f" "%f" "%r.pdf")
         ("latexmk -e '$pdflatex=q/luajitlatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/upbibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/upmendex %%O -o %%D %%S/' -norc -gg -pdf %f" "%f" "%r.pdf")
         ("latexmk -e '$pdflatex=q/xelatex %%O -synctex=1 -interaction=nonstopmode %%S/' -e '$bibtex=q/upbibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/upmendex %%O -o %%D %%S/' -norc -gg -pdf %f" "%f" "%r.pdf")
         ("latexmk -e '$latex=q/uplatex %%O -synctex=1 -interaction=nonstopmode %%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 %f" "%f" "%r.pdf")
         ("latexmk -e '$lualatex=q/lualatex %%O -synctex=1 -interaction=nonstopmode %%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 %f" "%f" "%r.pdf")
         ((concat "\\doc-view" " \"" (car (split-string (format "%s" (tex-main-file)) "\\.")) ".pdf\"") "%r.pdf")
         ("xdg-open %r.pdf &" "%r.pdf")
         ("evince %r.pdf &" "%r.pdf")
         ("okular --unique %r.pdf &" "%r.pdf")
         ("zathura -s -x \"emacsclient --no-wait +%%{line} %%{input}\" %r.pdf &" "%r.pdf")
         ("zathura -x \"emacsclient --no-wait +%%{line} %%{input}\" %r.pdf &" "%r.pdf")
         ("qpdfview --unique %r.pdf &" "%r.pdf")
         ("texworks %r.pdf &" "%r.pdf")
         ("texstudio --pdf-viewer-only %r.pdf" "%r.pdf")
         ("mupdf %r.pdf &" "%r.pdf")
         ("firefox -new-window %r.pdf &" "%r.pdf")
         ("chromium --new-window %r.pdf &" "%r.pdf")))
         ("chromium --new-window %r.pdf &" "%r.pdf")
         ("wine64 cmd /c start Acrobat.exe %r.pdf &" "%r.pdf")))
 
 (defun evince-forward-search ()
   (interactive)
   (let* ((ctf (buffer-name))
          (mtf (tex-main-file))
          (pf (concat (car (split-string mtf "\\.")) ".pdf"))
          (ln (format "%d" (line-number-at-pos)))
          (cmd "fwdevince")
          (args (concat "\"" pf "\" " ln " \"" ctf "\"")))
     (message (concat cmd " " args))
     (process-kill-without-query
     (process-query-on-exit-flag
      (start-process-shell-command "fwdevince" nil cmd args))))
 
 (add-hook 'latex-mode-hook
           '(lambda ()
              (define-key latex-mode-map (kbd "C-c e") 'evince-forward-search)))
 
 (require 'dbus)
 
 (defun un-urlify (fname-or-url)
   "A trivial function that replaces a prefix of file:/// with just /."
   (if (string= (substring fname-or-url 0 8) "file:///")
       (substring fname-or-url 7)
     fname-or-url))
 
 (defun evince-inverse-search (file linecol &rest ignored)
   (let* ((fname (un-urlify file))
   (let* ((fname (decode-coding-string (url-unhex-string (un-urlify file)) 'utf-8))
          (buf (find-file fname))
          (line (car linecol))
          (col (cadr linecol)))
     (if (null buf)
         (message "[Synctex]: %s is not opened..." fname)
       (switch-to-buffer buf)
       (goto-line (car linecol))
       (unless (= col -1)
         (move-to-column col)))))
         (move-to-column col))
       (x-focus-frame (selected-frame)))))
 
 (dbus-register-signal
  :session nil "/org/gnome/evince/Window/0"
  "org.gnome.evince.Window" "SyncSource"
  'evince-inverse-search)
 
 (defun okular-forward-search ()
   (interactive)
   (let* ((ctf (buffer-file-name))
          (mtf (tex-main-file))
          (pf (concat (car (split-string mtf "\\.")) ".pdf"))
          (ln (format "%d" (line-number-at-pos)))
          (cmd "okular")
          (args (concat "--unique \"file:" pf "#src:" ln " " ctf "\"")))
     (message (concat cmd " " args))
     (process-kill-without-query
     (process-query-on-exit-flag
      (start-process-shell-command "okular" nil cmd args))))
 
 (add-hook 'latex-mode-hook
           '(lambda ()
              (define-key latex-mode-map (kbd "C-c o") 'okular-forward-search)))
 
 (defun zathura-forward-search ()
   (interactive)
   (let* ((ctf (buffer-name))
          (mtf (tex-main-file))
          (pf (concat (car (split-string mtf "\\.")) ".pdf"))
          (ln (format "%d" (line-number-at-pos)))
          (cmd "zathura")
          (args (concat "--synctex-forward " ln ":0:" ctf " " pf)))
     (message (concat cmd " " args))
     (process-kill-without-query
     (process-query-on-exit-flag
      (start-process-shell-command "zathura" nil cmd args))))
 
 (add-hook 'latex-mode-hook
           '(lambda ()
              (define-key latex-mode-map (kbd "C-c z") 'zathura-forward-search)))
 
 (defun qpdfview-forward-search ()
   (interactive)
   (let* ((ctf (buffer-name))
          (mtf (tex-main-file))
          (pf (concat (car (split-string mtf "\\.")) ".pdf"))
          (ln (format "%d" (line-number-at-pos)))
          (cmd "qpdfview")
          (args (concat "--unique \"" pf "#src:" ctf ":" ln ":0\"")))
     (message (concat cmd " " args))
     (process-kill-without-query
     (process-query-on-exit-flag
      (start-process-shell-command "qpdfview" nil cmd args))))
 
 (add-hook 'latex-mode-hook
           '(lambda ()
              (define-key latex-mode-map (kbd "C-c q") 'qpdfview-forward-search)))
 
 ;;
 ;; RefTeX with TeX mode
 ;;
 (add-hook 'latex-mode-hook 'turn-on-reftex)
----
*使い方 [#b6d90b9d]

>
|COLOR(#FFF):BGCOLOR(#36A):CENTER:~メニュー [TeX]|COLOR(#FFF):BGCOLOR(#36A):CENTER:~入力|COLOR(#FFF):BGCOLOR(#36A):CENTER:~機能|
|TeX File|C-c C-f|タイプセット|
|TeX Kill|C-c C-k|タイプセットを中断|
|BibTeX File|C-c C-i または C-c TAB|Biblatex, BibTeX|
|TeX View|C-c C-v|プレビュー|
|TeX Print|C-c C-p|印刷|
||C-c C-c|ユーザー定義コマンドの実行|
<
*関連リンク [#ca23f166]

ユーザー定義コマンドは C-c C-c C-i または C-c C-c TAB で一覧が表示できます.~
一覧の中からマウスでクリックすると実行されます.~
キーボードを使用する場合はある程度キーボードで入力して C-i または TAB を入力すると補完されます.~
-[[TeX Mode - GNU Emacs Manual:https://www.gnu.org/software/emacs/manual/html_node/emacs/TeX-Mode.html#TeX-Mode]]
-[[TeX Mode (GNU Emacs Manual(Japanese Translation)):https://ayatakesi.github.io/emacs/26.1/html/TeX-Mode.html#TeX-Mode]]
-[[RefTeX User Manual:https://www.gnu.org/software/emacs/manual/html_node/reftex/]]
-[[【電脳】Mac OS Xで「EmacsでLaTeXファイルを編集→pdflatexでコンパイル→Previewでプレビュー」を繰り返す【自動リロード】:https://srad.jp/~t-nissie/journal/560083]]

----
>
|COLOR(#FFF):BGCOLOR(#36A):CENTER:~入力|COLOR(#FFF):BGCOLOR(#36A):CENTER:~機能|
|C-c C-o|\begin{...} ... \end{...} の補完|
|C-c C-e|\end{...} の補完|
|C-c C-u|環境内の \begin{...} の先頭に移動|
<
----
&color(#3465A4,#3465A4){%%% %%%};[[&ref(http://upload.wikimedia.org/wikipedia/commons/thumb/0/08/EmacsIcon.svg/200px-EmacsIcon.svg.png,around,28x28,GNU Emacs - GNU Project - Free Software Foundation (FSF));>http://www.gnu.org/software/emacs/]]&color(#3465A4,#3465A4){%%%               &color(Black){''emacs@TeX mode''};       &color(#3465A4,#3465A4){%%%[ &color(Black){''◛''}; ]%%%};&color(#3465A4,#3465A4){%%%[ &color(Black){''▭''}; ]%%%};&color(#DD4444,#DD4444){%%%[ &color(White){''×''}; ]%%%};%%%};&br;
&color(Black,#DAE0FE){%%%  ファイル  編集  オプション  バッファ  ツール  TeX  Ref  ヘルプ    %%%};&br;
...&br;
&#x2d;U\---  ''emacs.tex''     Top L1   (LaTeX Ref)-------------------&br;
----
&color(#3465A4,#3465A4){%%% %%%};[[&ref(http://upload.wikimedia.org/wikipedia/commons/thumb/0/08/EmacsIcon.svg/200px-EmacsIcon.svg.png,around,28x28,GNU Emacs - GNU Project - Free Software Foundation (FSF));>http://www.gnu.org/software/emacs/]]&color(#3465A4,#3465A4){%%%                         &color(Black){''emacs@TeX mode''};                 &color(#3465A4,#3465A4){%%%[ &color(Black){''◛''}; ]%%%};&color(#3465A4,#3465A4){%%%[ &color(Black){''▭''}; ]%%%};&color(#DD4444,#DD4444){%%%[ &color(White){''×''}; ]%%%};%%%};&br;
&color(Black,#DAE0FE){%%%  ファイル  編集  オプション  バッファ  ツール  TeX  Errors  Complete  In/Out  Signals  ヘルプ    %%%};&br;
...&br;
&#x2d;U\---  ''emacs.tex''     Top L1   (LaTeX Ref)-----------------------------------------------&br;
...&br;
&#x2d;S:**-  ''*tex-shell*''     Bot L1   (TeX-Shell:run Shell-Compile)--------------------------------&br;
----
**レポジトリ [#kdedd1cc]
-http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/textmodes/tex-mode.el
-http://git.savannah.gnu.org/gitweb/?p=emacs.git;a=blob;f=lisp/textmodes/tex-mode.el;hb=HEAD

*関連リンク [#ca23f166]
**ChangeLog [#fe3d1392]

-[[TeX Mode - GNU Emacs Manual:http://www.gnu.org/software/emacs/manual/html_node/emacs/TeX-Mode.html#TeX-Mode]]
-[[RefTeX User Manual:http://www.gnu.org/software/emacs/manual/html_node/reftex/]]
-[[Using pdfTeX in Emacs `tex-mode':http://www.emacswiki.org/emacs/PdfTeX]]
-[[LaTeX メモ#Emacs との連携:http://www-is.amp.i.kyoto-u.ac.jp/lab/kmaeda/latex/#emacs]]
-[[西谷・平山研Hiki - LaTeX-mode:http://www.kono.cis.iwate-u.ac.jp/~hiki/?LaTeX-mode]]
-[[MacPortsでインストールしたTeXLive2013をEmacsのTeX-modeで使う:http://d.hatena.ne.jp/tnil/20130824/1377290688]]
-[[Emacs.app の設定 - マスクメロン:http://www.muskmelon.jp/?page_id=410]]
-[[【電脳】Mac OS Xで「EmacsでLaTeXファイルを編集→pdflatexでコンパイル→Previewでプレビュー」を繰り返す【自動リロード】:http://slashdot.jp/~t-nissie/journal/560083]]
-http://git.savannah.gnu.org/cgit/emacs.git/log/lisp/textmodes/tex-mode.el