New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leave math alone entirely #342

Closed
sampsyo opened this Issue May 28, 2016 · 13 comments

Comments

Projects
None yet
3 participants
@sampsyo

sampsyo commented May 28, 2016

When math_engine is disabled, it appears that Kramdown wraps display math (like $$this$$) in <pre> blocks:

$ kramdown --version
1.11.1
$ echo '$$x$$' | kramdown
<script type="math/tex; mode=display">x</script>
$ echo '$$x$$' | kramdown --math-engine nil
<pre>$$
x
$$</pre>

This is quite surprising—I imagined that this option would disable the feature entirely, letting me keep my $$s exactly as they were in the source. Is there any option to turn off this extension entirely?

This happens in the convert_math method in the HTML converter. The format_math call returns nil when this is disabled, so the if falls through to the second arm, which wraps the value in a <pre> block.

sampsyo added a commit to sampsyo/home that referenced this issue May 28, 2016

Turn off Kramdown's math engine
This doesn't quite work, because of:
gettalong/kramdown#342

@gettalong gettalong self-assigned this May 28, 2016

@gettalong

This comment has been minimized.

Owner

gettalong commented May 28, 2016

You are probably right. I have looked through the previous version of the conversion function and it didn't use <pre> or <span> there. So if the math_engine is turned off, it really should just output the input string.

Thanks for letting me know!

@gettalong gettalong added the bug label Aug 6, 2016

@gettalong

This comment has been minimized.

Owner

gettalong commented Aug 6, 2016

@sampsyo So, looking at the code and the previous versions in more detail, it seems the best way to go forward when no math engine is selected, is to output LaTeX style inline/block delimiters, i.e. $ for inline and $$ for block, wrapped in <div> and <span>.

The <div> and <span> tags won't do anything to the styled output but allows us to preserve possibly set attributes and to assign class="kdmath" to allow for easy selection via CSS or Javascript.

So this input:

Some $$inline=math$$ is here

$$
And some
block math here
$$

would yield the following output:

<p>Some <span class="kdmath">$inline=math$</span> is here</p>

<div class="kdmath">$$
And some
block math here
$$</div>

Would that satisfy your needs?

@sampsyo

This comment has been minimized.

sampsyo commented Aug 6, 2016

Absolutely! Thanks for looking into it.

@gettalong

This comment has been minimized.

Owner

gettalong commented Aug 6, 2016

Okay, then I will do that.

@gettalong

This comment has been minimized.

Owner

gettalong commented Aug 7, 2016

Will be in the next version.

@gettalong gettalong closed this Aug 7, 2016

gettalong added a commit that referenced this issue Aug 7, 2016

Fixed HTML output for math elements when no math engine is set
The output used a <pre> tag which was not really appropriate. Now it
uses <div> and <span> tags and also assigns the special class name
'kdmath' to make selecting the math elements easy.

Fixes #342
@sampsyo

This comment has been minimized.

sampsyo commented Aug 7, 2016

Woohoo! Thank you!

@dato dato referenced this issue Nov 2, 2016

Closed

Support for KaTeX #292

@AvverbioPronome

This comment has been minimized.

AvverbioPronome commented Nov 9, 2017

@gettalong, having the same syntax for inline and display math conflicts with usual math-writing use, where display math is usually inside paragraphs (text after starts in lowercase and all), and there is no way to do that with kramdown second guessing the writer's intentions. Please consider a math_engine that truly ignores everything between single and double dollars (dollars included), leaving all the config to a MathJax config block.

@gettalong

This comment has been minimized.

Owner

gettalong commented Nov 9, 2017

@9peppe Sorry, I don't understand your statement. Could you please be more specific to what kramdown should do? Best would be to include sample input, current output and preferred output.

You can already disable the math_engine by setting it to null. Then the output just consists of <div> plus $$ for block math elements and <span> plus $ for inline math elements.

@AvverbioPronome

This comment has been minimized.

AvverbioPronome commented Nov 9, 2017

@gettalong Well, if I do that, single dollars get rightly ignored. But double dollars do not.

Inputs like

This is a paragraph $$with a display equation inside\text{.}$$

and

This is a paragraph.

$$followed by display math in another paragraph\text{.}$$

Give outputs like:

<p>This is a paragraph <span class="kdmath">$with a display equation inside\text{.}$</span></p>

and

<p>This is a paragraph.</p>

<div class="kdmath">$$followed by display math in another paragraph\text{.}$$</div>

I have no problems with the second example, but in the first my equation becomes an inline equation, when I expected it to be a display math piece inside <p>, or at least a raw source piece with both dollars left alone. Like:

<p>This is a paragraph $$with a display equation inside\text{.}$$</p> 

The main problem is that while I can use single and double dollars to let MathJax decide what to do, kramdown converts all double-dollar display math inside paragraphs to single-dollar inline math, even with math_engine set to null or nil.

@gettalong

This comment has been minimized.

Owner

gettalong commented Nov 9, 2017

kramdown distinguishes between inline and block elements. Block elements like math blocks cannot be used as inline elements. This means that inside a paragraph math elements are treated as inline math and otherwise as block elements.

So what you want is not directly possible with kramdown. However, you can tell kramdown to ignore dollar signs by escaping them. Then it will not treat the dollar signs as the start of a math element.

@AvverbioPronome

This comment has been minimized.

AvverbioPronome commented Nov 9, 2017

Uhm, display math isn't really a block element according to MathJax people, and is traditionally used inside paragraphs.

Escaping dollar signs kinda works, but I am worried the underscores in the equation contents might end up interpreted as emphasis, and other conflicts like that (and every authoring tool not expecting escaped dollars to mean anything). Isn't there a way to tell kramdown to treat dollars, double dollars, and everything in between like raw text?

@gettalong

This comment has been minimized.

Owner

gettalong commented Nov 9, 2017

Please remember that we are talking about kramdown, not MathJax here. In kramdown there is a difference between block and span elements. And therefore there are two different forms of math elements, one block math element and one span math element. And only the span math element may be used inside a paragraph. This has nothing to do with how MathJax sees things.

You can use the nomarkdown extension to tell kramdown to not parse part of the source as kramdown source but raw text.

Modifying the parsing behaviour of kramdown is not possible and will not be implemented. If you want to change how kramdown parses things, you can easily subclass the parser and modify it. See the GFM or Markdown parser implementations for that.

@AvverbioPronome

This comment has been minimized.

AvverbioPronome commented Nov 10, 2017

Ok. I found a solution that might work for me. I'll use the second group of delimiters:

<script type="text/x-mathjax-config">
   MathJax.Hub.Config({
       tex2jax: {
           inlineMath: [ ['$','$'], ['\\(', '\\)'] ],
           displayMath: [ ['$$','$$'], ['\\[', '\\]'] ],
           processEscapes: true
       }
   });
</script>

@dometto dometto referenced this issue Oct 3, 2018

Merged

Update kramdown #1325

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment