You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code中LaTeX Workshop下自动补全\(\)和\[\]的方法咨询

实现LaTeX中()和[]的自动配对补全

插件方案(与LaTeX Workshop兼容)

  • 安装Latex Utilities插件,它与LaTeX Workshop无冲突,内置了LaTeX符号、环境的自动配对功能。
  • 安装后,在VS Code设置中搜索latex.utilities.autoPair,确保启用(、[等符号的自动配对(默认已启用)。此时输入\(会直接补全为\(\)并将光标定位在中间,无需回车选择补全项。

自定义代码片段方案

如果不想额外安装插件,可以通过VS Code用户代码片段实现:

  1. 按下Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(Mac),输入Configure User Snippets,选择latex.json(针对LaTeX文件的全局片段)。
  2. 将以下代码添加到文件中:
{
  "Inline Math Auto Pair": {
    "prefix": "\\(",
    "body": "\\($0\\)",
    "description": "Auto complete inline math brackets"
  },
  "Display Math Auto Pair": {
    "prefix": "\\[",
    "body": "\\[$0\\]",
    "description": "Auto complete display math brackets"
  }
}
  1. 调整VS Code设置,让代码片段优先触发:打开settings.json(快捷键Ctrl+,,点击右上角打开JSON),添加或修改:
"editor.snippetSuggestions": "top",
"latex-workshop.intellisense.package.enabled": true,
"editor.acceptSuggestionOnEnter": "off"

设置完成后,输入\(或\[时,代码片段会优先触发并自动补全,光标直接落在括号中间。

内容的提问来源于stack exchange,提问作者Severus Tux

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 20:23:26