markdig
markdig copied to clipboard
Distinguish block math from inline math
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:

😉 It will be very helpful for LaTeX guys...
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>
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>

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)
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... 😕
Here is a guideline of MathJax on StackExchange: https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference
Oh, then it makes sense to make $$
always a block, no problem, will fix that...
Oh, thanks 😄 It would be convenient to type short equations inside $$
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;
)
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. 😄