vsch / idea-multimarkdown

Markdown language support for IntelliJ IDEA.
https://plugins.jetbrains.com/plugin/7896-markdown-navigator
Apache License 2.0
813 stars 129 forks source link

Markdown math #826

Closed jsinkers closed 4 years ago

jsinkers commented 4 years ago

Markdown navigator enhanced 3.0 Win 10

Is there any support in markdown navigator for $$ $$ syntax for math representation in preview? A couple of other issues mention using this syntax but I cannot get it to work. I have enabled Katex script in Settings>Markdown>Stylesheet, and I can see it works with $` `$ syntax when I enable Gitlab Katex, but ideally I would be able to use $$ $$ because this works for Jekyll and pandoc conversions.

Inspecting the browser HTML, the katex js and css are present. I have also tried manually inserting katex js + css into the head, but no luck so far.

Would appreciate guidance on 1) whether I can use the $$ $$ syntax, and 2) if so, what settings should make it work correctly Cheers!

vsch commented 4 years ago

@jsinkers, this option would have to be added to the markdown parser. Right now there is no easy way to make it work.

I did some tests and it can be done for MathJax which does its own parsing of the HTML document so it does convert $$ $$ to math rendering.

This can be done by adding MathJax JS to the HTML Generation settings. In the example below I have a custom rendering profile defined for it so it does not affect all files but you can also add the same config setting to main profile in Languages & Frameworks | Markdown | HTML Generation:

image

The added text is:

<script type="text/x-mathjax-config">
        MathJax.Hub.Config({
           tex2jax: {
              inlineMath: [['$','$'], ['\\(','\\)']],
            },
        });
</script>
<script type="text/javascript" async
        src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_HTMLorMML">
</script>

The test markdown:

When $a \ne 0$, there are two solutions to \\(ax\^2 + bx + c = 0\\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}$$

$${\bf e}(\varphi) = \begin{pmatrix} \cos\varphi\\\\\sin\varphi \end{pmatrix}$$

$$\begin{matrix}
f & = & 2 + x + 3 \\
& = & 5 + x \\
\end{matrix}$$

$$\hat{x}\ \vec{x}\ \ddot{x}$$

Renders as:

image
vsch commented 4 years ago

@jsinkers, I played around with updated MathJax 3.x script to get inline $ working and auto-equation numbering. MathJax 3 Docs, specifically Configuring MathJax

Need both Head Top script and Body Bottom to allow configuration parameters:

image

Head Top Text

<script type="text/x-mathjax-config">
  MathJax.Config({
     loader: {load: ['[tex]/enclose']},
     tex: {
        packages: ['base'],        // extensions to use
        processEscapes: true,      // use \$ to produce a literal dollar sign
        processEnvironments: true, // process \begin{xxx}...\end{xxx} outside math mode
      },
      svg: {
        fontCache: 'global'
      }
  });
</script>
<script type="text/javascript" id="MathJax-script" async
        src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>

Body Bottom Text

<script>
  window.MathJax = {
    tex: {
       inlineMath: [['\\(','\\)'], ['$','$'], ],
       displayMath: [['$$', '$$'], ['\\[','\\]']],
       tags: 'all',
       tagSide: 'right',
    }
  };
  MathJax.typeset()
</script>

Same markdown as above renders as:

image
vsch commented 4 years ago

@jsinkers, the Body Bottom text should probably be Body Top. Both work, but if/when I add MathJax in page math rendering option, then MathJax.typeset() will automatically be added before Body Bottom and user configuration will not be used.

jsinkers commented 4 years ago

Great. That does the trick. Thanks for your help!