From b7d75f45215e7643f7d4e5ed2a3c81b60a18810e Mon Sep 17 00:00:00 2001 From: Allan Chain <36528777+AllanChain@users.noreply.github.com> Date: Sun, 1 Dec 2024 10:59:19 +0800 Subject: [PATCH] feat: set macros for MathLive Closes #33 --- src/ml-tweak.ts | 5 +++++ src/settings.ts | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/ml-tweak.ts b/src/ml-tweak.ts index 5879560..053dc4f 100644 --- a/src/ml-tweak.ts +++ b/src/ml-tweak.ts @@ -32,4 +32,9 @@ export function configureMF(mfe: MathfieldElement) { } catch (err) { logseq.UI.showMsg(`Fail to configure MathLive inline shortcuts: ${err}`, 'error') } + try { + mfe.macros = { ...mfe.macros, ...logseq.settings?.macros } + } catch (err) { + logseq.UI.showMsg(`Fail to configure MathLive macros: ${err}`, 'error') + } } diff --git a/src/settings.ts b/src/settings.ts index 05d9903..3907fb4 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -111,6 +111,25 @@ export const settingsConfig: SettingSchemaDesc[] = [ align: '\\begin{align*}\n#? &= #? \\\\\n #? &= #?\\end{align*}', }, }, + { + title: 'Macros', + description: + 'Configure [MathLive macros](https://cortexjs.io/mathlive/guides/macros/).' + + '\n\nOne trick is to copy over default macros with `expand: false` to avoid automatic macro expansion.\n\n' + + '**Note**: MathLive have [bugs](https://github.com/arnog/mathlive/issues/1565) with `expand: false`, ' + + 'Use it with caution.\n\nYou can also check [this discussion]' + + '(https://github.com/AllanChain/logseq-live-math/discussions/14) for more examples.', + key: 'macros', + type: 'object', + default: { + phase: { + def: '\\enclose{phasorangle}{#1}', + args: 1, + captureSelection: false, + expand: false, + }, + }, + }, { title: 'Disable default shortcuts', description: 'Disable default inline shortcuts defined by MathLive.',