VS code +Latex+SumatrPDF正反向搜索设置

VS code +Latex+SumatrPDF 正反向搜索设置

复制最下面的代码到settings.json即可,注意更改路径和易错点,如下:

1. 不能删除.gz文件,所以清除生成的多余文件的代码为:
       "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"
       ],

注意此项里面不能添加后缀为.gz的代码!

2. 设置正向搜索
       "latex-workshop.view.pdf.viewer": "external",
       "latex-workshop.view.pdf.external.viewer.command": "D:/SumatraPDF/SumatraPDF/SumatraPDF.exe", 
       // 注意修改路径,路径为SumatraPDF.exe文件的路径
       "latex-workshop.view.pdf.external.viewer.args": [
           "-forward-search",
           "%TEX%",
           "%LINE%",
           "-reuse-instance",
           "-inverse-search",
           "\"D:\\Microsoft VS Code\\Code.exe\" \"D:\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -gr \"%f\":\"%l\"",
           "%PDF%"
           //前面一个路径是VS code 安装包的路径,后面一个路径与Code.exe在同一个大文件夹下
           //参考下方截图   
       ],

路径示意图:
注意
D:\Microsoft VS Code\Code.exe”
D:\Microsoft VS Code\resources\app\out\cli.js” -gr “%f”:"%l""
是在同一大文件夹下,换成你自己的后,第二行后面的代码照抄我这上面的就好了
在这里插入图片描述

3. 文件路径需要注意的东西

文件名称带空格的,要把 / 换成 \ \
在这里插入图片描述
在这里插入图片描述

4. 设置反向搜索
       "latex-workshop.view.pdf.external.synctex.command": "D:/SumatraPDF/SumatraPDF/SumatraPDF.exe", // 注意修改路径。
       "latex-workshop.view.pdf.external.synctex.args": [
           "-forward-search",
           "%TEX%",
           "%LINE%",
           "-reuse-instance",
           "-inverse-search",
           "\"D:\\Microsoft VS Code\\Code.exe\" \"D:\\Microsoft VS Code\\resources\\app\\out\\cli.js\"  -gr \"%f:%l\"",
           "%PDF%"
    ],

这里路径和上面的一样,注意 -gr 不要写错了,深刻的教训!

SumatraPDF软件中的设置:

方法一:设置-高级选项
入图片描述
找到这行,将后面改为之前设置的。

方法二: 设置-选项
在这里插入图片描述
改成刚才设置的即可。

5. 快捷键

正向搜索: 代码处 ctrl+alt+j
反向搜索:双击PDF

6. 完整代码
{
    //------------------------------LaTeX 配置----------------------------------
       // 设置是否自动编译
       "latex-workshop.latex.autoBuild.run":"onFileChange",
       //右键菜单
       "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"
       ],
       //设置为onFaild 在构建失败后清除辅助文件
       "latex-workshop.latex.autoClean.run": "onFailed",
       // 使用上次的recipe编译组合
       "latex-workshop.latex.recipe.default": "lastUsed",
       // 用于反向同步的内部查看器的键绑定。ctrl/cmd +点击(默认)或双击
       "latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",
   
   
   
       //使用 SumatraPDF 预览编译好的PDF文件
       // 设置VScode内部查看生成的pdf文件
       "latex-workshop.view.pdf.viewer": "external",
       // PDF查看器用于在\ref上的[View on PDF]链接
       // "latex-workshop.view.pdf.ref.viewer":"auto",
       // 使用外部查看器时要执行的命令。此功能不受官方支持。
       "latex-workshop.view.pdf.external.viewer.command": "D:/SumatraPDF/SumatraPDF/SumatraPDF.exe", // 注意修改路径
       // 使用外部查看器时,latex-workshop.view.pdf.external.view .command的参数。此功能不受官方支持。%PDF%是用于生成PDF文件的绝对路径的占位符。
       "latex-workshop.view.pdf.external.viewer.args": [
           
           "-forward-search",
           "%TEX%",
           "%LINE%",
           "-reuse-instance",
           "-inverse-search",
           "\"D:\\Microsoft VS Code\\Code.exe\" \"D:\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -gr \"%f\":\"%l\"",
           "%PDF%"
       ],
       // 将synctex转发到外部查看器时要执行的命令。此功能不受官方支持。
       "latex-workshop.view.pdf.external.synctex.command": "D:/SumatraPDF/SumatraPDF/SumatraPDF.exe", // 注意修改路径
       // latex-workshop.view.pdf.external.synctex的参数。当同步到外部查看器时。%LINE%是行号,%PDF%是生成PDF文件的绝对路径的占位符,%TEX%是触发syncTeX的扩展名为.tex的LaTeX文件路径。
       "latex-workshop.view.pdf.external.synctex.args": [
           "-forward-search",
           "%TEX%",
           "%LINE%",
           "-reuse-instance",
           "-inverse-search",
           "\"D:\\Microsoft VS Code\\Code.exe\" \"D:\\Microsoft VS Code\\resources\\app\\out\\cli.js\"  -gr \"%f:%l\"",
           
           "%PDF%"
    ],
    
   }
  • 12
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值