欢迎光临散文网 会员登陆 & 注册

VS Code+Sumatra PDF正反向搜索

2023-06-29 00:36 作者:青爷威武  | 我要投稿

简介

重新装机后,在配置VS Code和LaTeX的环境后,问题卡在了正反向搜索这边,简单记录下。


综合参考以下链接:

  • [VS Code + Tex Live + SumatraPDF配置LaTeX反向搜索(持续更新)](https://blog.csdn.net/yihuajack/article/details/123877375)

  • [解决SumatraPDF 在VS Code上反向搜索失效](https://www.jianshu.com/p/2b21384e0638)

  • [Sumatra PDF反向搜索的问题记录 (texlive+vscode)](https://zhuanlan.zhihu.com/p/447892378)

正向

在安装LaTeX Workshop后,打开VS Code的settings.json


首先是配置基本的命令参数,常用的就是这三种

   "latex-workshop.latex.tools": [
       {
           "name": "xelatex",
           "command": "xelatex",
           "args": [
               "-synctex=1",
               "-interaction=nonstopmode",
               "-file-line-error",
               "-pdf",
               "%DOCFILE%"
           ]
       },
       {
           "name": "pdflatex",
           "command": "pdflatex",
           "args": [
               "-synctex=1",
               "-interaction=nonstopmode",
               "-file-line-error",
               "%DOCFILE%"
           ]
       },
       {
           "name": "bibtex",
           "command": "bibtex",
           "args": [
               "%DOCFILE%"
           ]
       }
   ],


然后是由上述基本命令引出的编译链

   "latex-workshop.latex.recipes": [
       {
           "name": "xelatex",
           "tools": [
               "xelatex"
           ]
       },
       {
           "name": "pdflatex",
           "tools": [
               "pdflatex"
           ]
       },
       {
           "name": "xe->bib->xe->xe",
           "tools": [
               "xelatex",
               "bibtex",
               "xelatex",
               "xelatex"
           ]
       },
       {
           "name": "pdf->bib->pdf->pdf",
           "tools": [
               "pdflatex",
               "bibtex",
               "pdflatex",
               "pdflatex"
           ]
       }
   ],


接着配置外部PDF阅读器

   "latex-workshop.view.pdf.viewer": "external",
   "latex-workshop.view.pdf.ref.viewer": "external",
   "latex-workshop.view.pdf.external.viewer.command": "C:/Users/AppData/Local/SumatraPDF/SumatraPDF.exe",


接下来才是正向搜索:

  1. 首先保证.gz不会被删除

  2. 同样地,在settings.json写入配置

"latex-workshop.view.pdf.external.synctex.command": "C:/Users/AppData/Local/SumatraPDF/SumatraPDF.exe",
   "latex-workshop.view.pdf.external.synctex.args": [
       "-forward-search",
       "%TEX%",
       "%LINE%",
       "-reuse-instance",
       "-inverse-search",
       "%PDF%"
   ],

有人在latex-workshop.view.pdf.external.synctex.args加入反向搜索的命令,但其实不会起作用,反向搜索只要在Sumatra PDF中设置就可以了

  1. 设置正向搜索等快捷键,打开keybindings.json

{
       "key": "alt+s",
       "command": "latex-workshop.synctex",
       "when": "editorTextFocus && !isMac"
   },
   {
       "key": "alt+b",
       "command": "latex-workshop.build",
       "when": "editorTextFocus && !isMac"
   },
   {
       "key": "alt+t",
       "command": "latex-workshop.kill",
       "when": "editorTextFocus && !isMac"
   },
   {
       "key": "alt+e",
       "command": "latex-workshop.recipes"
   },

这样就可以通过alt+s来正向搜索

反向

在Sumatra PDF的设置->选项中,设置反向搜索命令:

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

  • 第一个参数是VS Code的所在位置

  • 第二个参数的cli.js和第三个参数的--ms-enable-electron-run-as-node是避免VS Code使用子进程打开Sumatra PDF后,Sumatra PDF无法反向搜索的情况


VS Code+Sumatra PDF正反向搜索的评论 (共 条)

分享到微博请遵守国家法律