2
1

More than 3 years have passed since last update.

Windows版VisualStudioCodeでTeX

Last updated at Posted at 2021-06-15

はじめに

Markdownでドキュメントを書いていると目次や付録などをこだわりたくなってきたのでTeX環境を整えます。

環境

Windows 10 (21H1)
Visual Studio Code (1.57.0)
Tex Live 2021

手順

細かい設定は行わずデフォルト設定でPDF作成まで走ります。

Visual Studio Codeのインストール

Tex Live 2021のインストール

Installing TeX Live over the Internetからinstall-tl-windows.exeを使用します。

ネットワークからダウンロードするので完了するまで2時間弱かかりました。
インストール先は、C:\texlive\2021です。

PDFの作成

ここでは試しとして、作業フォルダC:\docs\hellotexを作り、VSCodeで開きます。

Visual Studio Codeの設定

ファイル→ユーザー設定→拡張設定またはCtrl + Shift + Xで拡張設定を開きます。
latexを検索して、LaTeX Workshopをインストールします。

vscode_extension_latexworkshop_1.png

インストール後、拡張機能の設定を選択します。

vscode_extension_latexworkshop_2.png

Latex-workshop > Latex:Toolsを探し、settings.jsonで編集を選択します。

vscode_extension_latexworkshop_3.png

settings.jsonにデフォルト設定がコピーされるので、"name": "latexmk"となっている"args"配列の"-pdf"を"-pdfdvi"に修正します。

修正後のsettings.json
    "latex-workshop.latex.tools": [

        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-pdfdvi",
                "-outdir=%OUTDIR%",
                "%DOC%"
            ],
            "env": {}
        },
       (略)

texファイルとlatexmk環境設定の作成

hello.texを作成します。

hello.tex
\documentclass[a4paper,10pt]{jsarticle}
\begin{document}
こんにちは、\TeX
\end{document}

latexmk環境設定用のファイル.latexmkrcを作成します。

.latexmkrc
$latex = 'platex %O %S';
$dvipdf = 'dvipdfmx %O -o %D %S';

ビルド

右上の▷ボタンまたはCtrl + Alt + Bでビルドします。
hello.pdfが生成されたことを確認して、同右上のプレビューボタンまたはCtrl + Alt + VでPDFを確認できます。

vscode_pdf_preview.png

編集するとビルドされるのでプレビューも更新されます。

vscode_pdf_preview2.png

2
1
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
2
1