Skip to content
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

Add TeX to MathML conversion via ritex #169

Closed
wants to merge 1 commit into from
Closed

Add TeX to MathML conversion via ritex #169

wants to merge 1 commit into from

Conversation

@tmthrgd
Copy link
Contributor

@tmthrgd tmthrgd commented Sep 29, 2014

This allows math environments to be output as MathML instead of MathJax script tags when using the Html converter. This allows browsers to natively display mathematics without the need for any javascript library (MathJax).

It has been provided conditionally similarly to coderay, with a enable_ritex option that defaults to false. It supports both inline and block math.

It relies on the ritex package ([sudo] gem install ritex). I have done my best to keep to the syntax as I could determine it and have not made any changes to the tests or manuals/docs which might be necessary to accept this pull request.

TeX such as $$f(x) = a{x^3} + b{x^2} + cx + d$$ (a cubic function) would be rendered as:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mi>a</mi><mrow><msup><mi>x</mi><mn>3</mn></msup></mrow><mo>+</mo><mi>b</mi><mrow><msup><mi>x</mi><mn>2</mn></msup></mrow><mo>+</mo><mi>c</mi><mi>x</mi><mo>+</mo><mi>d</mi></math>

which renders as f(x)=ax3+bx2+cx+d

@tmthrgd tmthrgd changed the title Add TeX -> MathML conversion via ritex Add TeX to MathML conversion via ritex Sep 29, 2014
@gettalong
Copy link
Owner

@gettalong gettalong commented Oct 1, 2014

Thanks for this pull request!

I have looked at the ritex gem and it doesn't seem to be actively developed anymore. Is it more or less feature complete and are therefore no updates anymore?

Nonetheless, there are still some things that would need to be done:

  • The new option has to be defined in lib/kramdown/options.rb.
  • What does the {:display => block} part do? Can the output of Ritex be nicely formatted?
  • Simple test cases are missing. Add them in test/testcases/block/15_math/ and test/testcases/span/math/ and use a .options file to set the new option. You may need to disable these tests in some cases, e.g. in the GFM tests. This can be done in test/test_files.rb.
  • Add the new gem dependency as development dependency to the gemspec in Rakefile
  • Add documentation for the option to doc/converter/html.page in the "Math Support" section and include the option at the end of the file in the webgen options tag.
@tmthrgd
Copy link
Contributor Author

@tmthrgd tmthrgd commented Oct 2, 2014

The :display option for the parser is representative of whether the math is inline or block (not the clearest option name).

Ritex indeed seems seldom updated now but it has the benefit of being pure ruby. There is another parser, ietex2mml, that is actively developed that I discovered since submitting this request. My concern with this parser is that it relies on a native binary, this may or may not be acceptable to you.

I'll add the options, tests and docs or I'm happy to rewrite it to use ietex2mml. It could even be written to use either ietex2mml or ritex, either as a fallback or another option.

@tmthrgd
Copy link
Contributor Author

@tmthrgd tmthrgd commented Oct 2, 2014

In terms of nicer formatted html, neither ritex nor ietex2mml support that. If it is essential the best I could suggest would be to pass the output through a HTML parser (probably the kramdown HTML parser) and then output the HTML nodes.

@gettalong
Copy link
Owner

@gettalong gettalong commented Oct 2, 2014

Thanks for the clarifications! The nicer formatting is not necessary, I just wanted to know if this would be possible.

I would prefer a pure Ruby solution to one that depends on a binary. However, if you want to implement both solution it would be fine with me. I had a short look at itextomml and it seems it doesn't actually depend on a binary but is just using the code that is also used in the binary. So if the gem is available on the platform, it should also just work.

Additionally, it would possibly make sense to introduce a general option like math_engine that defaults to 'mathjax' and can optionally be set to 'ritex' (or 'ietex2mml') - what do you think?

@tmthrgd
Copy link
Contributor Author

@tmthrgd tmthrgd commented Oct 2, 2014

I'll admit my Ruby knowledge is very fresh and I couldn't quite work out how itextomml worked. So it may well be 'binary free', I was simply working off the description on the website.

I personally love the idea of a generic math_engine option as you described it. My only concern (if you can call it that) is consistency. Should code blocks also have a similar setup, that might allow pygments or other highlighters?

I'd suggest closing this pull request and spiking it off into an issue until a decision is reached. Which I'll happily do when it's not 5:21am...

@tmthrgd
Copy link
Contributor Author

@tmthrgd tmthrgd commented Oct 2, 2014

Oh hell it's only 5:21am!

@gettalong
Copy link
Owner

@gettalong gettalong commented Oct 3, 2014

Thanks for all your input! As for code blocks and syntax highlighting this is already on my TODO list.

@gettalong gettalong self-assigned this Oct 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants