[Tex/LaTex] LaTeX on VS Code: pdf viewer does not update, and can only run one file in a folder

compilingmakeindex

I am trying to use VS Code on Windows 10 x64 with LaTeX Workshop 8.7.2 to compile documents in LaTeX.

I am facing three problems:

  1. The PDF viewer that is displayed in a tab in VS Code does not update anymore when I compile the document again after having opened the PDF viewer. Opening the PDF file with another program shows that it gets updated, so it is just the viewer in VS Code that does not update on compilation. I have to close the tab and open it again (LaTeX Workshop: View LaTeX PDF file in VSCode tab) to display the newest, i.e. current version of the PDF file.

  2. The file tasks.json that lies in the subfolder .vscode of the folder in which my myfilename.tex-file that I want to compile lies contains the line "myfilename.tex". I see in multiple places online (like the accepted answer here or here) that this should seemingly rather be %DOC%.tex or %DOC% (although in the first link, they are referring to the settings.json file, which looks as below for me, i.e. completely different. When I compile this with %DOC%.tex or just %DOC%, I get:

This is pdfTeX, Version 3.14159265-2.6-1.40.20 (MiKTeX 2.9.7250 64-bit)
entering extended mode
! Emergency stop.
<*> %DOC%

!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.
The terminal process terminated with exit code: 1

This problem means that if I want to compile two .tex-files in the same folder, I need to manually replace the filename in the tasks.json file each time. What I also tried, to no avail, is (following https://github.com/James-Yu/LaTeX-Workshop/issues/384) "%DOCFILE%.tex" and "%DOCFILE%").

  1. I want to also create an index within the PDF file. In TeXWorks, which I used before, I used MakeIndex like this:

enter image description here

or (preferably, combined with pdfLaTeX) like this

enter image description here

What would I have to do to run MakeIndex using VS Code?


Here are my files:
tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run pdflatex",
            "type": "shell",
            "group": {
                "kind": "build"
            },
            "command": "pdflatex",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "myfilename.tex"
            ]
        },
        {
            "label": "Run bibtex",
            "type": "shell",
            "group": {
                "kind": "test",
                "isDefault": true
            },
            "command": "bibtex",
            "args": [
                "-terse",
                "*.aux"
            ]
        },
        // {
        //     "label": "Run makeindex",
        //     "command": "makeindex",
        //     "args": [
        //           "myfilename.tex.nlo",
        //           "-s nomencl.ist",
        //           "-o myfilename.tex.nls%"
        //     ]
        // },
        {
            "label": "update pdf",
            "command": "${command:latex-workshop.refresh-viewer}",
            "problemMatcher": []
        },
        {
            "label": "Compile and update",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "dependsOrder": "sequence",
            "dependsOn": [
                // "Run makeindex",
                "Run pdflatex",
                "update pdf"
            ],
            "problemMatcher": []
        }
    ]
}

settings.json

{
    "latex-workshop.message.update.show": false,
    "latex-workshop.latex.autoClean.run": "onBuilt",
    "latex-workshop.latex.clean.fileTypes": [
        "*.aux",
        "*.toc",
        // "*.blg",
        // "*.lof",
        // "*.lot",
        // "*.out",
        // "*.acn",
        // "*.acr",
        // "*.alg",
        // "*.glg",
        // "*.glo",
        // "*.gls",
        // "*.fls",
        // "*.log",
        // "*.fdb_latexmk",
        // "*.snm",
        "*.synctex(busy)",
        "*.synctex.gz(busy)",
        "*.nav"
    ],
    "latex-workshop.view.pdf.ref.viewer": "tabOrBrowser",
    "latex-workshop.view.pdf.viewer": "tab",
    "latex-workshop.view.pdf.zoom": "page-fit",
    "window.zoomLevel": 1,
    "latex-workshop.latex.recipes": [
        {
          "name": "pdflatex ➞ bibtex ➞ pdflatex × 2",
          "tools": [
            "pdflatex",
            "bibtex",
            "pdflatex",
            "pdflatex"
          ]
        },
      ]
}

Best Answer

I finally created an issue on on the Github-page of LaTeX-Workshop.

You are not supposed to used tasks for compilation. I do not recall now where I picked that up, but it was not the good thing to do.

What now worked, on one computer, was to change the settings.json-file as follows:

{
    "cSpell.enabled": true,
    "editor.cursorBlinking": "solid",
    "editor.wordWrap": "on",
    "editor.wordWrapColumn": 80,
    "editor.wrappingIndent": "same",
    "latex-workshop.view.pdf.viewer": "tab",  
    "latex-workshop.view.pdf.zoom": "page-fit",
    "latex-workshop.latex.autoBuild.cleanAndRetry.enabled": true,
    "latex-workshop.latex.autoClean.run": "onFailed",
    "latex-workshop.latex.clean.subfolder.enabled": true,
    "latex-workshop.latex.clean.fileTypes": [ "*.aux"
        //, "*.toc", 
        // "*.ilg", 
        // "*.blg",
        // "*.lof",
        // "*.lot",
        // "*.out",
        // "*.acn",
        // "*.acr",
        // "*.alg",
        // "*.glg",
        // "*.glo",
        // "*.gls",
        // "*.fls",
        // "*.log",
        // "*.fdb_latexmk",
        // "*.snm"
    ],
    "latex-workshop.message.log.show": true,
    "latex-workshop.latex.recipes": [
        {
          "name": "latexmk",
          "tools": [
            "latexmk"
          ]
        },
        {
          "name": "pdflatex",
          "tools": [
            "pdflatex",
            // "bibtex",
            "makeindex",
            // "pdflatex",
            "pdflatex"
          ]
        }
      ],
    "latex-workshop.latex.tools":[
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-pdf",
                "-f",
                "-outdir=%OUTDIR%",
                "%DOC%"
            ],
            "env": {}
        },
        {
            "name": "lualatexmk",
            "command": "latexmk",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-lualatex",
                "-outdir=%OUTDIR%",
                "%DOC%"
            ],
            "env": {}
        },
        {
            "name": "latexmk_rconly",
            "command": "latexmk",
            "args": [
                "%DOC%"
            ],
            "env": {}
        },
        {
            "name": "pdflatex",
            "command": "pdflatex",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "%DOC%"
            ],
            "env": {}
        },
        {
            "name": "bibtex",
            "command": "bibtex",
            "args": [
                "%DOCFILE%"
            ],
            "env": {}
       },
       { 
            "name": "makeindex",
            "command": "makeindex",
            "args": [
                "%DOCFILE%.nlo",
                "-s",
                "nomencl.ist",
                "-o",
                "%DOCFILE%.nls"
            ],
           "env": {}
      },
      {
            "name": "rnw2pdf",
            "command": "Rscript",
            "args": [
                "-e",
                "knitr::knit2pdf('%DOCFILE%')"
            ],
            "env": {}
      }
    ],
    "latex-workshop.message.update.show": false
}

and executing with ctrl + alt + b.

In particular, this worked on a new PC (also with Windows 10, MikTeX, and TeXWorks installed from my previous usage), on which I simply downloaded and installed VS Code (1.44.0) and the LaTeX Workshop extension (8.8.0). I then adjusted the settings.json as above and all problems are solved (except that the PDF viewer does not update automatically upon compilation, at least not regularly; I'm still trying to identify the issue, but this is minor).

However, on another computer, I do not have perl installed, and using the above settings.json, I obtain the error:

latexmk: The script engine could not be found
latexmk: Data: scriptEngine="perl.exe", scriptName="latexmk"

when I uncomment the recipe latexmk in the settings file, this results in:

  • Document compiles without errors
  • PDF does not update in tab, icon needs to be clicked again to see changes
  • Table of contents stays empty after multiple compilations
  • Referenced labels of sections and their page numbers (ref, pageref) and are only question marks.