Visual Studio Code as Latex Editor on Ubuntu 16.04

2018-08-06

Inference

Prerequisites

texlive

sudo apt install texlive

Tutorial

  1. Download and install Visual Studio Code.
  2. Install extensions. ‘latex-workshop’ and ‘Code Spell Checker’
  3. Open the directory of your latex project in vscode. mkdir latex_project && code latex_project
  4. Create vscode tasks for building ‘.tex’ and ‘.bib’ documents.
    1. Make ‘.vscode’ directory in the root of your latex project.
    2. Create ‘task.json’ file inside the ‘.vscode’ directory with the following content.
       {
       "version": "2.0.0",
       "tasks": [
       {
           "label": "Run pdflatex",
           "type": "shell",
           "group": {
               "kind": "build",
               "isDefault": true
           },
           "command": "pdflatex",
           "args": [
               "-interaction=nonstopmode",
               "-file-line-error",
               "*.tex"
           ]
       },
       {
           "label": "Run bibtex",
           "type": "shell",
           "group": {
               "kind": "test",
               "isDefault": true
           },
           "command": "bibtex",
           "args": [
               "-terse",
               "*.aux"
           ]
       }      
       ]
       }
      
  5. Set up a spell checker.

    Create the cSpell.json file inside the ‘.vscode’ directory with the following content.

     {
     "version": "0.1",
     "language": "en",
     "dictionaryDefinitions": [
     { "name": "projectDictionary", "path": "./dictionary.txt"}
     ],
     "dictionaries": ["projectDictionary"],
     "languageSettings": [
     { "languageId": "*", "dictionaries": ["projectDictionary"] }
     ],
     "ignoreRegExpList": [
     "\\\\cite{[A-Za-z0-9, -]+}",
     "\\\\begin{\\w+}",
     "\\\\end{\\w+}",
     "\\\\usepackage{\\w+}",
     "\\\\bibliographystyle{\\w+}",
     "\\\\hyphenation{[A-Za-z0-9, -]+}",
     "\\w+{?"]
     }
    

    The configuration instructs the Code Spell Checker to use a default English extended by a custom list of words loaded from the ‘dictionary.txt’ file. Spelling errors will not be reported for latex commands and text in-between curly brackets of the shortlisted command.

    Create an empty ‘dictionary.txt’ file in the ‘.vscode’ directory. It should contain words that are not recognized by the spell checker. An example of the valid file format, a list of words separated by a newline character, is provided below.

     aforementioned
     combinatorial
     decremental
     forementioned
     polytope
     pseudocode
     scalability
     superset
     subproblem
    
  6. Alter editor settings for better work with text files.

    Create the ‘setting.json’ file in the ‘.vscode’ directory with the following content.

     {  
     "cSpell.enabled": true,
     "editor.cursorBlinking": "solid",
     "editor.wordWrap": "on",
     "editor.wordWrapColumn": 80,
     "editor.wrappingIndent": "same",
     "latex-workshop.debug.showUpdateMessage": false,
     "telemetry.enableCrashReporter": false,
     "telemetry.enableTelemetry": false
     }