Insert inline LateX within Slate
See original GitHub issueI am trying to insert an inline LateX formula and am having some difficulties getting the equation rendered properly. To do this, I have created the following data model and fed it to the editor component. The extra blub is marked by latex
, whose text
attribute is set to \\lambda
.
{
"document": {
"nodes": [
{
"object": "block",
"type": "paragraph",
"nodes": [
{
"object": "text",
"leaves": [
{
"text": "This is editable "
},
{
"text": "rich",
"marks": [
{
"type": "bold"
}
]
},
{
"text": " \\lambda ",
"marks": [
{
"type": "latex"
}
]
},
{
"text": " text, "
},
{
"text": "much",
"marks": [
{
"type": "italic"
}
]
},
{
"text": " better than a "
},
{
"text": "<textarea>",
"marks": [
{
"type": "code"
}
]
},
{
"text": "!"
}
]
}
]
}
}
}
Following is the method where I analyze the node types:
_renderMark = props => {
const { children, mark, attributes } = props;
switch (mark.type) {
case "bold":
return <strong {...attributes}>{children}</strong>;
case "code":
return <code {...attributes}>{children}</code>;
case "italic":
return <em {...attributes}>{children}</em>;
case "underlined":
return <u {...attributes}>{children}</u>;
case "latex":
return <InlineMath {...attributes} math={children}/>;
}
};
Following is the method that renders the editor:
_renderEditor = () => {
return (
<div className="editor">
<Editor placeholder="Enter some rich text..."
value={this.props.value}
onChange={this._onChange}
onKeyDown={this._onKeyDown}
renderNode={this._renderNode}
renderMark={this._renderMark}
spellCheck
autoFocus/>
</div>
);
};
As it can be seen in the following image, the letter lambda
is both rendered as \lambda
and λ
, the latter of which is the expected behavior. Can someone please advise what I might be doing wrong?
Note: InlineMath
comes from react-katex
.
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Adding inline blocks(math equation) in slate js - Stack Overflow
User writes text in slate editor; Then to insert equation user writes eqation in maths editor and click on insert equation.
Read more >How to display inline LaTeX code inside a LaTeX document?
I usually combine it with fancyvrb which makes inline code simple to write also. Here's just one possible setup, which I use in...
Read more >How to use the slate.Inline.create function in slate - Snyk
To help you get started, we've selected a few slate. ... insertInline(inline) // Normalize the keys in the block nodes to match what...
Read more >Building a rich text editor in React with SlateJS - Kitemaker
Building an awesome editor for your React-based web application is by no means easy. But with SlateJS things get much easier.
Read more >Inline - Slate
A inline node in a Slate Document . Inline nodes implement the Node interface.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Anaizing it’s https://slate-js.slack.com/
Hey, thanks for using Slate! Unfortunately, we can’t offer support for usage questions in the issues here because it becomes overwhelming to maintain the project if the issues are filled with questions.
However, we do have a Slack channel and people are constantly asking and answering questions in there. So I’m going to close this issue, but I definitely recommend joining the Slack channel if you want to find people that might be able to help.
Thanks for understanding!