Image-Py / imagepy

Image process framework based on plugin like imagej, it is esay to glue with scipy.ndimage, scikit-image, opencv, simpleitk, mayavi...and any libraries based on numpy

Home Page:http://imagepy.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support maths in markdown

CsatiZoltan opened this issue · comments

ImagePy uses Python-Markdown, which can be extended for maths support using several extensions. I myself tried this one. To enable, you need to append the exts list with 'mdx_math' in the imagepy/ui/mkdownwindow.py file. For instance, markdown("$$x^2$$", extensions=['mdx_math']) results in the HTML code '<p>\n<script type="math/tex; mode=display">x^2</script>\n</p>'. This trick alone is not enough in ImagePy, the documentation writes that some additional steps are needed. Could you implement this? It would be very useful for displaying formulas in help texts.

hi, I try the code, and got the '

\n<script type="math/tex; mode=display">x^2</script>\n

'

but I am not aware of web, can you show me how to config the js? I got a blank page with the code below:

<html lang="zh-cn">
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
</head>

<body>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js"></script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      config: ["MMLorHTML.js"],
      jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
      extensions: ["MathMenu.js", "MathZoom.js"]
    });
</script>

<p>
    <script type="math/tex; mode=display">x^2</script>
</p>

</body>
</html>

@yxdragon It's a blank page for me too. There is a related issue. I wrote there and I am waiting for the response...

@CsatiZoltan It is OK, swap the order of two script

<html lang="zh-cn">
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
</head>

<body>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      config: ["MMLorHTML.js"],
      jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
      extensions: ["MathMenu.js", "MathZoom.js"]
    });
</script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js"></script>

</body>

<p>
    <script type="math/tex; mode=display">x^2</script>
</p>

</html>

I will try to integrate in imagepy

Based on the author's comment, here is the modified MWE:

<html lang="en">

<head>

<meta content="text/html; charset=utf-8" http-equiv="content-type" />

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      config: ["MMLorHTML.js"],
      jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
      extensions: ["MathMenu.js", "MathZoom.js"]
    });
</script>

<script type="text/javascript" 

src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js"></script>

</head>

<p>
    <script type="math/tex; mode=display">x_2^2</script>
</p>

</html>

@CsatiZoltan Now it is OK, have a try. But the js is online, So if you want to render math, you need be online.

I have two ideas in mind: if the user is offline,

  1. do not render the math
  2. render using the offline version of MathJax (see here; the latest version is 33 MB). It could be bundled with ImagePy if its license is compatible with Apache 2.0.

now if offline only do not render math, others is ok.

about using offline mathjax, it could be a plugin like IBook, because it is large, and not necessary.

I agree.