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? – KJO Nov 29 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 – KJO Nov 29 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 – KJO Nov 29 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/… – KJO Nov 29 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) – KJO Nov 29 at 16:59
up vote 1 down vote accepted

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
Password:
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
/Library/TeX/texbin/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.

New contributor
gsalgueiros is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 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 ? – KJO Dec 14 at 13:44

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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