question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Insert inline LateX within Slate

See original GitHub issue

I 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.

image

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
isubasticommented, Feb 13, 2019
1reaction
ianstormtaylorcommented, Jun 19, 2018

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found