Latex Visual Studio Code



Visual Studio Code 编辑 LaTex 入门 (一) 刚装了电脑,这几天一直在整理资料还有倒腾软件。今天打开Word突然觉得它很难用,因为它经常出现格式混乱的情况。这时候脑海里浮出Latex,于是上知乎搜索了一下,发现了VS Code这个软件,第一眼就被软件的高颜值吸引了. Viewing output within Visual Studio Code (Images, Html, Graphs, LaTeX, SVG, and more) Getting Started. Before using Jupyter (IPython), you will need to ensure the prerequisites are installed and setup. Once you have the necessary prerequisites installed and setup, you are ready to evaluate code in a Jupyter kernel from within Visual Studio Code. One quite useful option is the Snippet Panel, which when clicked will open a tab on the right with symbols, which when selected will add in the relevant LaTeX code at your cursor in the document. It’s mostly maths symbols, but also Greek letters and some latin symbols. Click on the symbol you want and the code.

LaTeX is a powerful typesetting language that has been used for decades by people looking to create documents without needing to worry about the look of it. I have been using it for the last few years for important documents, and I wanted to integrate it with my favourite editor prior to undertaking a large project using it. It works very well with Visual Studio Code to create a very effective LaTeX editor that also integrates well with revision control plugins.

Visual-studio-code latex tex xelatex. Improve this question. Follow edited Jul 31 '19 at 14:16. Asked May 13 '19 at 9:11. A.Ametov A.Ametov. 1,015 1 1 gold badge 9 9 silver badges 18 18 bronze badges. Add a comment 2 Answers Active Oldest Votes.

I have written a follow-up post about using Visual Studio Code with LaTeX, mostly about the extensions that I also use with it as well as with additional configuration items.

Introduction

I try my best to make an effort to update my resume at least 2 or 3 times a year. Not necessarily because I am looking for a new job, but because I don’t want to forget about certain accomplishments. 2019 was a very busy year for me and for the first time in almost 10 years I didn’t update it once. The last time I updated it was in mid-2018, and at that time I had converted my resume from Word to LaTeX.

At the time I didn’t really have a good reason to use LaTeX for my resume, I just wanted to get a bit of experience using it. The biggest benefit to using LaTeX for my resume is the ability to use version control with Git. Office 365 has supported version control for a while now, but I have never been a big fan of it since I find it can create far too many snapshots and it is not always easy to search through everything.

In the past I have just used LaTeX on Windows 10 with the MiKTeX package, using the included TeXworks editor. TeXworks is a very basic and lightweight LaTeX editor in nature that is fast and easy to use. I am working on a new project this year that I want to use LaTeX for, but it is going to be a lot more complex than a multi-page resume so I want to use something that is a bit more robust.

I have been using Visual Studio Code (VS Code) for the last few years and it is an amazing code editor and best of all it is free. For my usage, I have decided to use the LaTeX Workshop plugin, which also uses the LaTeX Utilities plugin. Since I am already familiar with MiKTeX, I decided to just stick with it over other LaTeX packages such at TeX Live. There is also a requirement to have Perl installed in order for it to work with the LaTeX Workshop plugin, and the quickest way to do that is to use a pre-built environment such as Strawberry Perl.

For this guide I am using Windows 10 Pro 1909 64-bit on my Workstation, and here are the versions of the other software as of the time of this writing:

  • Visual Studio Code 64-bit v1.41 (System Installer)
  • MiKTeX 64-bit v2.9.7269
  • Strawberry Perl 64-bit v5.30.1.1
  • LaTeX Workshop v8.6.0
  • LaTeX Utilities v0.3.4

Installing Visual Studio Code

I won’t go into the installation of VS Code since it is fairly straightforward, and accepting all of the default options should be fine. When you download it there are three options for installing it, User Installer, System Installer and Zip. It is your preference, and no matter how you install it there should be no issues using the LaTeX plugins with it.

Installing MiKTeX

Like the installation of VS Code, I also won’t go into the details on how to install it since it is very straightforward to do. Just accept all of the default options and everything should work. There are two post-installation tasks to do, and one thing to confirm after installation.

Immediately after installation the MiKTeX Console should appear prompting you to update packages. Click on the “Update now” button and let the packages update. It should prompt you to restart the console when it completes.

When the MiKTeX Console reopens, you should be prompted to select a mode of operation. This is your choice, but if your workstation has multiple users you should select the option “Stay in user mode”.

You should also take a moment to confirm that the MiKTeX executables have been added to the System PATH.

If everything looks good then proceed with installing Strawberry Perl.

Installing Strawberry Perl

For the installation of Strawberry Perl, accept all of the default options. When the installation has completed, the Strawberry Perl executables should also have been automatically added to the System PATH.

If the System PATH looks okay, then you can install the LaTeX plugins in VS Code.

It is probably a good idea at this point to logout and log back in to ensure that the PATH has been picked up correctly by your user account.

Installing LaTeX Workshop and LaTeX Utilities

The two plugins can be easily installed directly through VS Code by going to the Extensions Marketplace window.

Search for “Latex” and it should bring up both extensions in the list. You can refine the search by searching just for “Latex Workshop” or “Latex Utilities”.

Click on “LaTeX Workshop” and then click the “Install” button to install the extension.

After the first extension is installed, click on “LaTeX Utilities” and then click the “Install” button to install the extension.

That is all there is to it to install both extensions.

Create a Basic LaTeX Document

To quickly test if the LaTeX plugins are working, create a new folder that will contain the test LaTeX document and create a new file called hello.tex in it. Here is a basic document that you can use to test LaTeX:

You can generate the PDF of the document by either using CTRL+ALT+B or by using CTRL+S. You should be prompted the first time on where you want the PDF to be displayed, the options being in VSCode tab, web browser and external viewer. If you choose to use the VSCode option, you should see the PDF in a split view.

MiKTeX is a great tool since it will automatically prompt you to install any missing plugins if you reference them in your LaTeX document.

I won’t go into the details on how to do more advanced configuration with the LaTeX Workshop plugin. The plugin is very well documented in the LaTeX Workshop Wiki.

Links

  • LaTeX Project: https://www.latex-project.org
  • MiKTeX: https://miktex.org
  • Strawberry Perl: http://strawberryperl.com
  • Visual Studio Code: https://code.visualstudio.com
  • LaTeX Workshop: https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop
  • LaTeX Workshop Wiki: https://github.com/James-Yu/LaTeX-Workshop/wiki
  • LaTeX Utilities: https://marketplace.visualstudio.com/items?itemName=tecosaur.latex-utilities
  • Visual Studio Code with LaTeX: https://mjcb.io/blog/2020/07/20/visual-studio-code-with-latex-follow-up/

LaTeX is one of those things you are sort of forced to learn when preparing technical documents, especially for academia. It is an old (but highly effective) typesetting system, and it is, at its core, complex as hell to use.

Latex Visual Studio Code Crack

Latex Visual Studio Code

In my day to day I jump between plaforms and operating systems so I always dreamed with a LaTeX editor that rule them all, sadly I had not found such thing (yet) but the closest has been, so far, Visual Studio Code so I took some time to prepare an environment and ensure I can work in the same document in the same way in any platform and, well, document the experience.

First we need to install the fantastic LaTeX Workshop, a Visual Studio Code extension designed to make your life with LaTeX easier (of course you need to have VS Code installed first). Now there is the big question, what about LaTeX? well, we have plenty of options, yes, you need to decide what LaTeX distribution to install and run in each of your operating systems and platforms, this is where I have most of my problems in the past, mostly because I got into a point where my installation was corrupted in macOS and I cannot compile Tex documents. Another problem I would like to avoid is to have global applications in my operating system; for example, I use minted a lot and this requires Pygments to be installed in your system, because this is a Python library I would prefer if it is installed in a virtual environment and all of that… As you see it could be daunting and I wanted to have a single and unique way to do it.

Containers to the rescue

If there were a way to isolate (and distribute) a process from all the rest of your processes… Wait a minute, such thing exists! It is called Docker! What if I use a container with all the dependencies I need to do the typesetting of a document in a container and just use it to compile the document and simple reuse the container all over again!

Visual Studio Code has an extension for this, Remote Containers, I just need to configure it to do what I need and make it work with LaTeX Workshop. This was a lot simpler than I thought but it required a few steps, especially for those that never used the extension before.

First, after installed the mentioned extension, we need to create a folder, .devcontainer in the directory where our document project is located, this directory with its content needs to be version controlled if you want to share your experience, it behaves pretty much like your settings for the project. Inside this directory we have to create a Dockerfile with the instructions to assemble our LaTeX container with our requirements, in my case it is very simple:

Feel free to change it to whatever you want to include in your LaTeX distribution, I prefer not to use texlive-full because, well, it will require to install 2GB of packages and I don’t need them all (yet).

Now that we have the instructions to assemble our container I build it locally to avoid delay when running the whole process:

Feel free to use whatever name you want for your image.

Now we create another file, devcontainer.json with the instructions of how to use a container for our project root:

Vscode Latex Workshop Xelatex

The dockerFile and image tell to VSCode to use the image we already built, if this image does not exists it will build it from scratch (and this will probably take some time). We tell it to automatically install the LaTeX Workshop extension in this container (if not, later VSCode will ask us if we want to install it or not) and opening the port 36887 from the container, we need to do this to enable the native preview used by the extension.

Latex Visual Studio Code

And this is all! When we open the directory with our LaTeX project VSCode will just ask us if we want to do this in the container, just follow the prompts and it will be set, our project will be compiled with our container and generate our document, if you need something else installed just do it in the container image instead of your machine.