荣斋居士分享 http://blog.sciencenet.cn/u/dalianwang

博文

配置VS CODE 丝滑编译LaTeX

已有 3373 次阅读 2022-4-24 09:21 |个人分类:软件学习|系统分类:科研笔记

1 背景及问题提出

作为一种高效便捷的写作语言,LaTeX受到很多人的欢迎。由于LaTeX编辑器种类较多(https://en.wikipedia.org/wiki/Comparison_of_TeX_editors),且各有优劣,导致很多用户难以实现最满意的选择。

Tex editor.jpg

截止到目前为止,我觉得最舒心的编辑器是vs code,主要吸引我的功能包括编译速度快、加载多种拓展工具实现高效编写(如图2所示部分拓展,有括号匹配、语法检查、彩虹缩进、颜色主题)等。

image.png

图2 部分vs code拓展


然而,vs code编辑器的最大的难点在于如何进行设置使得vs code可以顺利丝滑地编译LaTeX。经过几番折腾,我的vs code终于可以丝滑运行了。在此,我将我的配置分享给大家。


2 问题解决

2.1 如何打开设置?


image.png

image.png

image.png

2.2  如何修改设置?

将下面的代码放在settings.json文件中

{
//     "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": "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"
//             ]
//         }
//     ],
//     "latex-workshop.view.pdf.viewer": "tab",
//     "latex-workshop.latex.autoBuild.run": "onFileChange",
//     "latex-workshop.message.error.show": false,
//     "latex-workshop.message.warning.show": false,
//     "json.schemas": [
//         {
//             "fileMatch": [
//                 "/myfile"
//             ],
//             "url": "schemaURL"
//         }

//     ],
//     // 设置预览方式

//   "latex-workshop.view.pdf.viewer": "external",

//   "latex-workshop.view.pdf.ref.viewer": "external",

//  

"latex-workshop.latex.tools": [
    {
      "name": "latexmk",
      "command": "latexmk",
      "args": [
        "-pvc-",
        "%DOCFILE%"
      ]
    },
    {
      "name": "latexmk-xelatex",
      "command": "latexmk",
      "args": [
        "-xelatex",
        "-synctex=1",
        "-interaction=nonstopmode",
        "-halt-on-error",
        "-file-line-error",
        "-pv",
        "%DOCFILE%"
      ]
    },
    {
      "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%"
      ]
    },
    {
      "name": "biber",
      "command": "biber",
      "args": [
        "%DOCFILE%"
      ]
    }
  ],
  "latex-workshop.latex.recipes": [
    {
      "name": "xelatex",
      "tools": [
        "xelatex"
      ]
    },
    {
      "name": "latexmk",
      "tools": [
        "latexmk"
      ]
    },
    {
      "name": "xelatex*2",
      "tools": [
        "xelatex",
        "xelatex"
      ]
    },
    {
      "name": "xelatex -> bibtex -> xelatex*2",
      "tools": [
        "xelatex",
        "bibtex",
        "xelatex",
        "xelatex"
      ]
    },
    {
      "name": "xelatex -> biber -> xelatex*2",
      "tools": [
        "xelatex",
        "biber",
        "xelatex",
        "xelatex"
      ]
    },
    // 如果不只为了 CCNUthesis 模板而使用 VS Code 编辑 LaTeX,可以取消注释以下配置以适用更多的文档,
    // 如果需要使用 -shell-escape 选项,可以自行仿照上面的做法进行添加
    {
      "name": "pdflatex",
      "tools": [
        "pdflatex"
      ]
    },
    {
      "name": "pdflatex -> bibtex -> pdflatex*2",
      "tools": [
        "pdflatex",
        "bibtex",
        "pdflatex",
        "pdflatex"
      ]
    },
    {
      "name": "pdflatex -> biber -> pdflatex*2",
      "tools": [
        "pdflatex",
        "biber",
        "pdflatex",
        "pdflatex"
      ]
    },
    {
      "name": "bibtex",
      "tools": [
        "bibtex"
      ]
    },
    {
      "name": "biber",
      "tools": [
        "biber"
      ]
    },
  ],
    "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"
  ],
  // 编译出错时是否通过弹窗显示
  "latex-workshop.message.error.show": false,
  "latex-workshop.message.warning.show": false,  
  "latex-workshop.synctex.afterBuild.enabled": true,
  // // 保存时就启动 Build 编译,Build 默认调用 recipe 中的第一条命令,这里默认设置为 never,如果需要可以改为 onSave
  "latex-workshop.latex.autoBuild.run": "never",
  "editor.tabSize": 2,
  "editor.wordWrap": "bounded",
  // 取当前窗口大小和 wordWrapColumn 的最小值来决定 VS Code 中一行的换行位置
  "editor.wordWrapColumn": 120,
  // 编辑器字体大小设置
  "editor.fontSize": 20,
  // 当 VS Code 失去焦点时自动保存文件
  "files.autoSave": "onWindowChange",
  // 终端字体大小设置
  "terminal.integrated.fontSize": 17,
  // 对不同后缀的文件进行格式关联
  "files.associations": {
    "*.sty": "latex-expl3",
    "*.def": "latex-expl3",
    "*.tex": "latex",
    "*.cls": "latex-expl3"
  },
  // 更加醒目的括号配对
  "editor.guides.bracketPairs":"active",
  // 如何选择自动补全
  "editor.suggestSelection": "first",







 // 设置外部PDF预览器

  "latex-workshop.view.pdf.external.viewer.command": "C:/CTEX/CTeX/ctex/bin/SumatraPDF.exe",

  "latex-workshop.view.pdf.external.viewer.args": ["%PDF%"],

//   // 配置Syntex的正向搜索(Latex->PDF)

  "latex-workshop.view.pdf.external.synctex.command": "C:/CTEX/CTeX/ctex/bin/SumatraPDF.exe",

  "latex-workshop.view.pdf.external.synctex.args": [

    "-forward-search",

    "%TEX%",

    "%LINE%",

    "-reuse-instance",

    "-inverse-search",

    "C:/Users/AppData/Local/Programs/Microsoft VS Code/Code.exe C:/Users/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js -r -g %f:%l",

    "%PDF%"

],

"workbench.editor.enablePreview": false,
"security.workspace.trust.untrustedFiles": "open",
"workbench.colorTheme": "Monokai Pro",
"editor.fontSize": 17,
"workbench.iconTheme": "Monokai Pro Icons",
"bracketPairColorizer.depreciation-notice": false,
"settingsSync.ignoredExtensions": [  
],
}

需要注意的是:上述涉及到地址的代码需要根据自己电脑的实际情况进行,否则还是会出错。





https://blog.sciencenet.cn/blog-2089193-1335370.html

上一篇:优化中的线性化处理及Lingo求解
下一篇:[转载]酒店床尾铺的那块布是干啥的?
收藏 IP: 219.242.57.*| 热度|

2 刘秀梅 杨学祥

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-24 03:02

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部