Hi, I have been trying to write a latex equation programmatically using the ProseMirror Math plugin, (GitHub - benrbray/prosemirror-math: Schema and plugins for "first-class" math support in ProseMirror!).
This is the command I am using(prosemirror-math/src/commands/insert-math-cmd.ts at master · benrbray/prosemirror-math · GitHub), But however, I don’t know how to pass the NodeType Instance to that function.
addLatex() {
// this.editor.schema.nodes.math_inline = "{S}_{dp}={n}_A.{n}_B.\mathit{\exp}\left(-{wd}^2\right); Sc= median\left\{{S}_{dp}\right\}"
const nodeSchema = this.editor.schema.node(schema.nodes.math_inline);
nodeSchema.textContent = "{S}_{dp}={n}_A.{n}_B.\mathit{\exp}\left(-{wd}^2\right); Sc= median\left\{{S}_{dp}\right\}";
this.editor.commands
.insertMathInline(nodeSchema)
.exec();
}
insertMathInline(nodeType:NodeType): this {
insertMathCmd(nodeType)(this.state, this.dispatch);
return this;
}
const mathInline: NodeSpec = {
group: "inline math",
content: "text*", // important!
inline: true, // important!
atom: true, // important!
toDOM: () => ["math-inline", { class: "math-node" }, 0],
parseDOM: [{
tag: "math-inline" // important!
},// ...defaultInlineMathParseRules
]
};
const mathDisplay: NodeSpec = {
group: "block math",
content: "text*", // important!
atom: true, // important!
code: true, // important!
toDOM: () => ["math-display", { class: "math-node" }, 0],
parseDOM: [{
tag: "math-display" // important!
}, //...defaultBlockMathParseRules
]
};
const nodes = {
doc,
text,
paragraph,
blockquote,
horizontal_rule: horizontalRule,
heading,
hard_break: hardBreak,
code_block: codeBlock,
image,
list_item: listItem,
ordered_list: orderedList,
bullet_list: bulletList,
math_inline: mathInline,
math_display: mathDisplay
};