LoginSignup
124
96

More than 5 years have passed since last update.

Visual Studio CodeでTeXのコンパイルをできるようにする方法

Last updated at Posted at 2018-05-26

Visual Studio CodeでTeXのコンパイルをできるようにする方法についてまとめます。

前提

  • upLaTeXを使う場合とpLaTeXを使う場合がある
  • pBibTeXを使う場合と使わない場合がある

必要なソフトウェアのインストール

  1. TeX Live - TeX Wikiのインストールを参考に、TeX Liveをインストールします。
  2. Download Visual Studio Code - Mac, Linux, WindowsからVisual Studio Codeをダウンロード・インストールします。

拡張機能のインストール

  1. Visual Studio Codeを起動します。
  2. Ctrl + Shift + Xを押下します。
  3. 検索窓で『LaTeX Workshop』を検索します。
  4. LaTeX Workshopをインストールします。

コンパイル設定

  1. Ctrl + ,を押下します。
  2. 右側のユーザ設定の部分に以下のように記述します。

    settings.json
    {
        "latex-workshop.latex.tools": [
            {
                "name": "latexmk",
                "command": "latexmk",
                "args": [
                    "-synctex=1",
                    "-interaction=nonstopmode",
                    "-file-line-error",
                    "-pdf",
                    "%DOC%"
                ]
            },
            {
                "name": "pdflatex",
                "command": "pdflatex",
                "args": [
                    "-synctex=1",
                    "-interaction=nonstopmode",
                    "-file-line-error",
                    "%DOC%"
                ]
                },
            {
                "name": "bibtex",
                "command": "bibtex",
                "args": [
                    "%DOCFILE%"
                ]
            },
            {
                "name":"ptex2pdf",
                "command": "ptex2pdf",
                "args": [
                    "-l",
                    "-ot",
                    "-kanji=utf8 -synctex=1",
                    "%DOC%"
                ]
            },
            {
                "name":"ptex2pdf (uplatex)",
                "command": "ptex2pdf",
                "args": [
                    "-l",
                    "-u",
                    "-ot",
                    "-kanji=utf8 -synctex=1",
                    "%DOC%"
                ]
            },
            {
                "name": "pbibtex",
                "command": "pbibtex",
                "args": [
                    "-kanji=utf8",
                    "%DOCFILE%"
                ]
            }
        ],
        "latex-workshop.latex.recipes": [
            {
                "name": "latexmk",
                "tools": [
                    "latexmk"
                ]
            },
            {
                "name": "pdflatex*2",
                "tools": [
                    "pdflatex",
                    "pdflatex"
                ]
            },
            {
                "name": "pdflatex -> bibtex -> pdflatex*2",
                "tools": [
                    "pdflatex",
                    "bibtex",
                    "pdflatex",
                    "pdflatex"
                ]
            },
            {
                "name": "ptex2pdf*2",
                "tools": [
                    "ptex2pdf",
                    "ptex2pdf"
                ]
            },
            {
                "name": "ptex2pdf -> pbibtex -> ptex2pdf*2",
                "tools": [
                    "ptex2pdf",
                    "pbibtex",
                    "ptex2pdf",
                    "ptex2pdf"
                ]
            },
            {
                "name": "ptex2pdf (uplatex) *2",
                "tools": [
                    "ptex2pdf (uplatex)",
                    "ptex2pdf (uplatex)"
                ]
            },
            {
                "name": "ptex2pdf (uplatex) -> pbibtex -> ptex2pdf (uplatex) *2",
                "tools": [
                    "ptex2pdf (uplatex)",
                    "pbibtex",
                    "ptex2pdf (uplatex)",
                    "ptex2pdf (uplatex)"
                ]
            },
        ]
    }
    

コンパイル用のキーショートカット設定

  1. Ctrl+Shift+Pを押下し、『Build with recipe』を検索・選択します。
  2. 選択画面が出てきたら、操作をキャンセルします。
  3. Ctrl + Kを押下します。
  4. Ctrl + Sを押下します。
  5. 検索窓で『Build with recipe』を検索します。
  6. Build with recipeをダブルクリックします。
  7. キーショートカットを設定します。

コンパイル方法

  1. 設定したコンパイル用のキーショートカットを押下します。
  2. 以下の中から適切なレシピを選択します。
    ※コンパイルの進捗状況は左下に表示されます。

    レシピ 内容
    latexmk LaTeXmkを用いてコンパイル
    pdflatex*2 pdfLaTeXを用いてコンパイル
    pdflatex -> bibtex -> pdflatex*2 pdfLaTeXとBibTeXを用いてコンパイル
    ptex2pdf*2 pLaTeXを用いてコンパイル
    ptex2pdf -> pbibtex -> ptex2pdf*2 pLaTeXとpBibTeXを用いてコンパイル
    ptex2pdf (uplatex) *2 upLaTeXを用いてコンパイル
    ptex2pdf (uplatex) -> pbibtex -> ptex2pdf (uplatex) *2 upLaTeXとpBibTeXを用いてコンパイル
  3. コンパイルが終了したら、Ctrl + Alt + Vを押下し、コンパイルしたPDFを表示します。

参考文献

124
96
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
124
96