Skip to content

Instantly share code, notes, and snippets.

@Ikuyadeu
Last active March 6, 2024 02:16
Show Gist options
  • Star 37 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save Ikuyadeu/204d06fffd912f441b383eb02463e29b to your computer and use it in GitHub Desktop.
Save Ikuyadeu/204d06fffd912f441b383eb02463e29b to your computer and use it in GitHub Desktop.
VSCode でLatexの日本語環境を作る

https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile に書いてあったbibのコンパイルを日本語に対応.

  1. VSCodeやLatexをインストールしてなければインストール(https://code.visualstudio.com/
  2. Latex-Workshopをインストール(https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop)
  3. settings.json(Windows: ファイル > 基本設定 > 設定 or Ctrl + ,, Mac: Code > 基本設定 > 設定 or + ,)の{ }内に以下を追加(設定ファイルの変更方法: https://qiita.com/y-w/items/614843b259c04bb91495)
    "latex-workshop.latex.tools": [
        {
            "command": "ptex2pdf",
            "args": [
                "-l",
                "-ot",
                "-kanji=utf8 -synctex=1",
                "%DOCFILE%.tex"
            ],
            "name": "Step 1: ptex2pdf"
        },
        {
            "command": "pbibtex",
            "args": [
                "%DOCFILE%",
                "-kanji=utf8"
            ],
            "name": "Step 2: pbibtex"
        },
        {
            "command": "ptex2pdf",
            "args": [
                "-l",
                "-ot",
                "-kanji=utf8 -synctex=1",
                "%DOCFILE%.tex"
            ],
            "name": "Step 3: ptex2pdf"
        },
        {
            "command": "ptex2pdf",
            "args": [
                "-l",
                "-ot",
                "-kanji=utf8 -synctex=1",
                "%DOCFILE%.tex"
            ],
            "name": "Step 4: ptex2pdf"
        }
    ],
    "latex-workshop.latex.recipes": [
        {
            "name": "toolchain",
            "tools": [
                "Step 1: ptex2pdf",
                "Step 2: pbibtex",
                "Step 3: ptex2pdf",
                "Step 4: ptex2pdf"
            ]
        }
    ],
    "latex-workshop.view.pdf.viewer": "tab",
    "editor.renderControlCharacters": true
  • "editor.renderControlCharacters": trueはMacのSierraを利用している場合に見えない記号を表示するために必要, そうでなければ消しても大丈夫
  • もしbibファイルがないなら
"latex-workshop.latex.tools": [
        {
            "command": "ptex2pdf",
            "args": [
                "-l",
                "-ot",
                "-kanji=utf8 -synctex=1",
                "%DOCFILE%.tex"
            ]
        }
],
"latex-workshop.latex.recipes": [
{
    "name": "toolchain",
    "tools": [
        "Step 1: ptex2pdf"
    ]
}],
"latex-workshop.view.pdf.viewer": "tab",
"editor.renderControlCharacters": true

だけで十分

  1. ファイルを保存またはF1キーを押してBuild Latex Projectを入力,実行するとコンパイルされる.
  2. F1キーの後, View PDF File in new tabでPDFを見れる.
  3. エラーが出た場合は 表示-> 統合ターミナルで下に端末が出るのでその中の出力を確認
@Ikuyadeu
Copy link
Author

@Yukishita26 ありがとうございます.修正を行いました.

@qqpann
Copy link

qqpann commented Apr 23, 2019

「もしbibファイルがないなら」でlatex-workshop.latex.recipesが2度出てきますが意図的ですか?

@pluswisteria
Copy link

"もしbibファイルがないなら"の方ですが,以下のコードでうまくいきました.(mac)
よくわかりませんがとりあえず動くので参考までに.

"latex-workshop.latex.tools": [ { "command": "ptex2pdf", "args": [ "-l", "-ot", "-kanji=utf8 -synctex=1", "%DOC%" ], "name": "Step 1: ptex2pdf" } ], "latex-workshop.latex.recipes": [ { "name": "toolchain", "tools": [ "Step 1: ptex2pdf" ], } ], "latex-workshop.view.pdf.viewer": "tab", "editor.renderControlCharacters": true

@Ikuyadeu
Copy link
Author

@qqhann, @pluswisteria ありがとうございます.重複している部分を削除いたしました.

@pluswisteria
Copy link

pluswisteria commented Sep 17, 2019

@Ikuyadeu
先ほどの場所ですが,~recipesの方に"name"タグが2つあり怒られてしまいます.
これを~toolsの方に移すとなぜか機嫌をなおしてくれました.
加えて,Mojave環境ですと,~tools": ~"args":"%DOC%""%DOCFILE%.tex"とすると正常に動きました.

@Ikuyadeu
Copy link
Author

@pluswisteria ありがとうございます.修正いたしました.
http://haruka0000.hatenablog.com/entry/2018/07/20/190853
%DOCFILE%.texのほうが最新環境では正しいみたいですね.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment