Proper Installation and Usage of LateX Workshop in Visual Studio Code
If you're a LateX apologist using Visual Studio Code for writing reports and stuff, it's always a pain to have a full-fledged environment ready, at least when using the default settings.
You're probably here because you can't afford an online solution like Overleaf as a broke student, and want to benefit from Github Student benefits like Github Copilot for helping you write those nice reports.
This guide will help you set up LateX the proper way so that you can set and forget. More specifically, in this guide you'll be adjusting the necessary settings so that you can generate Reports with Acronyms, click on any part of the TEX file or PDF file, so that the other half points at where you're at.
Firstly, you want to install the Latex Workshop extension on VSCode. If you're like me and enjoy using Docker, you won't need to install LateX on your Operating System.
After having installed Docker, you can proceed with the following commmand to download the texlive-full image by xu-cheng (kudos to him):
docker pull --platform linux/amd64 ghcr.io/xu-cheng/texlive-full
While waiting for the command above to finish, you can proceed to the next step, which is withing VSCode. Start by opening your User settings.json file and add the following JSON to it:
{
"latex-workshop.docker.enabled": true,
"latex-workshop.docker.image.latex": "ghcr.io/xu-cheng/texlive-full",
"latex-workshop.latex.clean.subfolder.enabled": true,
"latex-workshop.latex.autoClean.run": "onBuilt",
"latex-workshop.latex.autoBuild.run": "onSave",
"latex-workshop.synctex.afterBuild.enabled": true,
"latex-workshop.view.outline.sync.viewer": true,
"latex-workshop.view.pdf.internal.synctex.keybinding": "double-click"
"latex-workshop.latex.recipes": [
{
"name": "pdflatex -> makeglossaries -> pdflatex",
"tools": [
"latexmk",
"makeglossaries",
"pdflatex"
]
},
{
"name": "latexml",
"tools": [
"latexml"
]
},
{
"name": "latexmk (latexmkrc)",
"tools": [
"latexmk_rconly"
]
},
{
"name": "latexmk (lualatex)",
"tools": [
"lualatexmk"
]
},
{
"name": "latexmk (xelatex)",
"tools": [
"xelatexmk"
]
},
{
"name": "pdflatex -> bibtex -> pdflatex * 2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
{
"name": "Compile Rnw files",
"tools": [
"rnw2tex",
"latexmk"
]
},
{
"name": "Compile Jnw files",
"tools": [
"jnw2tex",
"latexmk"
]
},
{
"name": "Compile Pnw files",
"tools": [
"pnw2tex",
"latexmk"
]
},
{
"name": "tectonic",
"tools": [
"tectonic"
]
}
],
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"-outdir=%OUTDIR%",
"%DOC%"
],
"env": {}
},
{
"name": "lualatexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-lualatex",
"-outdir=%OUTDIR%",
"%DOC%"
],
"env": {}
},
{
"name": "xelatexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-xelatex",
"-outdir=%OUTDIR%",
"%DOC%"
],
"env": {}
},
{
"name": "latexmk_rconly",
"command": "latexmk",
"args": [
"%DOC%"
],
"env": {}
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-output-directory=%OUTDIR%",
"%DOC%"
],
"env": {}
},
{
"name": "makeglossaries",
"command": "makeglossaries",
"args": [
"%DOC%"
],
"env": {}
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
],
"env": {}
},
{
"name": "rnw2tex",
"command": "Rscript",
"args": [
"-e",
"knitr::opts_knit$set(concordance = TRUE); knitr::knit('%DOCFILE_EXT%')"
],
"env": {}
},
{
"name": "jnw2tex",
"command": "julia",
"args": [
"-e",
"using Weave; weave(\"%DOC_EXT%\", doctype=\"tex\")"
],
"env": {}
},
{
"name": "jnw2texminted",
"command": "julia",
"args": [
"-e",
"using Weave; weave(\"%DOC_EXT%\", doctype=\"texminted\")"
],
"env": {}
},
{
"name": "pnw2tex",
"command": "pweave",
"args": [
"-f",
"tex",
"%DOC_EXT%"
],
"env": {}
},
{
"name": "pnw2texminted",
"command": "pweave",
"args": [
"-f",
"texminted",
"%DOC_EXT%"
],
"env": {}
},
{
"name": "tectonic",
"command": "tectonic",
"args": [
"--synctex",
"--keep-logs",
"--print",
"%DOC%.tex"
],
"env": {}
}
],
}
The settings above will configure everything that is needed. There shoudln't be any other setting starting by "latex-workshop", unless you know what you're doing.
After configuring this, every time you save a TEX file, the compilation will trigger automatically, the PDF viewer will match the code line you're selecting or eventually double-click, and the Acronyms will work as should :)
If you also use Git as much as I do for storing your documents, I have this .gitignore section to share with you:
# LaTeX build
*.acn
*.acr
*.alg
*.bbl
*.glg
*.glo
*.gls
*.glsdefs
*.ist
*.synctex.gz
*.lol
*.aux
*.blg
*.fdb_latexmk
*.fls
*.lof
*.Lot
*.toc
*.log
Feel free to drop any suggestion!