1. 程式人生 > 其它 >VSCode配置Latex編譯環境

VSCode配置Latex編譯環境

VSCode配置Latex編譯環境

需要在VSCode中安裝LaTeX Workshop外掛,並對setting.json檔案進行配置。

setting.json檔案的{}中加入如下配置程式碼:

/***********************************
*  下面為Latex編譯環境配置
***********************************/

    //使用 SumatraPDF 預覽編譯好的PDF檔案
    // 設定VScode內部檢視生成的pdf檔案
    // PDF檢視器用於在\ref上的[View on PDF]連結
    "latex-workshop.view.pdf.ref.viewer":"auto",
    // 使用外部檢視器時要執行的命令。此功能不受官方支援。
    "latex-workshop.view.pdf.external.viewer.command": "C:/SumatraPDF/SumatraPDF.exe", // 注意修改路徑
    // 使用外部檢視器時,latex-workshop.view.pdf.external.view .command的引數。此功能不受官方支援。%PDF%是用於生成PDF檔案的絕對路徑的佔位符。
    "latex-workshop.view.pdf.external.viewer.args": [
        "%PDF%"
    ],
    // 將synctex轉發到外部檢視器時要執行的命令。此功能不受官方支援。
    "latex-workshop.view.pdf.external.synctex.command": "C:/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",
        "\"C:/Microsoft VS Code/Code.exe\"\" \"C:/Microsoft VS Code/resources/app/out/cli.js\" -r -g \"%f:%l\"", // 注意修改路徑
        "%PDF%"
    ],
    "editor.minimap.enabled": true, //控制是否顯示縮圖。
    //定義要在配方中使用的 LaTeX 編譯工具。每個工具都標有其名稱。 
    //呼叫時,命令會使用 args 中定義的引數和 env 中定義的環境變數生成。 
    //通常,除非在路徑中,否則每個引數中不應出現空格。
    //佔位符 %DOC%、%DOC_W32%、%DOC_EXT%、%DOC_EXT_W32%、%DOCFILE%、%DOCFILE_EXT%、%DIR%、%DIR_W32%、%TMPDIR% 和 %OUTDIR%、%OUTDIR_W32% 可用.
    "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",
          "%DOC%"
            ]
        },          
        {
          "name": "pdflatex",
          "command": "pdflatex",
          "args": [
          "-synctex=1",
          "-interaction=nonstopmode",
          "-file-line-error",
          "%DOC%"
          ]
        },
        {
          "name": "bibtex",
          "command": "bibtex",
          "args": [
          "%DOCFILE%"
          ]
        }
      ],
  "latex-workshop.latex.recipes": [
        {
          "name": "xelatex",
          "tools": [
          "xelatex"
                      ]
                },
        {
          "name": "latexmk",
          "tools": [
          "latexmk"
                      ]
        },

        {
          "name": "pdflatex -> bibtex -> pdflatex*2",
          "tools": [
          "pdflatex",
          "bibtex",
          "pdflatex",
          "pdflatex"
                      ]
        }
      ],
  "latex-workshop.view.pdf.viewer": "tab",
  "latex-workshop.latex.clean.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"
    ],
    //設定為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",
    //右鍵選單
    "latex-workshop.showContextMenu":true,
    //從使用的包中自動補全命令和環境
    "latex-workshop.intellisense.package.enabled": true,
    //將 glob 模式配置到編輯器(例如 "*十六進位制": "hexEditor.hexEdit")。這些優先順序高於預設行為。
    "workbench.editorAssociations": {
        "*.ipynb": "jupyter-notebook"
    },
    "kite.showWelcomeNotificationOnStartup": false,    //需要安裝kite,show the Kite welcome notification on startup.
    "python.defaultInterpreterPath": "E:\\Python\\python.exe", //python路徑
    //應在何處顯示單元格工具欄,或是否隱藏它。
    "notebook.cellToolbarLocation": {
        "default": "right",
        "jupyter-notebook": "left"//為特定檔案型別配置單元格工具欄位置
    },
    //若設定為 true,則自動從當前 Git 儲存庫的預設遠端庫提取提交。若設定為“全部”,則從所有遠端庫進行提取。
    "git.autofetch": true,
    //始終信任工作區
    "security.workspace.trust.untrustedFiles": "open",
    //不顯示新版本訊息
    "vsicons.dontShowNewVersionMessage": true,
    //針對某種語言,配置替代編輯器設定
    "[latex]": {
        "editor.formatOnPaste": false,//針對某種語言,配置替代編輯器設定
        "editor.suggestSelection": "recentlyUsedByPrefix" //控制在建議列表中如何預先選擇建議。recentlyUsedByPrefix: 根據之前補全過的建議的字首來進行選擇。例如,co -> console、con -> const。
    },
    "code-runner.clearPreviousOutput": true,
    "code-runner.saveAllFilesBeforeRun": true,
    "code-runner.runInTerminal": true,