Write LaTeX reports with VSCode
Benefits and configuration
8 avr. 2022
If you don't know it yet, LaTeX is a language that allows you to write documents without worrying about the layout. It is used in the scientific community.
Problem: how to write documents efficiently?
If you know a little bit about LaTeX, you have probably already heard about softwares like Texmaker. However, all these programs that I could find are really ugly, not user-friendly, etc.
The only good editor that is currently widespread and that I recommend is Overleaf. It is very useful for group editing with people who don't know Git/GitHub especially. But when you work alone, it is not necessarily ideal...
First of all, it's a website and not a program, so when the servers are down 2 hours before the delivery of a project, nothing is accessible anymore (yes, it has happened to a friend recently...). Moreover, the editor is not necessarily configurable as you wish. You can't install a local package for example (you have to upload it to each of your projects). In short, it is not necessarily ideal.
Solution: Use VSCode, our favorite editor!
Prerequisites
- VSCode
- TeX Live (or alternatives)
- The LaTeX Workshop extension
- The LaTeX Utilities extension
LaTeX Workshop
This very complete extension allows you to replace your usual LaTeX editor. In particular, it allows :
- Automatic PDF compilation of files when saving
- Autocompletion
- Table of contents with jump to sections
- A library of symbols
- A TikZ library
- Preview of equations and TikZ diagrams
- ...
Personally, I prefer to compile with XeLaTeX (especially for the custom fonts support). To do so, you need to add this in your VSCode configuration (Settings > Show settings in JSON):
{ "latex-workshop.latex.tools": [ { "name": "latexmk", "command": "latexmk", "args": [ "-xelatex", "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "%DOC%" ] } ] }
LaTeX Utilities
Less known, this great extension adds several third party features. I use it a lot to speed up writing equations.
It has a multitude of shortcuts. For example:
>=
will be replaced by\geq
2/3
will be replaced by\frac{2}{3}
a1
will automatically add the underscore to writea_1
- ...
Taken together, these shortcuts will save you several hours.
For a more complete overview of the features of this extension, I advise you to take a look at the README of the project.
And then?
This is where the magic happens. When you create a
.texfile in VSCode and save it, LaTeX Workshop will automatically compile your file into a PDF. You can then open this PDF in a VSCode tab (and for example have your
.texon the left and your pdf on the right).
Multi-file or multi-document projects are also very well handled.
Conclusion
- It is indeed possible to edit LaTeX files without having to use unpleasant editors;
- You will save a lot of time.