利用VS Code實現LaTeX編輯

衆所周知,VS Code插件功能強大、界面美觀,是碼農都喜歡的文本編輯器。下面介紹如何用VS Code配置LaTeX編輯器。

1.下載texlive

從清華大學開源軟件鏡像站下載需要的安裝文件:https://mirrors.tuna.tsinghua.edu.cn/CTAN
例如Windows系統可以選擇texlive/Image目錄下的texlive2019.iso進行光驅安裝。

2. 下載VS Code 插件

搜索latex,下載首選模塊LaTeX。

3.配置用戶設置

依次點擊VS Code的文件→首選項→設置或點擊Ctrl+,進入設置。拉到任何一塊設置的末尾,點擊“在settings.json中編輯”打開json文件。

添加如下代碼:

"latex-workshop.latex.recipes": [{
      "name": "xelatex",
      "tools": [
          "xelatex"
      ]
    }, {
      "name": "latexmk",
      "tools": [
          "latexmk"
      ]
    },
    {
      "name": "pdflatex -> bibtex -> pdflatex*2",
      "tools": [
          "pdflatex",
          "bibtex",
          "pdflatex",
          "pdflatex"
      ]
    }
    ],
    "latex-workshop.latex.tools": [{
    "name": "latexmk",
    "command": "latexmk",
    "args": [
      "-synctex=1",
      "-interaction=nonstopmode",
      "-file-line-error",
      "-pdf",
      "%DOC%"
    ]
    }, {
    "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",
      "%DOC%"
    ]
    }, {
    "name": "bibtex",
    "command": "bibtex",
    "args": [
      "%DOCFILE%"
    ]
    }],
    "latex-workshop.view.pdf.viewer": "tab",
    "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"
    ]

4. Hello World!

新建一個.tex文件,左邊可見模塊的TeX插件圖標。先點build再點view,就大功告成了。

Windows系統如果build失敗,提示找不到root file等等,可以將texlive/bin/win32加入環境變量的路徑中。第一次build後直接點View LaTeX PDF可能會報錯,可以點擊右上角第二個標識預覽pdf。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章