Deployment of Latex IDE in macOS

Deployment of Latex IDE in macOS

IT, Others

LaTeX is a TEX-based typesetting system. many teachers ask students to write papers with Latex. The peoblem is, the TEX project just like a c program project, you can only get the output by compiling. It’s very cumbersome to print a bunch of command every time to get the output. Sometimes you even need to compile the project with different compilers a few times. So you’d better to have a IDE, there are lot of IDEs can be used: LyX, TeXworks, TexStudio, WinEdt, Emacs, Sublime Text, Atom, Visual Studio Code.
This article will show you how to configure Visual Studio Code as the Latex IDE in macOS.

Prepare packages:

MacTex Latex compilers and environment

Visual Studio Code IDE

Skim PDF reader

Install steps:

Install MacTex:

MacTex is a commonly used Latex compilation environment package on MacOS. Of course, texlive or MikTex can also be used in MacOS. The full installation files are large, you can also use the MacTex_Basic installation package, but you may find some problems like missing dependencies in compiling.

Install Visual Studio Code:

VSCode is a free editor developed by Microsoft. In the past two years, it has won the favor of many programmers with its excellent syntax highlighting, good running speed and powerful plug-in.

You should first download the installing package, you can easily finish the installing with guide.

After installing, you can install plugin for LaTeX. Click the Extensions bottom on the left, search LaTeX Workshop, choose Install, then it will be installed and enabled.

Configure the compilation mode and compilation chain:

VS Code have 3 default compiler: latexmk, pdflatex and bibtex. The default compiler compiled the project only once, and some special content can’t be compiled with them. So we need to add another compiler. e.g. xelatex. We need to modify the configuration of VS Code: click the setting icon on the bottom left corner of the windows and select configuration, then add the following things to json file in user-defined settings:


"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": "xelatex",
    "command": "xelatex",
    "args": [
      "-synctex=1",
      "-interaction=nonstopmode",
      "-file-line-error",
      "-pdf",
      "%DOC%"
    ]
  },
  {
    "name": "bibtex",
    "command": "bibtex",
    "args": [
      "%DOCFILE%"
    ]
  }
],

compilation-chain:

A very common compilation-chain is xelatex -> bibtex -> xelatex*2. so we continue to add the build-chain to the user-defined settings:


"latex-workshop.latex.recipes": [
  {
    "name": "xelatex -> bibtex -> xelatex*2",
    "tools": [
      "xelatex",
      "bibtex",
      "xelatex",
      "xelatex"
    ]
  },
  {
    "name": "latexmk",
    "tools": [
      "latexmk"
    ]
  },
  {
    "name": "pdflatex -> bibtex -> pdflatex*2",
    "tools": [
      "pdflatex",
      "bibtex",
      "pdflatex",
      "pdflatex"
    ]
  }
],

After adding the above content, it can be compiled normally. The first content will be used as the default value. You can press ctrl+alt+B to directly start compiling according to the default value.

Install Skim:

The install is not very hard, but you cannot use backward search at this moment.

Skim provided a simple script to get this feature:


/Applications/Skim.app/Contents/SharedSupport/displayline %line "%pdffile" "%texfile"

%line is the line number in .tex, %pdffile is the path of output PDF file, %texfile is the source file.

you should add this settings to user-defined settings:


"latex-workshop.view.pdf.external.synctex": {
    "command": "/Applications/Skim.app/Contents/SharedSupport/displayline",
    "args": [
        "-r",
        "%LINE%",
        "%PDF%",
        "%TEX%"
    ]
  },
}

Amefs, EFS, IT
Previous Post
Deployment in SYS ARM-2T
Next Post
Install Plex Media Server on Debian Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

keyboard_arrow_up