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

Enable preview in MathJax converter #225

Closed
jethrogb opened this Issue Feb 23, 2015 · 11 comments

Comments

Projects
None yet
2 participants
@jethrogb

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

@gettalong gettalong self-assigned this Feb 23, 2015

@gettalong gettalong added the question label Feb 23, 2015

@gettalong

This comment has been minimized.

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.

@gettalong gettalong closed this Feb 23, 2015

@jethrogb

This comment has been minimized.

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.

@gettalong

This comment has been minimized.

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

This comment has been minimized.

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.

@gettalong

This comment has been minimized.

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 <script> tags, with the HTML converter and itex2mml/ritex, it is transformed to MathML, with the LaTeX converter it is left untouched.

@jethrogb

This comment has been minimized.

jethrogb commented Feb 24, 2015

"With the HTML converter and MathJax, it is wrapped in <script> tags" ← this is called a jax. See also http://docs.mathjax.org/en/latest/model.html . Hence, kramdown is converting TeX to jax, so you would not normally use tex2jax again (not sure if this is even possible).

Now that we both understand how this works, I would like to propose, again, that the kramdown TeX to jax converter be as featureful as (or at least close to) tex2jax.

@gettalong

This comment has been minimized.

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

This comment has been minimized.

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:

<span class="MathJax_Preview">\sqrt{a}=2</span><script type="math/tex">\sqrt{a}=2</script>

Displaymath example:

<div class="MathJax_Preview"> (\frac{4}{5^C-\alpha_\equiv}=10)^3 </div>
<script type="math/tex; mode=display"> (\frac{4}{5^C-\alpha_\equiv}=10)^3 </script>
@gettalong

This comment has been minimized.

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.

@gettalong gettalong reopened this Feb 24, 2015

@gettalong gettalong closed this in 567d213 Feb 24, 2015

@gettalong

This comment has been minimized.

Owner

gettalong commented Feb 24, 2015

This is implemented now!

@jethrogb

This comment has been minimized.

jethrogb commented Feb 24, 2015

Awesome, thanks

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