# Leave math alone entirely #342

Closed
opened this Issue May 28, 2016 · 13 comments

Projects
None yet
3 participants

### sampsyo commented May 28, 2016

 When math_engine is disabled, it appears that Kramdown wraps display math (like $$this$$) in 
blocks: $kramdown --version 1.11.1$ echo '$$x$$' | kramdown  $echo '$$x$$' | kramdown --math-engine nil $$x$$  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   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  4ca4527  ### gettalong self-assigned this May 28, 2016 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   or  there. So if the math_engine is turned off, it really should just output the input string. Thanks for letting me know! ### gettalong added the bug label Aug 6, 2016 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   and . The   and  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:  Some$inline=math$is here $$And some block math here$$  Would that satisfy your needs? ### sampsyo commented Aug 6, 2016  Absolutely! Thanks for looking into it. Owner ### gettalong commented Aug 6, 2016  Okay, then I will do that. Owner ### gettalong commented Aug 7, 2016  Will be in the next version. ### 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  cdf30d4  ### sampsyo commented Aug 7, 2016  Woohoo! Thank you! ### dato referenced this issue Nov 2, 2016 Closed #### Support for KaTeX #292 ### AvverbioPronome commented Nov 9, 2017 • edited  @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. 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   plus $$ for block math elements and  plus  for inline math elements. ### 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:  This is a paragraph with a display equation inside\text{.}  and  This is a paragraph.$$followed by display math in another paragraph\text{.}$$ 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  , or at least a raw source piece with both dollars left alone. Like:  This is a paragraph$$with a display equation inside\text{.}$\$

 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.
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 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?
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 commented Nov 10, 2017

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

Merged