mathjax / MathJax

Beautiful and accessible math in all browsers
http://www.mathjax.org/
Apache License 2.0
10.25k stars 1.16k forks source link

Extension for siunitx #447

Open Manishearth opened 11 years ago

Manishearth commented 11 years ago

siunitx is a package that is rather common in physics papers. Could this be added?

(It was proposed here, making it into a formal feature request)

pkra commented 11 years ago

Just some general remarks. I'm not familiar with this extension, but from a quick glance (at the 98 page manual...), there doesn't seem anything fundamentally difficult about it, e.g. no picture environments (well, ignoring the Text-macros anyway).

So if I didn't miss anything, the answer is "yes, it could", but it's not in our backlog (well, ok it is now).

Instead of waiting for our backlog to clear, we would be very happy to help somebody else write an extension. At least for the basic set of siunitx commands, this shouldn't be too hard (except for a very good knowledge of the sinuitx).

burnpanck commented 10 years ago

I have started to give such an extension a try, available in my fork. However, except for being eager to learn, I am in a particularly bad position to do this, as I:

Therefore, I'll probably need your input on various fronts. So far I have very basic parsing of the two commands \si and \SI. Now, here are my first two questions:

davidcarlisle commented 10 years ago

On 14 September 2014 15:23, Yves Delley notifications@github.com wrote:

  • What is the proper element in MathML/Jax to describe a unit?

mi mostly, we (Math WG) have a note on this subject:

http://www.w3.org/TR/mathml-units/

burnpanck commented 10 years ago

Thanks for the pointer!

pkra commented 10 years ago

@burnpanck first off: thanks for getting involved -- awesome! I think your self-description sounds very good actually -- perfect mix of "no baggage" ;-), so to speak.

For your first question, I would suggest to make use of the MathJax third party extension repository. That way, you can pack whichever way you like (we use our dev-tools but we have no preference) and you can push this along in the current state while having it on the MathJax CDN for a wider audience. (I would also post to relevant user group postings to recruit testers).

pkra commented 10 years ago

There might also be users on physics.SE that are willing to help -- to repeat the link from the OP: http://meta.physics.stackexchange.com/questions/4220/siunitx-latex-package

davidcarlisle commented 10 years ago

On 15 September 2014 21:00, Peter Krautzberger notifications@github.com wrote:

There might also be users on physics.SE that are willing to help -- to repeat the link from the OP: http://meta.physics.stackexchange.com/questions/4220/siunitx-latex-package

— Reply to this email directly or view it on GitHub https://github.com/mathjax/MathJax/issues/447#issuecomment-55649254.

Joseph (siunitx's author) just made a blog post where MathJax gets a mention....

http://www.texdev.net/2014/09/18/reworking-and-exposing-siunitx-internals/

burnpanck commented 10 years ago

Which might be very well be due to the fact that I told him by eMail about my endeavour, while asking about some internals of the package :-)

burnpanck commented 10 years ago

@pkra: I have now switched over to the third-party extension repo. However, now testing just got harder: Is there an easy way to load MathJax from a standard location, but tell it to look for third-party extensions somewhere else?

pkra commented 10 years ago

@burnpanck

Which might be very well be due to the fact that I told him by eMail about my endeavour, while asking about some internals of the package :-)

awesome!

Is there an easy way to load MathJax from a standard location, but tell it to look for third-party extensions somewhere else?

Yes, there is -- see http://docs.mathjax.org/en/latest/options/ThirdParty.html

burnpanck commented 9 years ago

Development on my siunitx plugin has stalled. Just wanted to post a link to the current status: https://github.com/burnpanck/MathJax-third-party-extensions/tree/add-siunitx-tex-extension Somehow, I never posted that link after I switched to MathJax-third-party-extensions.

I should add that it provides usable visible output for almost all test-cases found in the siunitx documentation. What currently still doesn't work correctly is

Furthermore, I am not sure if the generated MathML is semantically correct.

If you want to judge for yourself, go to http://rawgit.com/burnpanck/MathJax-third-party-extensions/add-siunitx-tex-extension/siunitx/sample-siunitx.html

pkra commented 9 years ago

Thanks, @burnpanck, for your work on this!

If it isn't broken (just incomplete), it would be perfectly ok from our point of view to merge your work into the third party extension repo.

Do you have any suggestions for those who want to contribute to your work?

burnpanck commented 9 years ago

My procedure used to be to look at the examples and fix features on a one-by-one basis. There are still a few broken (i.e. wrong output) cases, those should at least be made to fail with an error message instead. Also, error handling might not be user friendly in that it results in JS exceptions.

Since this is a relatively complex extension, I'd say a nice step forward would be the incorporation of an automated test procedure, e.g. MathJax-test. In particular since there are many options and corner cases that can easily be overlooked.

Finally, it would be good to inspect the generated MathML for typographical and semantical correctness.

burnpanck commented 9 years ago

Actually, today I was in dire need of some procrastination, so I fixed the lists, angles and literal unit input. With this, there is no feature left known to be broken. However, the generated output still does not look optimal. Indeed, I would appreciate help there. I have no idea how MathJax's MML classes work nor do I know MathML well and am just attempting trial and error. Particularly, spacing is not correct and differs between HTML-CSS and MathML output in my Firefox.

pkra commented 9 years ago

@burnpanck yay for procrastination :-) Maybe we should get together for a chat some time? Your code looks really interesting and we'd love to get a better understanding where things stand and how we might help. If you're interested, please ping me at peter.krautzberger@mathjax.org.

hpvd commented 9 years ago

+1, having units in mathjax is a must!!! @burnpanck many thanks for your work! Having perfect looking units at all there numbers with always the perfect space between number and unit but never a linebreak is one of the reasons engineers use latex! And engineers would adore to have this on their websites too :-)

pkra commented 9 years ago

@hpvd I believe @burnpanck is looking for helpers. If we can help with questions about the inner workings of MathJax's TeX input or anything else, do let us know.

RafiKueng commented 9 years ago

Just as a note: I'm using @burnpanck 's extension with my private dokuwiki instance and the mathjax plugin. I quickly described my setup in the faq on that page (bottom). I hope thats ok for everyone (esp. @burnpanck) that I put direct links to files?

It works fine for me so far (using \SI, \si, \num). All I'm missing is \sisetup to work to tweak output; I'd hack it in if I had time but until now I can live with this flaw.. I might encounter bugs and fix them, or hack in new features eventually. If that happens, I'll report back here.

hpvd commented 9 years ago

@RafiKueng many thanks for detailed description!

pkra commented 9 years ago

@burnpanck any objections if I create a PR from your repository to the third party repo? Then it gets put on our CDN and people have an easier time using/testing it.

burnpanck commented 9 years ago

No objections, please go ahead! I know, during our video-chat some time ago, I agreed to address a few more of the remaining issues, unfortunately, I will have very little time until end of winter. But I'm happy to see that it's useful to some people even in it's current state!

pkra commented 9 years ago

No objections, please go ahead!

Great! I did an initial PR. I'm wondering if it's ok to drop the test folder for the third party repo -- testing should probably happen on your own end for now? If that's ok then I'll clean up the PR a bit.

address a few more of the remaining issues, unfortunately, I will have very little time until end of winter

No worries at all -- it's fantastic what you've done so far.

Do you have a todo list somewhere? It would probably be helpful for potential contributors to have a list of easy (or hard) work items. I'll see if I can dig up my notes from our chat as well.

pkra commented 9 years ago

I've pushed a copy of @burnpanck's extension to the third party repo and the CDN. See http://codepen.io/pkra/pen/meLxzW for a live demo.

hpvd commented 9 years ago

This demo is awesome - even complicate things like $$\SI[per-mode=symbol]{123,44e-3}{\kilogram\metre\per\ampere\per\second}$$ are working fine!!

One relatively important thing which seem not to work at the moment is the switching of the decimal maker to "," (comma) from siunitx docu page 28 the code for this should be \num[output-decimal-marker = {,}]{1.23} the demo shows still "." (dot)

how should one handle findings like that? / where to report?

pkra commented 9 years ago

how should one handle findings like that? / where to report?

Well, it's @burnpanck 's code. Maybe https://github.com/burnpanck/MathJax-third-party-extensions/ (which is where I just directed a PR).

We (the MathJax team) are happy to help and advise but third party extensions are just that, third party code, so we can't dedicate too many resources to them.

hpvd commented 9 years ago

possibility to open issuses seems to be disabled on this place. Maybe we still wait on @burnpanck's comment...

burnpanck commented 9 years ago

You guys are quick! Issues are now enabled - feel free to add whatever you deem important. Even if I don't immediately find time to address them, it's certainly a good place to collect the issues.

@pkra: There is the file siunitx/ImplementationDetails.md, which contains a short list indicating areas where improvements could be made. I wrote that list just prior to our chat.

hpvd commented 9 years ago

@burnpanck Thanks for getting back and enabling issues. Just opened the first one ;-)

hpvd commented 9 years ago

@pkra just one general question: is there something like an automatic that the demo uses always the latest code? => so is this the right place for testing?

pkra commented 9 years ago

@pkra just one general question: is there something like an automatic that the demo uses always the latest code?

That would have to be set up separately (and is a little tricky, actually). The simplest way is to copy&paste the extension's code directly into a codepen or jsbin page, e.g., http://codepen.io/pkra/pen/OyZqqx. You can fork that and hack around to your delight, update as you want.

burnpanck commented 9 years ago

Never used codepen, but can't you just use a normal MathJax setup and do MathJax.Ajax.config.path['Contrib'] = 'http://rawgit.com/burnpanck/MathJax-third-party-extensions/add-siunitx-tex-extension'? Note, there is a (non-interactive) reference rendering of siunitx's documentation using rawgit. There is also an interactive test page. The rawgit links always point to the head of the branch add-siunitx-tex-extension.

pkra commented 9 years ago

can't you just use a normal MathJax setup

Sure. I was thinking of a live demo to hack the code with.

I've udpated http://codepen.io/pkra/pen/meLxzW to use your repo via rawgit.

eMPee584 commented 7 years ago

Is this still being worked on? .. just ran into this (on cocalc.com), resorted to using

%md
$n_{out} = 60\mathrm{~min^{-1}}$
pkra commented 7 years ago

Is this still being worked on?

There is a third party extension for siunitx and it's repository is at https://github.com/burnpanck/MathJax-siunitx.

sixtyfive commented 4 years ago

https://rawgit.com/burnpanck/MathJax-siunitx/master/examples/siunitx.dtx.html

So basically it's dead now. Sad. Any chance of reviving it?

mhchem commented 4 years ago

While this is by no means a replacement for siunitx, users just wanting to type simple units in MathJax could have a look at mhchem's \pu command. \pu{\pu{123 kJ*mol-1}} manual, scroll down all the way. (This command has been in use on StackExchange for several years. So, I hope you see this as a friendly pointer and not as shameless advertisement.)

piiskop commented 2 years ago

i need something that works without any modification for both HTML and LaTeX. pu doesn't seem to replace unit. siunitx has a lot of automation built in. Tonight, i discovered that my equations that worked just fine for PDF output didn't work for HTML output and started to investigate whether it's as easy as just telling MathJax to use whatever LaTeX package and it just takes it and converts and works with it. Seemingly for every LaTeX package, a separate MathJax conversion must be written manually which is a lot of work. Couldn't the process be automated?

dpvc commented 2 years ago

@piiskop

Couldn't the process be automated?

Not very easily. MathJax does not work like true TeX under the hood, and doesn't implement most of the low-level control sequences that are needed for the operation of most TeX packages. While MathJax tries to provide the top-level macros, its internal plumbing is so different from that of actual TeX that an automated conversion of packages seems unlikely to be very effective.

On the other hand, there is a third-party group that is seeking a grant to implement siunitx for MathJax, and we are hopeful that they will be able to obtain it, so it may be that the package becomes available in MathJax in the future.

JeppeKlitgaard commented 2 years ago

@dpvc Do you know what the outcome of this grant-seeking was?

dpvc commented 2 years ago

The grant was not funded, I'm sorry to say.