vscode寫latex的正反向搜索問題
vscode使用LaTeX Workshop + TexLive時可以很舒暢的寫作
但是在長篇寫作時,會涉及到正反向搜索的需求。即根據源碼搜pdf的位置,和根據pdf的位置搜索源碼的位置。尤其改論文時用的很多。
但是我使用搜索功能發現不能用,幾經搜索找到了問題。
在安裝LaTeX Workshop時,需要在setting.json中進行一些配置工作,這里面有兩項配置叫
"latex-workshop.latex.autoClean.run": "onBuilt",
"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"
],
這個配置是每次編譯后,會將中間生成的臨時文件刪除掉,以保持項目文件夾的整潔。
但是!這里會闡述掉一個重要的文件,叫xxx.synctex.gz。這個文件負責的就是剛才說的正反向搜索的錨點。如果刪除掉它,那么整個正反向搜索的功能就失效了。
想要不刪除它,也很簡單,只要注釋掉上面的配置文件中的.gz就可以了。
使用正反向搜索的方法也很簡單
正向搜索:先固定源碼中的光標,然后Ctrl + Alt + J
反向搜索:Ctrl + 鼠標左鍵點擊pdf中某個位置
最后附上我關於LaTeX Workshop的全部配置設置:
其中為了寫論文方便,我把pdflatex - bibtex - pdflatex*2放到了最前面,不常用的話可以自己修改回去。
// Latex workshop
"editor.wordWrap": "on",
"workbench.startupEditor": "newUntitledFile",
"latex-workshop.latex.autoClean.run": "onBuilt",
"latex-workshop.hover.command.enabled": true,
"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"
],
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.recipes": [
{
"name": "pdflatex ➞ bibtex ➞ pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
{
"name": "XeLaTex 🔃",
"tools": [
"xelatex"
]
},
{
"name": "pdfLaTex 🔃",
"tools": [
"pdflatex"
]
},
{
"name": "texify 🔃",
"tools": [
"texify"
]
},
{
"name": "xelatex ➞ bibtex ➞ xelatex*2",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
},
{
"name": "xelatex ➞ biber ➞ xelatex*2",
"tools": [
"xelatex",
"biber",
"xelatex",
"xelatex"
]
},
{
"name": "latexmk 🔃",
"tools": [
"latexmk"
]
},
{
"name": "BibTeX 🔃",
"tools": [
"bibtex"
]
},
{
"name": "Biber 🔃",
"tools": [
"biber"
]
}
],
"latex-workshop.latex.tools": [
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOC%"
]
},
{
"name": "texify",
"command": "texify",
"args": [
"--synctex",
"--pdf",
"--tex-option=\"-interaction=nonstopmode\"",
"--tex-option=\"-file-line-error\"",
"%DOC%.tex"
],
"env": {}
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
},
{
"name": "biber",
"command": "biber",
"args": [
"%DOCFILE%"
]
}
],
"extensions.autoUpdate": true,
"tabnine.experimentalAutoImports": true