MacOSのTex環境導入

自宅のMacにTex環境を構築しました。そのときの備忘録を残しておこうと思います。

方針

TexWikiに記載している通りにインストールしていけば大丈夫です。MacTexのインストーラをダウンロードして、TexLive2013、GUI Application、Fontをインストールし、HomebrewでGhostscriptとImageMagickをインストールしました。エディタはEmacsを使用しているのでYatexを使用しています。

MacTexのインストール

  1. MacTexのインストール
  2. Pathの追加
  3. TexLiveのアップデート
  4. texmf.cnfの更新
  5. 日本語環境の整備

MacTexのインストール

MacTexからMacTex.pkgをダウンロード。パッケージをカスタマイズする際に、TexLive2013、GUI Application、Fontにチェックしてインストールを行います。

Pathの追加

Tex Wikiの手順にはインストールするとパスが追加される、とあったのですが、追加されなかったので手動で追加します。私はpathの設定はzshenvに記載しているので、そこに/usr/texbinを追加しています。

TexLiveのアップデート

下記のコマンドでアップデート可能です。割りと時間がかかります。

sudo tlmgr update --self --all

texmf.cnfの更新

/usr/local/texlive/texmf-local/web2c/texmf.cnf を新規作成し、編集します。

shell_escape_commands = \
bibtex,bibtex8,bibtexu,pbibtex,upbibtex,biber,\
kpsewhich,\
makeindex,mendex,texindy,\
mpost,pmpost,upmpost,\
repstopdf,epspdf,extractbb

% guess input enc
PTEX_IN_FILTER = /usr/local/bin/nkf -w

日本語環境の整備

ヒラギノフォントを使用したいので、下記コマンドを実行します。

$ sudo mkdir -p /usr/local/texlive/texmf-local/fonts/opentype/hiragino/
$ cd /usr/local/texlive/texmf-local/fonts/opentype/hiragino/
$ sudo ln -fs "/Library/Fonts/ヒラギノ明朝 Pro W3.otf" ./HiraMinPro-W3.otf
$ sudo ln -fs "/Library/Fonts/ヒラギノ明朝 Pro W6.otf" ./HiraMinPro-W6.otf
$ sudo ln -fs "/Library/Fonts/ヒラギノ丸ゴ Pro W4.otf" ./HiraMaruPro-W4.otf
$ sudo ln -fs "/Library/Fonts/ヒラギノ角ゴ Pro W3.otf" ./HiraKakuPro-W3.otf
$ sudo ln -fs "/Library/Fonts/ヒラギノ角ゴ Pro W6.otf" ./HiraKakuPro-W6.otf
$ sudo ln -fs "/Library/Fonts/ヒラギノ角ゴ Std W8.otf" ./HiraKakuStd-W8.otf
$ sudo mktexlsr

$ sudo kanji-config-updmap-sys hiragino

Homebrewで必要なパッケージをインストール

  1. brew install ghostscript
  2. brew install imagemagick
  3. brew install nkf

Yatexのインストール

結局、これが一番はまった。ELPAにはないようなのでel-get経由でインストールしました。el-getもSTABLE(4.1)にはパッケージがなかったため、自分でRECIPEを書く必要がありました。

recipeファイルの作成

  1. el-getでインストール
  2. .loaddefs.elの編集
  3. init.elの編集

recipeファイルの作成

(el-get-recipe-path)で指定したディレクトリにyatex.rcpファイルを作成し、下記内容を追加。

(:name yatex
       :website "http://www.yatex.org/"
       :description "Yet Another TeX mode for Emacs"
       :type hg
       :url "http://www.yatex.org/hgrepos/yatex"
)

el-getでインストール

M-x el-get-install RET yatex

.loaddefs.elの編集

Emacsを再起動するとinit.elでエラーが発生。~/.emacs.d/el-get/.loaddefs.el を編集

;;;### (autoloads (YaTeX-goto-corresponding-paren) "yatex/yatexmth"
;;;;;;  "yatex/yatexmth.el" (21108 60721 0 0))
;;; Generated autoloads from yatex/yatexmth.el
from yatex.el

(autoload 'YaTeX-goto-corresponding-paren "yatex/yatexmth" "\
Go to corresponding mathematical parentheses.

↑のfrom yatex.elでエラーが発生しているのでコメントする

;;;### (autoloads (YaTeX-goto-corresponding-paren) "yatex/yatexmth"
;;;;;;  "yatex/yatexmth.el" (21108 60721 0 0))
;;; Generated autoloads from yatex/yatexmth.el from yatex.el

(autoload 'YaTeX-goto-corresponding-paren "yatex/yatexmth" "\
Go to corresponding mathematical parentheses.

init.elの編集

これもMacTexにサンプルファイルがあるので、そのままコピーすればOK。私の場合は起動速度をあげるためにlazyloadを利用しているので、少し修正して、下記のようにした。

; -*- Mode: Emacs-Lisp ; Coding: utf-8 -*-
;; ----------------------------------------------------------------------
;; @ yatex
;; http://oku.edu.mie-u.ac.jp/~okumura/texwiki/?YaTeX

(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))
;;
;; YaTeX
;;

(lazyload (yatex-mode) "yatex"

          ;; key-bind
          (define-key YaTeX-mode-map (kbd "C-c s") 'skim-forward-search)


          (setq YaTeX-inhibit-prefix-letter t)
          (setq YaTeX-kanji-code nil)
          (setq YaTeX-use-LaTeX2e t)
          (setq YaTeX-use-AMS-LaTeX t)
          (setq YaTeX-dvi2-command-ext-alist
                '(("Preview\\|TeXShop\\|TeXworks\\|Skim\\|mupdf\\|xpdf\\|Firefox\\|Adobe" . ".pdf")))
          (setq tex-command "/usr/texbin/ptex2pdf -l -ot '-synctex=1'")
                                        ;(setq tex-command "/usr/texbin/ptex2pdf -l -u -ot '-synctex=1'")
                                        ;(setq tex-command "/usr/texbin/pdflatex -synctex=1")
                                        ;(setq tex-command "/usr/texbin/lualatex -synctex=1")
                                        ;(setq tex-command "/usr/texbin/luajitlatex -synctex=1")
                                        ;(setq tex-command "/usr/texbin/xelatex -synctex=1")
                                        ;(setq tex-command "/usr/texbin/latexmk")
                                        ;(setq tex-command "/usr/texbin/latexmk -e '$latex=q/platex %O -synctex=1 %S/' -e '$bibtex=q/pbibtex %O %B/' -e '$makeindex=q/mendex %O -o %D %S/' -e '$dvipdf=q/dvipdfmx %O -o %D %S/' -norc -gg -pdfdvi")
                                        ;(setq tex-command "/usr/texbin/latexmk -e '$latex=q/platex %O -synctex=1 %S/' -e '$bibtex=q/pbibtex %O %B/' -e '$makeindex=q/mendex %O -o %D %S/' -e '$dvips=q/dvips %O -z -f %S | convbkmk -g > %D/' -e '$ps2pdf=q/ps2pdf %O %S %D/' -norc -gg -pdfps")
                                        ;(setq tex-command "/usr/texbin/latexmk -e '$latex=q/uplatex %O -synctex=1 %S/' -e '$bibtex=q/upbibtex %O %B/' -e '$makeindex=q/mendex %O -o %D %S/' -e '$dvipdf=q/dvipdfmx %O -o %D %S/' -norc -gg -pdfdvi")
                                        ;(setq tex-command "/usr/texbin/latexmk -e '$latex=q/uplatex %O -synctex=1 %S/' -e '$bibtex=q/upbibtex %O %B/' -e '$makeindex=q/mendex %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")
                                        ;(setq tex-command "/usr/texbin/latexmk -e '$pdflatex=q/pdflatex %O -synctex=1 %S/' -e '$bibtex=q/bibtex %O %B/' -e '$makeindex=q/makeindex %O -o %D %S/' -norc -gg -pdf")
                                        ;(setq tex-command "/usr/texbin/latexmk -e '$pdflatex=q/lualatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$makeindex=q/texindy %O -o %D %S/' -norc -gg -lualatex")
                                        ;(setq tex-command "/usr/texbin/latexmk -e '$pdflatex=q/luajitlatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$makeindex=q/texindy %O -o %D %S/' -norc -gg -lualatex")
                                        ;(setq tex-command "/usr/texbin/latexmk -e '$pdflatex=q/xelatex %O -synctex=1 %S/' -e '$bibtex=q/bibtexu %O %B/' -e '$makeindex=q/texindy %O -o %D %S/' -norc -gg -xelatex")
          (setq bibtex-command (cond ((string-match "uplatex\\|-u" tex-command) "/usr/texbin/upbibtex")
                                     ((string-match "platex" tex-command) "/usr/texbin/pbibtex")
                                     ((string-match "lualatex\\|luajitlatex\\|xelatex" tex-command) "/usr/texbin/bibtexu")
                                     ((string-match "pdflatex\\|latex" tex-command) "/usr/texbin/bibtex")
                                     (t "/usr/texbin/pbibtex")))
          (setq makeindex-command (cond ((string-match "uplatex\\|-u" tex-command) "/usr/texbin/mendex")
                                        ((string-match "platex" tex-command) "/usr/texbin/mendex")
                                        ((string-match "lualatex\\|luajitlatex\\|xelatex" tex-command) "/usr/texbin/texindy")
                                        ((string-match "pdflatex\\|latex" tex-command) "/usr/texbin/makeindex")
                                        (t "/usr/texbin/mendex")))
          (setq dvi2-command "/usr/bin/open -a Preview")
                                        ;(setq dvi2-command "/usr/bin/open -a Skim")
                                        ;(setq dvi2-command "/usr/bin/open -a TeXShop")
                                        ;(setq dvi2-command "/usr/bin/open -a TeXworks")
                                        ;(setq dvi2-command "/usr/bin/open -a Firefox")
          (setq dviprint-command-format "/usr/bin/open -a \"Adobe Reader\" `echo %s | gsed -e \"s/\\.[^.]*$/\\.pdf/\"`")

          (defun skim-forward-search ()
            (interactive)
            (progn
              (process-kill-without-query
               (start-process
                "displayline"
                nil
                "/Applications/Skim.app/Contents/SharedSupport/displayline"
                (number-to-string (save-restriction
                                    (widen)
                                    (count-lines (point-min) (point))))
                (expand-file-name
                 (concat (file-name-sans-extension (or YaTeX-parent-file
                                                       (save-excursion
                                                         (YaTeX-visit-main t)
                                                         buffer-file-name)))
                         ".pdf"))
                buffer-file-name))))



          (auto-fill-mode -1)

          ;;
          ;; RefTeX with YaTeX
          ;;
          (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)


          )

© 2021, fruitymidnight.net