【Latex】使用技能站:(三)使用 Vscode 配置 LaTeX

使用 Vscode 配置 LaTeX

  • 引言
  • [1 安装texlive](#1 安装texlive)
  • [2 安装vscode](#2 安装vscode)
    • [2.1 插件安装](#2.1 插件安装)
    • [2.2 配置](#2.2 配置)
  • [3 安装SumatraPdf](#3 安装SumatraPdf)
    • [3.1 vscode配置](#3.1 vscode配置)
    • [3.2 配置反向搜索](#3.2 配置反向搜索)

引言

  • 安装texlive
  • 安装vscode
  • 安装SumatraPdf

1 安装texlive

在线LaTeX编辑器:https://www.overleaf.com

TeX Live下载:https://www.tug.org/texlive/acquire-iso.html

MikTeX下载:https://miktex.org/download

LaTeX 公式编辑器:https://latex.codecogs.com/eqneditor/editor.php

一份不太简短的LaTeX介绍:https://github.com/CTeX-org/lshort-zh-cn


2 安装vscode

参考笔者之前的博客:【Ubuntu】安装Anaconda+vscode

2.1 插件安装

  • Chinese , 用于汉化界面
  • LaTeX Workshop , 必备插件

2.2 配置

安装好插件重启一下 vscode ,点击左下角齿轮,打开设置,并打开配置文件 settings.json ,按下图操作

打开配置文件并修改,将下面代码粘贴到里面

python 复制代码
{
    "latex-workshop.latex.autoBuild.run": "never",
    "latex-workshop.showContextMenu": true,
    "latex-workshop.intellisense.package.enabled": true,
    "latex-workshop.message.error.show": false,
    "latex-workshop.message.warning.show": false,
    "latex-workshop.latex.tools": [
        {
            "name": "xelatex",
            "command": "xelatex",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "%DOCFILE%"
            ]
        },
        {
            "name": "pdflatex",
            "command": "pdflatex",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "%DOCFILE%"
            ]
        },
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-pdf",
                "-outdir=%OUTDIR%",
                "%DOCFILE%"
            ]
        },
        {
            "name": "bibtex",
            "command": "bibtex",
            "args": [
                "%DOCFILE%"
            ]
        }
    ],
    "latex-workshop.latex.recipes": [
        {
            "name": "XeLaTeX",
            "tools": [
                "xelatex"
            ]
        },
        {
            "name": "PDFLaTeX",
            "tools": [
                "pdflatex"
            ]
        },
        {
            "name": "BibTeX",
            "tools": [
                "bibtex"
            ]
        },
        {
            "name": "LaTeXmk",
            "tools": [
                "latexmk"
            ]
        },
        {
            "name": "xelatex -> bibtex -> xelatex*2",
            "tools": [
                "xelatex",
                "bibtex",
                "xelatex",
                "xelatex"
            ]
        },
        {
            "name": "pdflatex -> bibtex -> pdflatex*2",
            "tools": [
                "pdflatex",
                "bibtex",
                "pdflatex",
                "pdflatex"
            ]
        },
    ],
    "latex-workshop.latex.clean.fileTypes": [
        "*.aux",
        "*.bbl",
        "*.blg",
        "*.idx",
        "*.ind",
        "*.lof",
        "*.lot",
        "*.out",
        "*.toc",
        "*.acn",
        "*.acr",
        "*.alg",
        "*.glg",
        "*.glo",
        "*.gls",
        "*.ist",
        "*.fls",
        "*.log",
        "*.fdb_latexmk"
    ],
    "latex-workshop.latex.autoClean.run": "onFailed",
    "latex-workshop.latex.recipe.default": "lastUsed",
    "latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",
    "zotero.latexCommand": "cite",
}

3 安装SumatraPdf

官网下载直接安装即可

3.1 vscode配置

将下面代码放到 settings.json 这份配置文件中,注意放的位置在最后一个花括号前面

python 复制代码
  "latex-workshop.view.pdf.viewer": "external",
  "latex-workshop.view.pdf.external.viewer.command":
         "D:/AppData/SumatraPDF/SumatraPDF.exe",  //注意修改路径,为安装的 SumatraPdf 的路径
  "latex-workshop.view.pdf.external.viewer.args": [
          "%PDF%"
      ],

3.2 配置反向搜索

反向搜索有利于快速定位到文档对应的源码位置,将下面代码加入到 settings.json 里面,同样也是最后一个花括号前面

python 复制代码
   "latex-workshop.view.pdf.external.synctex.command":
       "D:/AppData/SumatraPDF/SumatraPDF.exe",  //注意修改路径
   "latex-workshop.view.pdf.external.synctex.args": [
       "-forward-search",
        "%TEX%",
       "%LINE%",
       "%PDF%",
   ],

在 SumatraPdf 软件中做一些配置,通过设置打开高级选项,会弹出一个配置文件,我们只需在配置文件最后加上如下代码

python 复制代码
InverseSearchCmdLine = "D:\Microsoft VS Code\Code.exe" "D:\Microsoft VS Code\resources\app\out\cli.js"  --ms-enable-electron-run-as-node -r -g "%f:%l"
EnableTeXEnhancements = true

然后就可以通过在 pdf 文档中双击跳转到 vscode 源码部分了

相关推荐
学历真的很重要40 分钟前
VsCode+Roo Code+Gemini 2.5 Pro+Gemini Balance AI辅助编程环境搭建(理论上通过多个Api Key负载均衡达到无限免费Gemini 2.5 Pro)
前端·人工智能·vscode·后端·语言模型·负载均衡·ai编程
程序员小寒8 小时前
VSCode有哪些好用的插件和快捷键?
ide·vscode·编辑器
初夏睡觉9 小时前
从0开始c++,但是重置版,第0篇(下载编辑器)
编辑器
Byron Loong11 小时前
【Debug】vscode 调试python,如何配置固定调试文件
ide·vscode·python
电子_咸鱼12 小时前
【QT SDK 下载安装步骤详解 + QT Creator 导航栏使用教程】
服务器·开发语言·网络·windows·vscode·qt·visual studio code
weixin_4093831213 小时前
简单四方向a*寻路学习记录2 先做个数组地图 在cocos编辑器模式上运行出格子 计算角色世界坐标跟数组地图的联系
学习·编辑器·cocos
HealthScience14 小时前
vscode通过跳板机连接到服务器
服务器·ide·vscode
猿小猴子16 小时前
主流 AI IDE 之一的 Kiro 介绍
ide·ai·kiro
神码小Z16 小时前
为什么架构师岗位即将消失?学会使用Cursor的三大神器Rules、Memories、Commands!小白也能写出专家级代码!
ide·intellij-idea
4***997416 小时前
工业网关助力Altivar320与S7-1200协同运行
ide·python·算法·spring·eclipse·sqlite·tornado