LaTeX authoring environment with VSCode

Lifestyle
Author

Hirofumi Shiba

Published

12/22/2023

概要
A page collecting tips to author technical documents with VSCode. Also including a starting guide.

1 Starting Guide

1.1 Installation

Please consult the following links (Japanese):

1.2 latexmkrc

As for me (Mac mini, and MacBook Pro), I use the following .latexmkrc file to compile LaTeX documents, through VSCode’s LaTeX Workshop extension.

.latexmkrc
#!/usr/bin/env perl

$pdf_mode = 3;
$latex            = 'uplatex %O -kanji=utf8 -no-guess-input-enc -interaction=nonstopmode -file-line-error %S -synctex=1';
$bibtex           = 'upbibtex %O %B';
$dvipdf           = 'dvipdfmx %O -o %D %S';
$makeindex        = 'mendex %O -o %D %S';

$pvc_view_file_via_temporary = 0;
$pdf_previewer               = 'open -ga /Applications/Skim.app';

Place .latexmkrc in your home directory (~/.latexmkrc).

1.3 settings.json

In order to make a pdf file from a LaTeX file, you need to set the following in your settings.json file.

settings.json

{
    "latex-workshop.latex.recipes": [
        {
            "name": "upLaTeX",
            "tools": [
                "latexmk"
            ]
        },
    ],

    "latex-workshop.latex.tools": [
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [
                "-silent",
                "-outdir=%OUTDIR%",
                "%DOC%"
            ],
        },
    ],
}

2 Tips

2.1 Intellisense

When editing *.bib files, typing @ triggers intellisense to suggest snippets.

These snippet suggestions are controlled by the file bibtex-entries.json, and three variables concerning formatting:

You can customize the variable latex-workshop.intellisense.bibtexJSON.replace to modify the default fields included in the snippet auto-completion.

settings.json
{
    "latex-workshop.intellisense.bibtexJSON.replace": {
        "article" : ["author", "year", "title", "journal", "volume", "number", "pages", "url"]
    },
    "latex-workshop.bibtex-format.tab": "4 spaces",
}