制御とコンピューターサイエンスの間

This is a blog to share codes and ideas for building robots/aeronautical systems

vs code で latex

この記事は自分へのメモ

参考にしたサイト

前提

  • TexLiveをインストール(latexの諸々のcompiler?が入る)
  • vs codeLatex Workshopをインストール

コンパイル設定

あとは,vs code内でtexliveでインストールしたcompilerたちを使ってどう文書を作成するかの設定.
躓いたのが日本語のlatex
いつもノリでlatexをやっていたので,ptex2pdfやpbibtexで-kanji=utf8オプションを加えると日本語コンパイル出来るの知らなかった.

そこで,英語・日本語の文書のコンパイルが選べるように,
Latex Workshop内でそれぞれのコンパイラを組み合わせてrecipeを作っておきます.
作り終わったら,あとはそのrecipeをvs code内で走らせるだけ.

cmd+,で設定を開き,settings.jsonに以下を記述

 {
    "window.zoomLevel": 2,
    "latex-workshop.view.pdf.viewer": "tab",
    "latex-workshop.latex.autoBuild.run": "never",
    "latex-workshop.latex.clean.fileTypes": [
        "*.aux", "*.bbl", "*.blg", "*.idx", "*.ind", "*.lof", "*.lot", "*.out", "*.toc", "*.acn", "*.acr", "*.alg", "*.glg", "*.glo", "*.gls", "*.ist", "*.fls", "*.log", "*.fdb_latexmk", "*.synctex.gz",
        // for Beamer files
        "_minted*", "*.nav", "*.snm", "*.vrb",
    ],
    "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": "ptex2pdf -> pbibtex -> ptex2pdf*2",
            "tools": [
                "ptex2pdf",
                "pbibtex",
                "ptex2pdf",
                "ptex2pdf"
            ]
        },
        {
            "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 (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. キーショートカットを設定

latex workshopそのほかの設定

latex workshopの公式ページに諸設定の説明が書いてあります.
今僕が設定したのは,以下の通り.
pdfをvs code内の「タブ」で見たいときは"tab", そのほかに"none" | "browser" | "external"があります. こんな感じで,勝手にビルドしてしまう設定もオフにします. autoBuild.run: "never" また,いらない途中生成ファイルをビルド後に削除も設定.

    "window.zoomLevel": 2,
    "latex-workshop.view.pdf.viewer": "tab",
    "latex-workshop.latex.autoBuild.run": "never",
    "latex-workshop.latex.clean.fileTypes": [
        "*.aux", "*.bbl", "*.blg", "*.idx", "*.ind", "*.lof", "*.lot", "*.out", "*.toc", "*.acn", "*.acr", "*.alg", "*.glg", "*.glo", "*.gls", "*.ist", "*.fls", "*.log", "*.fdb_latexmk", "*.synctex.gz",
        // for Beamer files
        "_minted*", "*.nav", "*.snm", "*.vrb",
    ],