LaTeX 環境の構築(macOS) - BYOD PC のセッティング(5)

はじめに

電気電子工学コースでは、第三学年からレポートを電子提出する。コースとしては、LaTeX か Microsoft Word での執筆を推奨しており、それぞれのスタイルファイルを配布している。5年になって学会活動などをする場合には、LaTeX の方が便利なことが多い。そのため、情報処理IIの授業では LaTeX の学習を行う。ここでは、LaTeX のインストールおよび初期設定の方法を示す。なお、この設定では数GB単位のネットワークアクセスがあるので、データ量に制限がある携帯回線などでは実施しない方がよい。

  • インストール後のアップデートについて(4/21追記) この記事を書いた時には TeX Live が 2019 だったが、その後 TeX Live 2020 に上がっている。そのためメッセージが一部異なる場合があるが、基本的に流れは同じはずである。すでに 2019 を入れてしまった人用にパッケージアップデートの方法を執筆するのでしばらく待って欲しい。

MacTeX のインストール

macOS での LaTeX のリポジトリは TeX Live ベースの MacTeX が最も有名である。これは Homebrew でインストール可能である。ただし、フルパッケージをインストールしてしまうと、古い Ghostscript のバイナリもインストールされてしまう。そこで、GUI については Homebrew cask で別個にインストールすることにする。以下、手順を箇条書きで示す。

  • Homebrew cask で mactex-no-gui をインストールする。
% brew cask install mactex-no-gui
==> Downloading http://mirror.ctan.org/systems/mac/mactex/mactex-20190508.pkg
==> Downloading from http://ftp.yz.yamagata-u.ac.jp/pub/CTAN/systems/mac/mactex/
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'mactex-no-gui'.
==> Installing dependencies: jpeg, libtiff, ghostscript
==> Installing jpeg
==> Downloading https://homebrew.bintray.com/bottles/jpeg-9d.catalina.bottle.tar
==> Downloading from https://akamai.bintray.com/8f/8f7b82a952fb3937889c7f22da140
######################################################################## 100.0%
==> Pouring jpeg-9d.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/jpeg/9d: 21 files, 775.2KB
==> Installing libtiff
==> Downloading https://homebrew.bintray.com/bottles/libtiff-4.1.0.catalina.bott
==> Downloading from https://akamai.bintray.com/44/449bd9123e73e4c4eab85b77322d7
######################################################################## 100.0%
==> Pouring libtiff-4.1.0.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/libtiff/4.1.0: 247 files, 3.7MB
==> Installing ghostscript
==> Downloading https://homebrew.bintray.com/bottles/ghostscript-9.52.catalina.b
==> Downloading from https://akamai.bintray.com/8c/8cd0efa1e5525f849be3ee1e50e16
######################################################################## 100.0%
==> Pouring ghostscript-9.52.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/ghostscript/9.52: 671 files, 87.4MB
==> Installing Cask mactex-no-gui
==> Running installer for mactex-no-gui; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are i
Password:
installer: Package name is MacTeX-2019
installer: choices changes file '/var/folders/5v/x42rtwgx37x7pst50clmgqxh0000gp/T/choices20200404-8741-1peqvmk.xml' applied
installer: Installing at base path /
installer: The install was successful.
🍺  mactex-no-gui was successfully installed!
  • MacTeX のインストールでパスが設定されるので、ターミナルを閉じて新しく開きます。
  • 次に tlmgr で TeX Live のパッケージを最新にします。かなり時間がかかります(30分くらい)。
sudo tlmgr update --self --all
  • デフォルトの紙サイズを A4 にします。
sudo tlmgr paper a4

ヒラギノフォントの埋め込み

デフォルトでは IPA フォントが埋め込まれているようになっている。このままでもいいのだが、せっかく macOS にヒラギノフォントが入っているので、これを埋め込めるようにしたい。手順を箇条書きで示す。

  • tlcontrib のリポジトリを追加する。
% sudo tlmgr repository add http://contrib.texlive.info/current tlcontrib
Password:
tlmgr: added repository with tag tlcontrib: http://contrib.texlive.info/current
  • tlcontribを追加します。
% sudo tlmgr pinning add tlcontrib '*'
TeX Live 2019 is frozen forever and will no
longer be updated.  This happens in preparation for a new release.

If you're interested in helping to pretest the new release (when
pretests are available), please read https://tug.org/texlive/pretest.html.
Otherwise, just wait, and the new release will be ready in due time.
tlmgr: package repositories
  main = http://mirror.ctan.org/systems/texlive/tlnet (not verified: gpg unavailable)
  tlcontrib = http://contrib.texlive.info/current (not verified: gpg unavailable)
For more about verification, see https://texlive.info/verification.html.
tlmgr: new pinning data for tlcontrib: *
  • tlmgr でフォント関係のいくつかのパッケージをインストールする。
% sudo tlmgr install japanese-otf-nonfree japanese-otf-uptex-nonfree ptex-fontmaps-macos cjk-gs-integrate-macos
TeX Live 2019 is frozen forever and will no
longer be updated.  This happens in preparation for a new release.

If you're interested in helping to pretest the new release (when
pretests are available), please read https://tug.org/texlive/pretest.html.
Otherwise, just wait, and the new release will be ready in due time.
tlmgr: package repositories
  main = http://mirror.ctan.org/systems/texlive/tlnet (not verified: gpg unavailable)
  tlcontrib = http://contrib.texlive.info/current (not verified: gpg unavailable)
For more about verification, see https://texlive.info/verification.html.
[1/5, ??:??/??:??] install: cjk-gs-integrate-macos.x86_64-darwin @tlcontrib [1k]
[2/5, 00:03/11:45] install: cjk-gs-integrate-macos @tlcontrib [5k]
[3/5, 00:07/01:58] install: japanese-otf-nonfree @tlcontrib [29k]
[4/5, 00:12/00:29] install: japanese-otf-uptex-nonfree @tlcontrib [43k]
[5/5, 00:17/00:18] install: ptex-fontmaps-macos @tlcontrib [5k]
running mktexlsr ...
done running mktexlsr.
running mtxrun --generate ...
done running mtxrun --generate.
tlmgr: package log updated: /usr/local/texlive/2019/texmf-var/web2c/tlmgr.log
  • 新しいパッケージにパスを通す。
% sudo tlmgr path add
  • 以前の設定を一度削除する。
% sudo cjk-gs-integrate --link-texmf --cleanup
cjk-gs-integrate: reading font database ...
cjk-gs-integrate: searching for Ghostscript resource
cjk-gs-integrate: going to clean up /usr/local/share/ghostscript/9.52/Resource
cjk-gs-integrate: cleaning up all links, snippets and cidfmap.local ...
cjk-gs-integrate: removing cidfmap.local from cidfmap file ...
cjk-gs-integrate: removing snippets and cidfmap.aliases for font aliases ...
cjk-gs-integrate: removing cidfmap.aliases from cidfmap file ...
cjk-gs-integrate: running mktexlsr ...
mktexlsr: Updating /usr/local/texlive/2019/texmf-config/ls-R... 
mktexlsr: Updating /usr/local/texlive/2019/texmf-dist/ls-R... 
mktexlsr: Updating /usr/local/texlive/2019/texmf-var/ls-R... 
mktexlsr: Updating /usr/local/texlive/texmf-local/ls-R... 
mktexlsr: Done.
cjk-gs-integrate: finished
  • フォントの設定を行う。
% sudo cjk-gs-integrate-macos --link-texmf
cjk-gs-integrate: reading font database ...
cjk-gs-integrate: checking for files ...
cjk-gs-integrate: searching for Ghostscript resource
cjk-gs-integrate: output is going to /usr/local/share/ghostscript/9.52/Resource
cjk-gs-integrate: generating links and snippets for CID fonts ...
cjk-gs-integrate: generating links, snippets and cidfmap.local for non-CID fonts ...
cjk-gs-integrate: adding cidfmap.local to cidfmap file ...
cjk-gs-integrate: generating snippets and cidfmap.aliases for font aliases ...
cjk-gs-integrate: adding cidfmap.aliases to cidfmap file ...
cjk-gs-integrate: running mktexlsr ...
mktexlsr: Updating /usr/local/texlive/2019/texmf-config/ls-R... 
mktexlsr: Updating /usr/local/texlive/2019/texmf-dist/ls-R... 
mktexlsr: Updating /usr/local/texlive/2019/texmf-var/ls-R... 
mktexlsr: Updating /usr/local/texlive/texmf-local/ls-R... 
mktexlsr: Done.
cjk-gs-integrate: finished
  • 最後にヒラギノフォントを埋め込むように設定する。
 % sudo kanji-config-updmap-sys --jis2004 hiragino-highsierra-pron
Setting up ... hiragino-highsierra-pron for ja
updmap [WARNING]: resetting $HOME value (was /Users/hkob) to root's actual home (/var/root).
Creating new config file /usr/local/texlive/2019/texmf-config/web2c/updmap.cfg
updmap [WARNING]: resetting $HOME value (was /Users/hkob) to root's actual home (/var/root).
updmap [WARNING]: resetting $HOME value (was /Users/hkob) to root's actual home (/var/root).
updmap will read the following updmap.cfg files (in precedence order):
  /usr/local/texlive/2019/texmf-config/web2c/updmap.cfg
  /usr/local/texlive/2019/texmf-dist/web2c/updmap.cfg
updmap may write changes to the following updmap.cfg file:
  /usr/local/texlive/2019/texmf-config/web2c/updmap.cfg
dvips output dir: "/usr/local/texlive/2019/texmf-var/fonts/map/dvips/updmap"
pdftex output dir: "/usr/local/texlive/2019/texmf-var/fonts/map/pdftex/updmap"
dvipdfmx output dir: "/usr/local/texlive/2019/texmf-var/fonts/map/dvipdfmx/updmap"

updmap is creating new map files
using the following configuration:
  LW35 font names                  : URWkb (/usr/local/texlive/2019/texmf-dist/web2c/updmap.cfg)
  prefer outlines                  : true (/usr/local/texlive/2019/texmf-dist/web2c/updmap.cfg)
  texhash enabled                  : true
  download standard fonts (dvips)  : true (/usr/local/texlive/2019/texmf-dist/web2c/updmap.cfg)
  download standard fonts (pdftex) : true (/usr/local/texlive/2019/texmf-dist/web2c/updmap.cfg)
  jaEmbed replacement string       : hiragino-highsierra-pron (/usr/local/texlive/2019/texmf-config/web2c/updmap.cfg)
  jaVariant replacement string     : -04 (/usr/local/texlive/2019/texmf-config/web2c/updmap.cfg)
  scEmbed replacement string       : arphic (/usr/local/texlive/2019/texmf-dist/web2c/updmap.cfg)
  tcEmbed replacement string       : arphic (/usr/local/texlive/2019/texmf-dist/web2c/updmap.cfg)
  koEmbed replacement string       : baekmuk (/usr/local/texlive/2019/texmf-dist/web2c/updmap.cfg)
  create a mapfile for pxdvi       : false (default)

Scanning for LW35 support files  [  3 files]
Scanning for MixedMap entries    [ 45 files]
Scanning for KanjiMap entries    [ 11 files]
Scanning for Map entries         [297 files]

Generating output for dvipdfmx...
Generating output for ps2pk...
Generating output for dvips...
Generating output for pdftex...

Files generated:
  /usr/local/texlive/2019/texmf-var/fonts/map/dvips/updmap:
       15796 2020-04-04 20:57:41 builtin35.map
       21269 2020-04-04 20:57:41 download35.map
     4557117 2020-04-04 20:57:41 psfonts_pk.map
     4818087 2020-04-04 20:57:41 psfonts_t1.map
     4811441 2020-04-04 20:57:41 ps2pk.map
          14 2020-04-04 20:57:42 psfonts.map -> psfonts_t1.map
  /usr/local/texlive/2019/texmf-var/fonts/map/pdftex/updmap:
     4811448 2020-04-04 20:57:42 pdftex_dl14.map
     4809783 2020-04-04 20:57:42 pdftex_ndl14.map
          15 2020-04-04 20:57:42 pdftex.map -> pdftex_dl14.map
  /usr/local/texlive/2019/texmf-var/fonts/map/dvipdfmx/updmap:
       10964 2020-04-04 20:57:40 kanjix.map

Transcript written on "/usr/local/texlive/2019/texmf-var/web2c/updmap.log".
updmap: Updating ls-R files.

TeXShop のインストールと設定

  • no-gui で GUI をスキップしてしまったので、TeXShop を Homebrew-cask でインストールする。
brew cask install texshop
  • TeXShop を起動し、環境設定を開く。
    f:id:hkob:20200404211714p:plain
    TeXShop の環境設定
  • 設定プロファイルから「pTeX (ptex2pdf)」を選択する。
    f:id:hkob:20200404211936p:plain
    設定プロファイルを選択
  • 設定が終わったら、一度アプリを終了してから再起動する。

LaTeXiT のインストール

  • TeXShop 同様、LaTeXiT も Homebrew-cask でインストールする。
brew cask install latexit

これらアプリの使い方は別の機会に説明する。 以上。

hkob.hatenablog.com