LaTeX macro preamble

unlisted

by WenchuanLiliZhao

Define global \newcommand-style macros for MathJax via Settings.

Updated 1mo ago0BSD
View on GitHub

LaTeX macro preamble

Obsidian plugin: define global LaTeX macros for MathJax (inline $…$ and display $$…$$ math in notes). Macros are stored in settings and applied when MathJax loads, similar to a small preamble with \newcommand.

Plugin id: latex-macros-preamble (folder name under .obsidian/plugins/ must match).

What it does

  • Adds a Settings → LaTeX macros tab: list of macros, each with a command name (no leading \) and a definition.
  • Arity is inferred from placeholders #1, #2, … in the definition; the plugin emits \newcommand{\name}[n]{…} for MathJax.
  • Live preview in settings uses Obsidian’s renderMath / finishRenderMath so previews match note rendering.
  • Legacy data: if your vault had an older preamble string in plugin data, lines that look like \newcommand / \renewcommand are parsed into the macro list on load.

Using macros in notes

After saving settings, use your commands inside normal math:

$\Class{x : \phi(x)}$

If math does not pick up changes, reload Obsidian (or restart the app) so MathJax is re-initialized with the new preamble.

Limitations

  • Only what MathJax supports applies; this is not a full LaTeX engine or PDF export preamble.
  • Macros are global to the vault for this plugin’s registered MathJax usage, not per-note files.

Installing from source

If you are not using Community Plugins: in this directory run npm install and npm run build, then copy main.js, styles.css, and manifest.json into .obsidian/plugins/latex-macros-preamble/. For day-to-day development, npm run dev watches and rebuilds main.js.

API (other plugins)

LatexMacrosPlugin implements LatexMacrosPluginApi (src/plugin-api.ts): settings, saveSettings(), applyPreamble(), and previewMacroInElement() for embedding previews.

Further reading

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.