# Enable preview in MathJax converter #225

Closed
opened this Issue Feb 23, 2015 · 11 comments

Projects
None yet
2 participants

### jethrogb commented Feb 23, 2015

 The MathJax tex2jax converter inserts preview elements right before jaxes to display while MathJax is loading (or to noscript users). Do the same:  if type == :block converter.format_as_block_html('div', {:class=>'MathJax_Preview'}, converter.escape_html(el.value), opts[:indent])+converter.format_as_block_html('script', attr, text, opts[:indent]) else converter.format_as_span_html('span', {:class=>'MathJax_Preview'}, converter.escape_html(el.value))+converter.format_as_span_html('script', attr, text) end

Owner

### gettalong commented Feb 23, 2015

 If I read http://docs.mathjax.org/en/latest/options/tex2jax.html correctly, you can control this via the MathJax control file. So there is no need for kramdown to do the work of MathJax.

### jethrogb commented Feb 23, 2015

 That is an argument for removing the MathJax Math Engine from kramdown, not an argument against improving the current state.
Owner

### gettalong commented Feb 23, 2015

 I'm sorry, I don't think I get the last comment. kramdown doesn't ship with MathJax, it just outputs a syntax that is compatible with it. You have to install and configure MathJax yourself, i.e. you have to create a control file (or however that is called in the MathJax/Javascript world).

### jethrogb commented Feb 23, 2015

 If you use the tex2jax converter that comes with MathJax, you don't need kramdown to convert TeX to jax, which is what the kramdown MathJax math engine currently does. However, I would like to use kramdown to convert TeX to jax since I trust kramdown more to know about the context of things and the escaping of things that needn't be converted can be done at the source level instead of the HTML level. It would be nice though if the kramdown TeX to jax converter was as feature-complete as the MathJax tex2jax module, such as inserting previews.
Owner

### gettalong commented Feb 24, 2015

 kramdown doesn't convert LaTeX to anything itself, it relies on different math engines to do it. kramdown itself provides a syntax for specifying span-level and block-level math statements that should include LaTeX math code. Allowing kramdown to recognize math statements has the benefit that the LaTeX contents can be correctly formatted for the output medium. With the HTML converter and MathJax, it is wrapped in 

### jethrogb commented Feb 24, 2015

 "With the HTML converter and MathJax, it is wrapped in 
Owner

### gettalong commented Feb 24, 2015

 Okay, so how do this previews work? Your code example in the initial post seem to indicate that the LaTeX code gets output twice. Please provide an example of the expected output or show me a demo site.

### jethrogb commented Feb 24, 2015

 "Your code example in the initial post seem to indicate that the LaTeX code gets output twice" Correct. I assume MathJax looks for the first previous sibling with class="MathJax_Preview". Demo site: http://jbeekman.nl/newsite/blog/2013/06/adaptive-hybrid-solution/ (This is a test site, URL to disappear soon) Inline mode example: \sqrt{a}=2 Displaymath example: 
(\frac{4}{5^C-\alpha_\equiv}=10)^3

Owner

### gettalong commented Feb 24, 2015

 Thanks for the explanation and the demo site! What I can do for you is this: kramdown allows setting options for the used math engine. I will update the MathJax engine to recognize a new "preview" option that is "false" by default and may be set to "true" so that the previews are generated.

Owner

### gettalong commented Feb 24, 2015

 This is implemented now!

### jethrogb commented Feb 24, 2015

 Awesome, thanks

Closed