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
http://imagepy.org
BSD 4-Clause "Original" or "Old" License
1.29k stars 330 forks source link

Support maths in markdown #78

Closed CsatiZoltan closed 4 years ago

CsatiZoltan commented 4 years ago

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.

yxdragon commented 4 years ago

hi, I try the code, and got the '

\n\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>
CsatiZoltan commented 4 years ago

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

yxdragon commented 4 years ago

@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

CsatiZoltan commented 4 years ago

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>
yxdragon commented 4 years ago

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

CsatiZoltan commented 4 years ago

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.
yxdragon commented 4 years ago

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.

CsatiZoltan commented 4 years ago

I agree.