admin 管理员组

文章数量: 886993

Vscode环境配置之一: 配置 Latex

前言(都是废话,可以不看)

得益于领导大发慈悲和采购部门的努力拖延,我的日常办公电脑终于从笔记本换成了台式工作站。
高兴的同时,原来电脑上的办公环境还要在新电脑上重新配置一遍。
借着周末的机会,先把Vscode相关的环境搭起来。

本文主要介绍如何在VScode配置Latex。

准备步骤

  1. 安装vscode,傻瓜式安装,此处略过。贴上官网链接,方便读者
    /

  2. 配置中文环境

    • 点击拓展图标,打开拓展
    • 搜索Chinese (Simplified) Language Pack for Visual Studio Code插件
    • 点击“install”
    • 重启Vscode

正文-配置Latex

一、 安装TeXLive,你喜欢MiKTex也可以

  1. 通过以下链接下载TeX Live 镜像文件
    .html
    也可以直接前往北大镜像网站等各个镜像网站。

  2. 加载镜像:win10及以上系统可以直接右键菜单中选择“装载”。

  3. 进入镜像根目录,以管理员身份运行install-tl-windows.bat

  4. 安装选项就全部默认吧,如果要改的话,看心情吧。

  5. 等待。。。。。。

  6. 欢迎进入 TeX Live 的世界!

二、为Vscode安装LaTeX插件

  1. 在扩展中搜索LaTeX Workshop插件
  2. 点击install

三、环境配置

  1. Ctrl+shift+P打开命令面板,点击“首选项:打开用户设置(Json)”,把以下代码复制进去即可。
// ======================== LaTeX 设置 BEGIN  ========================// 这是一些独立的编译选项,可以作为工具被编译方案调用"latex-workshop.latex.tools": [{"name": "xelatex-latexmk","command": "latexmk","args":["-xelatex","-synctex=1","-interaction=nonstopmode","-file-line-error","%DOCFILE%"]},{"name": "pdflatex-latexmk","command": "latexmk","args": ["-synctex=1","-interaction=nonstopmode","-file-line-error","-pdf","%DOC%"]},{"name": "pdflatex","command": "pdflatex","args": ["-synctex=1","-interaction=nonstopmode","-file-line-error","%DOCFILE%"]},{"name": "xelatex","command": "xelatex","args": ["-synctex=1","-interaction=nonstopmode","-file-line-error","%DOCFILE%"]},{"name": "latexmk","command": "latexmk","args": ["-synctex=1","-interaction=nonstopmode","-file-line-error","-pdf","%DOCFILE%"]},{"name": "bibtex","command": "bibtex","args": ["%DOCFILE%"]}],//这是一些编译组合,会出现在 GUI 菜单里"latex-workshop.latex.recipes": [{"name": "XeLaTeX-LaTexMk","tools": ["xelatex-latexmk"]},{"name": "PDFLaTeX-LaTexMk","tools": ["pdflatex-latexmk"]},{"name": "XeLaTeX","tools": ["xelatex"]}, {"name": "PDFLaTeX","tools": ["pdflatex"]},{"name": "XeLaTeX -> BibTeX -> XeLaTeX*2","tools": ["xelatex","bibtex","xelatex","xelatex"]},{"name": "PDFLaTeX -> BibTeX -> PDFLaTeX*2","tools": ["pdflatex","bibtex","pdflatex","pdflatex"]},{"name": "latexmk","tools": ["latexmk"]},{"name": "BibTeX","tools": ["bibtex"]}],// 清空中间文件"latex-workshop.latex.clean.fileTypes": ["*.aux","*.bbl","*.blg","*.idx","*.ind","*.lof","*.lot","*.out","*.toc","*.acn","*.acr","*.alg","*.glg","*.glo","*.gls","*.ist","*.fls","*.log","*.xdv","*.fdb_latexmk","*.bcf","*.run.xml","*.pdf","*.synctex.gz"//从PDF返回tex的文件],// 设置 latex-workshop 的 PDF 预览程序,external 指的是外部程序"latex-workshop.view.pdf.viewer": "external","latex-workshop.view.pdf.ref.viewer": "external","latex-workshop.view.pdf.external.viewermand": "C:/Users/yyxx/AppData/Local/SumatraPDF/SumatraPDF.exe", // 注意修改SumatraPDF路径"latex-workshop.view.pdf.external.viewer.args": ["%PDF%"],// 配置正向、反向搜索:.tex -> .pdf"latex-workshop.view.pdf.external.synctexmand": "C:/Users/yyxx/AppData/Local/SumatraPDF/SumatraPDF.exe", // 注意修改SumatraPDF路径"latex-workshop.view.pdf.external.synctex.args": [// 正向搜索"-forward-search","%TEX%","%LINE%","-reuse-instance",// 反向搜索"-inverse-search","\"C:\\Users\\DELL\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" \"C:\\Users\\DELL\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -gr \"%f\":\"%l\"",//注意修改VSCode路径"%PDF%"],// bibtex 格式"latex-workshop.bibtex-format.tab": "tab",// 自动编译,全部关闭,当且仅当你认为有需要的时候才会去做编译"latex-workshop.latex.autoBuild.run": "onSave","latex-workshop.latex.autoBuild.cleanAndRetry.enabled": false,"latex-workshop.message.error.show": true,"latex-workshop.message.warning.show": true,"latex-workshop.latex.recipe.default": "lastUsed",//"latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",//"latex-workshop.showContextMenu": true,// ======================== LaTeX 设置 END ========================
  1. 配置SumatraPDF反向搜索
    • SumatraPDF中依次点击设置->选项
    • 在“请您输入双击PDF文件后调用的命令行”框中输入以下代码,注意将路径改为你自己的

"C:/Users/DELL/AppData/Local/Programs/Microsoft VS Code/Code.exe" "C:/Users/DELL/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js" --ms-enable-electron-run-as-node -g -r "%f":"%l"

“--ms-enable-electron-run-as-node” 千万不要少,网上很多文章都没提到这一点,否则反向搜索会失败,双击PDF无法跳转到代码对应位置。

  1. 配置 .tex->.pdf 快捷键
    • 其实可以鼠标操作,不用快捷键
      左侧活动栏–>TEX–>Navigate,select, and edit–>Synctex from cursor.
    • 有默认快捷键 ctrl+alt+j,读者可以试一试,其实并不快捷
    • 更改快捷键
      • ctrl+K Ctrl+s 打开键盘快捷方式,或者通过点击左下角齿轮打开
      • 搜索syncTex -->旋转左侧按钮–>输入自定义快捷组合

结语

到此为止,vscode配置系列完结(划掉,烂尾),媳妇儿睡觉醒了,没有闲心再在这儿配置环境写博文了,直接登录账户同步,其他的python、remote、matlab、git环境都配置好了,撒由那拉!!

本文标签: Vscode环境配置之一 配置 Latex