I am very new to using VS Code and am very lost in it. I would like to edit and preview tex documents in VSC like I can on overleaf. I Installed LaTeX Workshop through VSC, but I can't see any preview.

For my LaTeX Compiler output, I get

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

I also get

No PDF viewer connected

in the LaTeX Workshop output.

I'm totally lost when it comes to installing packages and having all my paths in order and everything like that, and none of the setup guides for LaTeX Workshop are very helpful for me. I've used TeX in Overleaf and I think I have MikTeX which I used for graphics in python.

I would really appreciate any help in getting me on my way in this. Let me know what I should try, what information you need.

  • 1
    Start slowly, you seem to be jumping about too much, 1) you need a stable tex engine, you think you have MiKTeX. so you need to check that is not old and is working. What OS are you using ? can you check version of MiKTeX from its help about screen? MiKTeX may have a PDF viewer for TeXworks but what choice of PDF viewers do you have on the system? – user170109 Nov 29 '18 at 12:36
  • 1
    what happens if on a command line you type and enter> MiKTeX-console (that is with a hyphen) does it bring up MiKTeX or add a tray icon, note there may be a slight delay – user170109 Nov 29 '18 at 12:50
  • 1
    Ok you seem to have the basics, so we dont spend all day line by line, I suggest look at recent threads about updating MiKTeX if you have problems ensuring all packages are up to date (use the tasks drop down to synchronise filenames etc.) Unfortunately I don't use VScode but I can possibly help with the pdf part, However I suggest in MiKTeX console you have a TeXworks editor with pdf viewer so see how that may help you test some basic latex code. Add any info on PDF viewers to your main question – user170109 Nov 29 '18 at 13:04
  • 1
    Spuds hopefully by now with an updated MiKTeX you have been able to run some latexmk code without error. You did not say if you had a single or dual install but if simply starting MiKTeX-console tells you to switch to admin then you need to update both levels and run tasks at both levels. Did you find TeXworks any use ? you can write files in vscode and compile in TeXworks. If you are sticking with vscode for compiling you may need add synctex to the MiKTeX folder is fairly simple as described on web site github.com/James-Yu/LaTeX-Workshop/… – user170109 Nov 29 '18 at 15:25
  • 1
    Spuds just noticed we need to check how many perls are on path so at prompt need to enter> where /r c:\ perl.exe (there should be only one line of response) and a common problem is if that is exactly correct in path without a ; at end of whole path so need you to show response to > Path (in original question) – user170109 Nov 29 '18 at 16:59

I faced some difficulties in configuring and I decided to do this tutorial. In fact, it would be easier to download MacTex, which is the full version; however, I was not in the mood to occupy 4GB of my SSD with this.

The tutorial is pretty basic anyway, so have patience.

Important: I assume that: (1) BasicTex is already installed on your Mac and LaTex Workshop is installed in the VS Code, and (2) there are not any of the required packages.

Download Packages

Configuring TeX Live Manager

We will use TeX Live Manager to install the packages. It is accessible via tlmgr command

1) Open Terminal on your Mac

2) Type sudo tlmgr update --self to update the TeX Live Manager itself

3) Once the process is complete, we will update all packages already installed by BasicTex. To do so, type sudo tlmgr update --all

Installing Packages

Now we will install the necessary packages. They are: latexmk, latexindent, synctext, chktex and texcount. I will not show the installation of all the packages because the process is exactly identical, having only to substitute the name of what I am going to use of example (the chktex) by the others.

1) At the Terminal, type sudo tlmgr install chktex. Wait for the installation to be completed. Usually the dynamic is as follows:

MacBook-Pro: ~ gabriel $ sudo tlmgr install chktex
tlmgr: package repository http://ctan.dcc.uchile.cl/systems/texlive/tlnet (not verified: gpg unavailable)
[1/2, ??: ?? / ??: ??] install: chktex.x86_64-darwin [54k]
[2/2, 00: 01/00: 01] install: chktex [10k]
running mktexlsr ...
done running mktexlsr.
tlmgr: package log updated: /usr/local/texlive/2018basic/texmf-var/web2c/tlmgr.log

2) Repeat this for all packages

3) To check where each package is installed, use the which [package_name] command, for example which chktex. In my case, the answer comes:

MacBook-Pro-of-Gabriel: ~ gabrielsalgueiro $ which chktex

Configuring in VS Code

Configuring the paths

1) Open your VS Code and go to the Commands tab (Cmd + Shift + P generally), and open the settings by typing Preference: Open Settings

2) In the window that appears, locate the Extensions tab. Click and find LaTex

3) Fill in the required fields with the paths discovered in the previous step. Just go down the page you will see where it should fill with the paths. The default is [Package_name]: Path

Generating Files

1) Configured all, go test. Open the .tex file.

2) Build (Cmd + Option + B, by default).

3) View the result (Cmd + Option + V, by default)

3.1) If all goes well, it will ask where you want to view the PDF (browser, in a new tab, or even in an external viewer). Select your option and be happy.

Q. Remember to use a folder that does not have restricted characters. Defining the workspace inside the "Documents" folder solves this problem, for example.

  • Since this thread was issues with windows your answer may best be a simple link here for mac users to say your fuller answer on a mac related thread such as tex.stackexchange.com/questions/455648/… however others may disagree ? – user170109 Dec 14 '18 at 13:44
  • when trying to open the pdf preview in VS code, I obtain the error command 'vscode.previewHtml' not found. I read online that this could be due to an update in VS code. I am using the Extensions: LaTeX Workshop 8.7.1, LaTeX Preview 0.5.1, and LaTeX language support 3.1.0. – Marie. P. Feb 4 '20 at 9:45
  • [Useful link] Here is a demo video on making Beamer presentation in VScode. youtube.com/watch?v=3AJru09eg8c – vineeshvs May 23 '20 at 13:30

When MiKTeX is running and LaTeX-Workshop installed, you do not need perl or latexmk.

Building Just open the command palette in VS Code (Menu: View > Command Palette ...) and type: Latex workshop: build with recipe, click on it and choose pdflatex->bibtex->pdflatex2 instead of latexmk.

If you want to build directly via command Ctrl + Alt + B, edit your user settings: Go to Menu in VS Code: File > Preferences > Settings, expand entry Extensions and choose LaTeX. Scroll down to Latex: Recipes and click Edit in settings.json. Click on the pencil next to "latex-workshop.latex.recipes" in order to copy this entry from DEFAULT USER SETTINGS to USER SETTINGS. In the USER SETTINGS delete the whole entry

  "name": "latexmk",  
  "tools": [  

Save the file USER SETTINGS and afterwards you can build your latex-project via Ctrl + Alt + B.

Pdf-Viewer In order to start PDF viewer you can also open command palette again and type: Latex workshop: view latex pdf file in vscode tab.

Setup Synctex Download https://ctan.org/tex-archive/systems/win32/w32tex/win64/pdftex-w64.tar.xz, unzip it twice (with 7-zip for example) to my\Favourite\location\path. Open again Settings/LateX (s.o.) scroll to Synctex: Path and fill in my\Favourite\location\path\synctex.exe.

Now Synctex is available from source to PDF via Ctrl + Alt + J or vice versa from PDF to source via Ctrl + left clicking.

  • 3
    Why this answer isn't the top answer? – Pedro Simões Apr 10 '19 at 15:26
  • when viewing the pdf-file, I am not able to right-click in the PDF file and choose "go to code" in order to see the code that is responsible for that part of the document (table, paragraph, or similar). Can this feature be added? It works in TeXWorks. – Marie. P. Jan 11 '20 at 11:18
  • 1
    @Marie.P. this works via ctrl+left click instead. See my post regarding Synctex. – heini Jan 21 '20 at 12:11

You'll need the latexmk package from the MikTeX Console and the Perl language interpreter. Since Perl is easier to set up, let's do that first. Simply go to The Perl Programming Language site and download the latest version of Perl. I'd recommend ActiveState Perl (it's easier to set up, I hear).

Next, you need the latexmk package. This is also easy to get. Go to your MikTeX Console, and since you'll be getting a package, run in Admin mode. Once there, go to the Packages tab on the left-hand side of the console window, and in the Search box, type latexmk. You'll see the package in the results menu - it's recognizable by MikTeX, but isn't installed yet. Install the package, and restart your VS Code application.

As for the PDF viewer problem, once a .tex file is saved, said file is automatically compiled, and the PDF is ready to be viewed in the VS Code application. Click the leftmost button in the upper right side of the application, just below the Windows minimize icon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.