LoginSignup
8
5

More than 3 years have passed since last update.

[Mac] HomebrewとVSCodeで快適LaTeX環境構築 (2019)

Last updated at Posted at 2019-05-24

はじめに

この記事では,HomebrewとVSCodeでLaTeXの環境構築を行います.
この手順を踏むことによって,最終的にVSCodeを使ってLaTeXファイルを自動コンパイルすることができます.
この環境が一番快適かつシンプルで、構築も楽だと思っています.

Mac向けのLaTeXディストリビューションはMacTeXが有名ですが,GUIアプリ(恐らく使わない)などが入っているため容量が3.9GB程度と,かなり大きいです.
そのため,ここでは最小構成であるBasicTeXを使います.これなら容量が100MB程度と,かなりコンパクトです:thumbsup:

Install

HomebrewでBasicTeXとGhostscriptをインストールします.

brew cask install basictex
brew install ghostscript

Setup

1. BasicTeXの設定

sudo tlmgr update --self --all
sudo tlmgr paper a4
sudo tlmgr install collection-langjapanese

2. ヒラギノフォント適用

ヒラギノフォントにしたい方はどうぞ.

sudo tlmgr repository add http://contrib.texlive.info/current tlcontrib
sudo tlmgr pinning add tlcontrib '*'
sudo tlmgr install japanese-otf-nonfree japanese-otf-uptex-nonfree ptex-fontmaps-macos cjk-gs-integrate-macos
sudo cjk-gs-integrate --link-texmf --cleanup
sudo cjk-gs-integrate-macos --link-texmf
sudo mktexlsr
sudo kanji-config-updmap-sys --jis2004 hiragino-highsierra-pron

3. Latexmkのインストール

自動コンパイルしてくれるやつです.

sudo tlmgr install latexmk

VSCode

1. LaTeX Workshopをインストール

2. VSCodeのsettings.jsonに以下を追記

settings.json
{
    "latex-workshop.latex.tools": [
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [
                "-e",
                "$latex=q/uplatex %O -synctex=1 -interaction=nonstopmode -file-line-error %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",
                "-pdfdvi",
                "%DOC%"
            ]
        }
    ]
}

LaTeXのテスト

1. LaTeXが使えることを確かめるために,以下のファイルを作成してください.

test.tex
\documentclass[a4j,11pt,uplatex]{jsarticle}
\begin{document}

吾輩は猫である。名前はまだ無い。

どこで生れたかとんと見当がつかぬ。
何でも薄暗いじめじめした所で
ニャーニャー泣いていた事だけは記憶している。
吾輩はここで始めて人間というものを見た。

\end{document}

2. このファイルを保存すると自動コンパイルされ,同ディレクトリにPDFファイルが生成されているはずです.

3. 良きTeXライフを:thumbsup:

参考リンク

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5