Skip to content

v2.1.0 — custom KaTeX macros (#15)

Latest

Choose a tag to compare

@MahammadNuriyev62 MahammadNuriyev62 released this 31 Jul 14:55

Your own macros now render (#15)

Macros defined in a file separate from the conversation used to appear as red unrenderable commands. Point the extension at your .tex file(s), or define a few inline:

{
  "claudeCodeKatex.macroFiles": ["~/tex/macros.tex", "${workspaceFolder}/preamble.tex"],

  // or, in KaTeX's own form:
  "claudeCodeKatex.macros": { "\\RR": "\\mathbb{R}", "\\vv": "\\mathbf{#1}" }
}

~, ${workspaceFolder} and ${userHome} are supported in paths.

What the file can contain

A slice of a real paper preamble. Comments, \usepackage lines and prose are ignored, and a definition KaTeX cannot handle is skipped without affecting the others.

\newcommand, \renewcommand, \providecommand, \def, \let and \DeclareMathOperator are all understood. \DeclareMathOperator is mapped onto \operatorname, which KaTeX does have, and your definition wins over a KaTeX built-in of the same name such as \vec or \argmax.

Copying a rendered formula gives you back your macro call, $$\vv{x} \in \RR^n$$, rather than the expansion, so it pastes straight back into your document.

Refreshing

Macros are read when the window loads. After editing a file, run Claude Code LaTeX: Reload Macros, which is also a button in the status bar popup. That popup reports how many macros loaded and names any file it could not read.

Known limits

Two things KaTeX itself cannot do, so neither can this. Both are reported as skipped rather than breaking the rest of your file:

  • optional argument macros, \newcommand{\x}[2][default]{...}
  • \newenvironment

Safety

If anything about a macro file is wrong, math renders exactly as it does without the feature. A bad macro cannot stop a formula from rendering. Users who configure no macros receive a byte for byte identical patch to 2.0.9, which is enforced by a test.

Also in this release: the README now documents Open VSX as an install source for VSCodium, Cursor and Code OSS users.