Skip to content

Configuration

zhangxh edited this page Aug 16, 2026 · 5 revisions

配置参考

在 VS Code Settings 中搜索:

@ext:zhangxh-math.texleaf

TeXLeaf 0.7.2 的 38 个用户可见设置只分为三组:

  1. TeXLeaf · 片段:22 项;
  2. TeXLeaf · 文献:9 项;
  3. TeXLeaf · 预览:7 项。

没有单独“高级”第四组;高级匹配参数归入“片段”。全部设置 scope 都是 resource,可以在用户、工作区、工作区文件夹或语言级范围覆盖。数组和对象较适合在 settings.json 中编辑。

TeXLeaf · 片段

设置 默认值 作用
texleaf.enabled true TeXLeaf 总开关
texleaf.autoSnippets true 自动展开带 A 选项的 Snippet 和整篇模板
texleaf.manualTrigger "tab" 非自动规则确认键:tabspace
texleaf.autoFraction true 数学区域输入 / 后把左侧局部表达式转换为分式
texleaf.autoFractionCommand "\\frac" 自动分数使用的命令,如 \frac\dfrac\tfrac
texleaf.autoEnlargeBrackets true 高结构插入后辅助把包围括号改为 \left/\right
texleaf.visualSnippets true 启用选择区包裹规则
texleaf.matrixShortcuts true matrix/align 的 Tab/Enter/Shift+Enter 和安全 left/right 跨行 Enter
texleaf.tabout true Tab 跳过 tabstop、闭括号或数学定界符
texleaf.skipPairedClosingCharacters true 已有 )]} 前输入同字符时只越过
texleaf.autoDeleteMathDelimiters true 空数学定界符内 Backspace 删除整对
texleaf.colorizeBrackets true 数学区域按嵌套深度着色括号
texleaf.highlightActiveBracketPair true 高亮光标附近或包围光标的括号对
texleaf.enableCompletions true 把可用 Snippet 提供给原生 Suggest
texleaf.languageIds ['latex','tex','bibtex'] 允许的 language ID;仍只作用于已保存 .tex/.bib
texleaf.snippetFiles [] 显式项目附加 JSON/JSONC 相对路径
texleaf.excludedEnvironments ['verbatim','lstlisting','minted'] 禁止自动片段和自动分数的环境
texleaf.matrixEnvironments matrix/align 默认列表 启用矩阵快捷键的环境名
texleaf.autoFractionBreakingCharacters "+-=,;:&" 自动分数向左扫描的停止字符
texleaf.autoEnlargeTriggers ['\\frac','\\sum','\\prod','\\int','\\lim'] 触发括号放大的命令
texleaf.maxRegexScanLength 512 正则规则向光标前扫描长度,范围 64–8192
texleaf.wordDelimiters "., +-\\n\\t:;!?\\/{}[]()=~$" w 选项认可的词边界;\n/\t 会解码

matrixEnvironments 的完整默认值:

[
  "matrix", "pmatrix", "bmatrix", "Bmatrix",
  "vmatrix", "Vmatrix", "array", "cases",
  "align", "align*", "aligned"
]

片段管理、默认规则和模板见 片段与模板;数据语法见 Snippet 格式

TeXLeaf · 文献

设置 默认值 / 范围 作用
texleaf.zoteroCitations true 文献/Zotero 总开关;未信任工作区强制停用
texleaf.bibliographyFile "reference.bib" 工作区内相对 .bib 路径
texleaf.bibliographyFormat "bibtex" 新导入条目格式:bibtexbiblatex
texleaf.autoShowCitationPicker true 进入 citation 参数时自动触发原生 Suggest
texleaf.citationCommands 见下方 可触发补全的命令;星号变体自动兼容
texleaf.zoteroLibrary "My Library" library 名称或内部数字 ID
texleaf.zoteroPort 231191–65535 Zotero/BBT 端口;主机固定 127.0.0.1;Juris-M 常见 24119
texleaf.zoteroRequestTimeoutMs 10000500–60000 本机请求超时,毫秒
texleaf.zoteroCacheSeconds 300–3600 文献列表内存缓存时间;0 表示每次过期刷新

默认 citation commands:

[
  "cite", "citep", "citet", "Cite", "Citet",
  "autocite", "parencite", "textcite", "footcite", "supercite"
]

命令名可以带或不带开头反斜杠,必须是安全的 LaTeX 命令名;星号形式自动兼容。

示例:

{
  "texleaf.bibliographyFile": "bib/sources.bib",
  "texleaf.bibliographyFormat": "biblatex",
  "texleaf.citationCommands": [
    "cite", "parencite", "textcite", "smartcite"
  ],
  "texleaf.zoteroLibrary": "42",
  "texleaf.zoteroPort": 23119,
  "texleaf.zoteroCacheSeconds": 60
}

远程主机、Better BibTeX、去重和第三方 citation provider 的边界见 文献与 Zotero

TeXLeaf · 预览

设置 默认值 / 范围 作用
texleaf.mathPreview.enabled true Math Preview 总开关
texleaf.mathPreview.presentation "cursor" cursorhoverboth
texleaf.mathPreview.placement "auto" autoabovebelow
texleaf.mathPreview.debounceMs 12050–2000 输入/移动停止后的更新延迟;大文档至少 300 ms
texleaf.mathPreview.scale 10.5–3 SVG 显示缩放
texleaf.mathPreview.maxSourceLength 8192256–32768 单公式最大 UTF-16 字符数
texleaf.mathPreview.macros {} 最多 128 个安全 MathJax 宏

宏键不带反斜杠,只允许 [A-Za-z@]+;单个 replacement 最多 2,048 字符,设置序列化总长度最多 16,384 UTF-16 字符。示例:

{
  "texleaf.mathPreview.presentation": "cursor",
  "texleaf.mathPreview.placement": "auto",
  "texleaf.mathPreview.debounceMs": 180,
  "texleaf.mathPreview.scale": 1.1,
  "texleaf.mathPreview.macros": {
    "RR": "\\mathbb{R}",
    "CC": "\\mathbb{C}"
  }
}

定位、主题、性能和 API 限制见 Math Preview

语言默认值与第三方补全

TeXLeaf 为 LaTeX/TeX 贡献以下默认值

"[latex]": {
  "editor.wordBasedSuggestions": "off"
},
"[tex]": {
  "editor.wordBasedSuggestions": "off"
}

作用是避免 VS Code 把文档中出现过的普通单词或 citation key 再作为 Text/word 候选混入 Suggest。用户或工作区显式设置优先于扩展默认。

这不能删除 LaTeX Workshop 自己的 citation provider。若它继续用 key 作为标签,可由用户显式设置:

{
  "latex-workshop.intellisense.citation.label": "title"
}

TeXLeaf 不能选择性删除另一扩展的候选;不要设置 editor.suggest.showReferences: false,否则会同时隐藏 TeXLeaf 文献和其他 Reference 补全。详见 文献与 Zotero

命令

片段

命令面板名称 Command ID
TeXLeaf: 管理 Snippet 与模板 texleaf.openSnippetEditor
TeXLeaf: 管理 TeX 模板 texleaf.openTemplateFile
TeXLeaf: 打开高级 Snippet JSONC texleaf.openSnippetFile
TeXLeaf: 恢复默认片段 texleaf.restoreDefaultSnippets
TeXLeaf: 重载片段 texleaf.reloadSnippets
TeXLeaf: 搜索并插入片段 texleaf.pickSnippet
TeXLeaf: 导入片段 texleaf.importSnippets
TeXLeaf: 导出片段 texleaf.exportSnippets
TeXLeaf: 用片段包裹所选内容 texleaf.wrapSelection
TeXLeaf: 切换启用状态 texleaf.toggle

文献

命令面板名称 Command ID
TeXLeaf: 显示参考文献补全 texleaf.pickCitation
TeXLeaf: 刷新 Zotero 参考文献缓存 texleaf.refreshZotero

预览

命令面板名称 Command ID
TeXLeaf: 切换 Math Preview texleaf.toggleMathPreview
TeXLeaf: 刷新 Math Preview texleaf.refreshMathPreview
TeXLeaf: 关闭当前 Math Preview texleaf.dismissMathPreview

部分内部命令(如 texleaf.handleTabmatrixEnter)由 when context 和键位调用,不需要直接从命令面板运行。

默认快捷键

功能 Windows / Linux macOS 说明
搜索并插入片段 Ctrl+Alt+L Cmd+Alt+L 编辑器聚焦且 TeXLeaf 开启
精确展开 / Tabout / Matrix 列 Tab Tab 按 context 决定;精确 TeXLeaf trigger 可在 Suggest 打开时优先
Matrix/Align 换行 Enter Enter 只在 TeXLeaf 提供对应 action 时
跳出 Matrix/Align Shift+Enter Shift+Enter 当前 matrix action 可用时
手动空格展开 Space Space manualTrigger=space
删除空数学定界符 Backspace Backspace 光标位于受支持空定界符内部
关闭当前预览 Escape Escape Suggest/Rename/Inline Suggest 不活跃时

快捷键冲突可在 Preferences: Open Keyboard Shortcuts 搜索 texleaf,或运行 Developer: Toggle Keyboard Shortcuts Troubleshooting

用户设置、工作区设置与安全

  • 个人输入习惯适合用户设置;
  • bibliography 路径、citation commands 和项目附加 Snippet 适合工作区设置;
  • 不应把个人 Zotero library 名称或不必要的本机端口写进公开仓库;
  • 未信任工作区忽略 snippetFiles,并禁用 Zotero 读取/写入;
  • bibliographyFile 只接受工作区内相对 .bib 路径;
  • zoteroPort 只改变固定回环主机上的端口数字。

相关页面

Clone this wiki locally