4.1. Latex settings in VScode#

last update: Feb 07, 2024

4.1.1. Install TexLive on macOS#

Download install-tl-unx.tar.gz

$ curl -OL http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz

Open install-tl-unx.tar.gz

$ tar xvf install-tl-unx.tar.gz

Change directory to the installer:

$ cd install-tl-2*

Install TexLive

$ sudo ./install-tl -no-gui -repository http://mirror.ctan.org/systems/texlive/tlnet/

To start installation, type I and enter.

Actions:
 <I> start installation to hard disk
 <H> help
 <Q> quit
Enter command: I

Add a symbolic link to /usr/local/bin

$ sudo /usr/local/texlive/????/bin/*/tlmgr path add

4.1.2. Setting in VScode#

  1. Install LaTeX Workshop extension.

  2. Open settings.json in VScode. In macOS, you can open it by typing the following command in the terminal.

    code ~/Library/Application\ Support/Code/User/settings.json
    
  3. Add the following code to settings.json. You have two recipes, ptex2pdf*3 and ptex2pdf -> pbibtex -> ptex2pdf*2. The former is to compile .tex files without .bib, and the latter is for .tex files with .bib. Please refer to this page for more details.

    {
        // ...
        
        // latex
        "latex-workshop.latex.tools": [
            {
                "name":"ptex2pdf",
                "command": "ptex2pdf",
                "args": [
                    "-l",
                    "-ot",
                    "-interaction=nonstopmode",
                    "-kanji=utf8 -synctex=1", // for Japanese
                    "%DOC%"
                ]
            },
            {
                "name": "pbibtex",
                "command": "pbibtex",
                "args": [
                    "-kanji=utf8", // for Japanese
                    "%DOCFILE%"
                ]
            },
            {
                "name": "biber",
                "command": "biber",
                "args": [
                    "--bblencoding=utf8",
                    "-u",
                    "-U",
                    "--output_safechars",
                    "%DOCFILE%"
                ]
            },
        ],
        "latex-workshop.latex.recipes": [
            {
                "name": "ptex2pdf*3",
                "tools":[
                    "ptex2pdf",
                    "ptex2pdf",
                    "ptex2pdf",
                ]
            },
            {
                "name": "ptex2pdf -> pbibtex -> ptex2pdf*3",
                "tools":[
                    "ptex2pdf",
                    "pbibtex",
                    "ptex2pdf",
                    "ptex2pdf",
                ]
            },
            {
                "name": "ptex2pdf -> biber -> ptex2pdf * 2",
                "tools":[
                    "ptex2pdf",
                    "biber",
                    "ptex2pdf",
                    "ptex2pdf",
                ]
            },
        ],
        "latex-workshop.latex.clean.fileTypes":
        [
            "*.bbl", "*.blg", "*.idx", "*.ind", "*.lof", "*.lot", "*.out", "*.toc", "*.acn", "*.acr", "*.alg",
            "*.glg", "*.glo", "*.gls", "*.ist", "*.fls", "*.log", "*.fdb_latexmk", "*.synctex.gz",
            "_minted*", "*.nav", "*.snm", "*.vrb",
        ],
        "latex-workshop.latex.autoClean.run": "onBuilt",
        "latex-workshop.latex.autoBuild.run": "onFileChange",
        "latex-workshop.synctex.afterBuild.enabled": true,
        "latex-workshop.view.pdf.viewer": "tab",
    }
    

4.1.3. Let’s compile your \(\LaTeX\) file!#

Let’s make a test latex directory. Please download article-template from here. Then, open the directory in VScode. You can edit sections/intro.tex and compile it by cmd + S (Mac). Finally, you will get the modified main.pdf.

The directory structure is as follows:

article-template
|-- img/
|-- preamble.tex
|-- main.tex
|-- main.pdf
|-- ref.bib
`-- sections/
    |-- intro.tex
    |-- method.tex
    ...
    `-- appendix.tex

You can divide your main.tex into several files as above and include them in main.tex as follows:

\begin{document}
\maketitle
...

\input{sections/intro.tex}
\input{sections/method.tex}
...
\newpage
\bibliographystyle{abbrv}
\bibliography{ref}
\newpage
\input{sections/appendix.tex}

\end{document}