markdig icon indicating copy to clipboard operation
markdig copied to clipboard

Distinguish block math from inline math

Open BOT-Man-JL opened this issue 7 years ago • 8 comments

Current version of markdig renders both $...$ pair and $$...$$ pair into <span class="math">...</span> uniformly. But many math engines treat them differently...

For example, MathJax support this:

image

😉 It will be very helpful for LaTeX guys...

BOT-Man-JL avatar Aug 13 '17 03:08 BOT-Man-JL

Inline math: $y=e_i^x$

Block math: $$y=e_i^x$$

will be rendered into

<p id="pragma-line-4">Inline math: <span class="math">y=e_i^x</span></p>
<p id="pragma-line-6">Block math: <span class="math">y=e_i^x</span></p>

BOT-Man-JL avatar Aug 13 '17 03:08 BOT-Man-JL

Inline math: $y=e_i^x$ support

Block math:

$$
y=e_i^x
$$

support

works...

<p id="pragma-line-6">Inline math: <span class="math">y=e_i^x</span> support</p>
<p id="pragma-line-8">Block math:</p>
<div id="pragma-line-10" class="math">y=e_i^x
</div>
image

BOT-Man-JL avatar Aug 13 '17 04:08 BOT-Man-JL

Yes, this is the expected behavior of the current code as explained in the Mathematics extension

  • $ and $$ can be used for inline/span maths inside the same line (but $$ cannot start a line)
  • $$ can be used as a block if it is declared alone on a line (like fenced code blocks)

xoofx avatar Aug 13 '17 12:08 xoofx

The current specs is a bit different from what I usually use...

And MathJax and KaTeX (with auto renderer) support $$ block in the same line... 😕

image

Here is a guideline of MathJax on StackExchange: https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference

image

BOT-Man-JL avatar Aug 14 '17 02:08 BOT-Man-JL

Oh, then it makes sense to make $$ always a block, no problem, will fix that...

xoofx avatar Aug 14 '17 11:08 xoofx

Oh, thanks 😄 It would be convenient to type short equations inside $$

BOT-Man-JL avatar Aug 15 '17 06:08 BOT-Man-JL

I have a remaining issue with this approach though. A $$ inside a paragraph should not generate a <div> as a paragraph is already a <p> and this is a HTML error to have a div inside a p element. We could emit a span with a class math and an additional block to mark that this span content should be display as a block instead (display: block;)

xoofx avatar Aug 30 '17 09:08 xoofx

Well, KaTeX adds class katex-display and MathJax adds MJXc-display to span tag if there is an block math code... So I think an additional class works. (math engine always reads the class name in CSS...)

display: block is another good solution, which will have effect directly in plain HTML. 😄

BOT-Man-JL avatar Aug 30 '17 12:08 BOT-Man-JL