artisticat1 / obsidian-latex-suite

Make typesetting LaTeX as fast as handwriting through snippets, text expansion, and editor enhancements
MIT License
1.39k stars 55 forks source link

[FR] Global/local latex macro definitions #84

Open itsuhane opened 2 years ago

itsuhane commented 2 years ago

Motivation

Currently, I define custom latex commands inside the first displayed equation block, for example:

$$
\newcommand{\diff}[2]{\frac{\mathrm{d}#1}{\mathrm{d}#2}}
\newcommand{\pardiff}[2]{\frac{\partial{}#1}{\partial{}#2}}
\newcommand{\ie}{\textit{i}.\textit{e}.}
\ie \diff{E}{u} = \pardiff{L}{u} - \diff{}{x}\pardiff{L}{u'} = 0
$$

The command definitions will be available in the current file (and in fact, leaking to the whole obsidian app once this block is rendered, which could be a security issue).

Feature Request

It would be helpful to support macro definitions, for example in the page's md preamble:

---
obsidian-latex-suite:
  latex-preamble: |
    \newcommand{\diff}[2]{\frac{\mathrm{d}#1}{\mathrm{d}#2}}
    \newcommand{\pardiff}[2]{\frac{\partial{}#1}{\partial{}#2}}
    \newcommand{\ie}{\textit{i}.\textit{e}.}
---

$$
\ie \diff{E}{u} = \pardiff{L}{u} - \diff{}{x}\pardiff{L}{u'} = 0 % the commands are available ONLY IN THIS FILE.
$$

Or setting them in some global config file so that all the files in the vault will benefit:

// .config/obsidian-latex-suite.conf.js
{
  // ...
  'latex-preamble': [
    '\newcommand{\diff}[2]{\frac{\mathrm{d}#1}{\mathrm{d}#2}}',
    '\newcommand{\pardiff}[2]{\frac{\partial{}#1}{\partial{}#2}}',
    '\newcommand{\ie}{\textit{i}.\textit{e}.}'
  ], // all the docs will be able to use these commands.
  // ...
}
itsuhane commented 2 years ago

Follow up: Extended LaTeX solved part of this issue. And its looking for another maintainer. Maybe the two plugins can be merged?

artisticat1 commented 1 year ago

The focus of this plugin is making typing LaTeX easier, as opposed to extending its functionality. Therefore, I think this functionality would belong better in the Extended MathJax plugin that you mentioned.

cossio commented 1 year ago

The command definitions will be available in the current file (and in fact, leaking to the whole obsidian app once this block is rendered, which could be a security issue).

Maybe this can be brought up as an upstream issue in Obsidian?