{"id":1405,"date":"2020-06-16T09:15:03","date_gmt":"2020-06-16T09:15:03","guid":{"rendered":"http:\/\/blog.davcloud.top:1443\/?p=1405"},"modified":"2020-06-16T23:25:46","modified_gmt":"2020-06-16T15:25:46","slug":"configure-latex-compilation-environment-in-vscode","status":"publish","type":"post","link":"https:\/\/blog.davcloud.top\/?p=1405","title":{"rendered":"Configure Latex compilation environment in VSCode"},"content":{"rendered":"\n<h2><strong>Abstract<\/strong><\/h2>\n\n\n\n<p>As we know, VSCode is a famous code editor with multiple language environment support. With the supporting of latex extension, it can be used to compile latex files as well. This article aims at record how to configure latex compilation environment in VSCode.<\/p>\n\n\n\n<h2><strong>Step 1. Install latex environment on your computer<\/strong><\/h2>\n\n\n\n<p>Make sure that the latex environment has been installed on your computer. In this article, we use MiKTeX environment as an example.<\/p>\n\n\n\n<h2><strong>Step 2. Install Latex Workshop extension<\/strong><\/h2>\n\n\n\n<p>Search and Install the extension \u201cLatex Workshop\u201d in VSCode:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"727\" height=\"143\" src=\"https:\/\/blog.davcloud.top:1443\/wp-content\/uploads\/2020\/06\/latex-workshop-extension.png\" alt=\"\" class=\"wp-image-1407\" srcset=\"https:\/\/blog.davcloud.top\/wp-content\/uploads\/2020\/06\/latex-workshop-extension.png 727w, https:\/\/blog.davcloud.top\/wp-content\/uploads\/2020\/06\/latex-workshop-extension-300x59.png 300w\" sizes=\"(max-width: 727px) 100vw, 727px\" \/><\/figure><\/div>\n\n\n\n<h2><strong>Step 3. Open VSCode settings in JSON file<\/strong><\/h2>\n\n\n\n<p>You can add the configurations for the extension to either user settings of VSCode or workspace settings of this workspace. In order to use the extension conveniently, we add the configurations to user settings of VSCode in this example so that it can be applied in global. Read my article below to learn how to configure user settings or workspace settings in VSCode:<\/p>\n\n\n\n<figure class=\"wp-block-embed-wordpress aligncenter wp-block-embed is-type-wp-embed is-provider-davcloud-blog\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"BsB14MwpQX\"><a href=\"https:\/\/blog.davcloud.top\/?p=1416\">Configure settings in VSCode<\/a><\/blockquote><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Configure settings in VSCode&#8221; &#8212; davcloud_Blog\" src=\"https:\/\/blog.davcloud.top\/?p=1416&#038;embed=true#?secret=DIW5Tl4Buy#?secret=BsB14MwpQX\" data-secret=\"BsB14MwpQX\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2><strong>Step 4. Add compilation tools configuration to user settings<\/strong><\/h2>\n\n\n\n<p>Three commonly used compilation tools for latex are \u201cxelatex\u201d, \u201cpdflatex\u201d and \u201cbibtex\u201d. Therefore, configure the three tools with settings below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \"latex-workshop.latex.tools\": [\n        {\n            \"name\": \"xelatex\",\n            \"command\": \"xelatex\",\n            \"args\": [\n                \"-synctex=1\",\n                \"-interaction=nonstopmode\",\n                \"-file-line-error\",\n                \"%DOCFILE%\"\n            ]\n        },\n        {\n            \"name\": \"pdflatex\",\n            \"command\": \"pdflatex\",\n            \"args\": [\n                \"-synctex=1\",\n                \"-interaction=nonstopmode\",\n                \"-file-line-error\",\n                \"%DOCFILE%\"\n            ]\n        },\n        {\n            \"name\": \"bibtex\",\n            \"command\": \"bibtex\",\n            \"args\": [\n                \"%DOCFILE%\"\n            ]\n        }\n    ],<\/code><\/pre>\n\n\n\n<h2><strong>Step 5. Add compilation recipes configuration to user settings<\/strong><\/h2>\n\n\n\n<p>The compile links can be represented by different recipes. In this example, we configure four generally used receipes \u201cxelatex\u201d, \u201cpdflatex\u201d, \u201cxe-&gt;bib-&gt;xe-&gt;xe\u201d and \u201cpdf-&gt;bib-&gt;pdf-&gt;pdf\u201d, where the first configured recipe is the default compile recipe:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \"latex-workshop.latex.recipes\": [\n        {\n            \"name\": \"xelatex\",\n            \"tools\": [\n                \"xelatex\"\n            ],\n        },\n        {\n            \"name\": \"pdflatex\",\n            \"tools\": [\n                \"pdflatex\"\n            ]\n        },\n        {\n            \"name\": \"xe->bib->xe->xe\",\n            \"tools\": [\n                \"xelatex\",\n                \"bibtex\",\n                \"xelatex\",\n                \"xelatex\"\n            ]\n        },\n        {\n            \"name\": \"pdf->bib->pdf->pdf\",\n            \"tools\": [\n                \"pdflatex\",\n                \"bibtex\",\n                \"pdflatex\",\n                \"pdflatex\"\n            ]\n        }\n    ],<\/code><\/pre>\n\n\n\n<h2><strong>(Optional) Step 6. Advanced Settings<\/strong><\/h2>\n\n\n\n<h3><strong>Use internal pdf viewer to preview<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\"latex-workshop.view.pdf.viewer\": \"tab\",<\/code><\/pre>\n\n\n\n<p>Press Ctrl + Alt + V to view the pdf file, and the view of pdf will update automatically when the tex file built successfully.<\/p>\n\n\n\n<h3><strong>Auto build when the tex file saved<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\"latex-workshop.latex.autoBuild.run\": \"onFileChange\",<\/code><\/pre>\n\n\n\n<p>If you do not like this, change the configuration to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"latex-workshop.latex.autoBuild.run\": \"never\",<\/code><\/pre>\n\n\n\n<h3><strong>Hide the window pops up automatically when a warning or error occurs during compilation<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\"latex-workshop.message.error.show\": false,\n\"latex-workshop.message.warning.show\": false,<\/code><\/pre>\n\n\n\n<h3>The final configuration(copy to settings.json directly):<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"latex-workshop.latex.tools\": [\n        {\n            \"name\": \"xelatex\",\n            \"command\": \"xelatex\",\n            \"args\": [\n                \"-synctex=1\",\n                \"-interaction=nonstopmode\",\n                \"-file-line-error\",\n                \"%DOCFILE%\"\n            ]\n        },\n        {\n            \"name\": \"pdflatex\",\n            \"command\": \"pdflatex\",\n            \"args\": [\n                \"-synctex=1\",\n                \"-interaction=nonstopmode\",\n                \"-file-line-error\",\n                \"%DOCFILE%\"\n            ]\n        },\n        {\n            \"name\": \"bibtex\",\n            \"command\": \"bibtex\",\n            \"args\": [\n                \"%DOCFILE%\"\n            ]\n        }\n    ],\n    \"latex-workshop.latex.recipes\": [\n        {\n            \"name\": \"xelatex\",\n            \"tools\": [\n                \"xelatex\"\n            ],\n        },\n        {\n            \"name\": \"pdflatex\",\n            \"tools\": [\n                \"pdflatex\"\n            ]\n        },\n        {\n            \"name\": \"xe->bib->xe->xe\",\n            \"tools\": [\n                \"xelatex\",\n                \"bibtex\",\n                \"xelatex\",\n                \"xelatex\"\n            ]\n        },\n        {\n            \"name\": \"pdf->bib->pdf->pdf\",\n            \"tools\": [\n                \"pdflatex\",\n                \"bibtex\",\n                \"pdflatex\",\n                \"pdflatex\"\n            ]\n        }\n    ],\n    \"latex-workshop.view.pdf.viewer\": \"tab\",\n    \"latex-workshop.latex.autoBuild.run\": \"onFileChange\",\n    \"latex-workshop.message.error.show\": false,\n    \"latex-workshop.message.warning.show\": false,\n}<\/code><\/pre>\n\n\n\n<h2><strong>Solution of error occurs<\/strong><\/h2>\n\n\n\n<p>If compile failed with error perl.exe does not exists, just download perl on official website:   <a href=\"https:\/\/www.perl.org\/get.html#win32\">https:\/\/www.perl.org\/get.html#win32<\/a><\/p>\n\n\n\n<h2><strong>Finally<\/strong><\/h2>\n\n\n\n<p>Above the process of configuring finished, you can write a simple tex file to test, it can be compiled successfully if all the configurations are correct. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Abstract As we know, VSCode is a famous code editor with multiple language environment support. With the supporting of latex extension, it can be used to compile latex files as well. This article aims at record how to configure latex compilation environment in VSCode. Step 1. Install latex environment on your computer Make sure that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[28,542],"tags":[114,122],"_links":{"self":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/1405"}],"collection":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1405"}],"version-history":[{"count":8,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/1405\/revisions"}],"predecessor-version":[{"id":1446,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=\/wp\/v2\/posts\/1405\/revisions\/1446"}],"wp:attachment":[{"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.davcloud.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}