cweijan / vscode-office

让VSCode支持预览PDF,Exce和Word等格式, 并增加markdown所见即所得编辑器
MIT License
1.01k stars 93 forks source link

Request for supporting `label` `\ref` `\eqref` #289

Open hyliang96 opened 5 months ago

hyliang96 commented 5 months ago

Vscode-office (v3.1.8) doesn't support label \ref \eqref, while Typora and LaTeX supports.

image

Maybe this is due to KaTeX (a dependency of vscode-office) doesn't support it, whis was discussed in https://github.com/KaTeX/KaTeX/issues/2003 .

Here I provide an idea to implement this feature in vscode-office.

There is a workaround proposed in KaTeX/KaTeX#2003 (comment), which doesn't require KaTeX to support \label \ref \eqref.

When KaTeX option is set as:

trust: (context) => ['\\htmlId', '\\href'].includes(context.command),
macros: {
  "\\eqref": "\\href{###1}{(\\text{#1})}",
  "\\ref": "\\href{###1}{\\text{#1}}",
  "\\label": "\\htmlId{#1}{}"
}

then \label \ref \eqref will be supported.

This idea can be applied to vscode plugin Markdown+Math, by adding the following settings (from goessner/mdmath#116 (comment)) into vscode config file,

"mdmath.katexoptions": {
    "trust": "(context) => ['\\htmlId', '\\href'].includes(context.command)"
},
"mdmath.macros": {
    "\\eqref": "\\href{###1}{(\\text{#1})}",
    "\\ref": "\\href{###1}{\\text{#1}}",
    "\\label": "\\htmlId{#1}{}"
},

and the following screen shot is the effect.

image

Counld author make vscode-office compatible with Markdown+Math, or provide similar config options vscode-office.katexoptions and vscode-office.macros, so as to let vscode-office support label \ref \eqref? Thanks.

By the way, as shown in the screen shot above, this workaround has a disadvantage: $\ref{eq-a}$ $\eqref{eq-a}$ will be rendered as 'eq-a' rather than '1' -- the numbering of equation. I wonder how to fix this bug, or is there another way to support label \ref \eqref?