MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

Extension for siunitx

Open Manishearth opened this issue 11 years ago • 38 comments

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)

Manishearth avatar Apr 23 '13 08:04 Manishearth

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).

pkra avatar Apr 23 '13 15:04 pkra

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:

  • Am just a casual JS coder
  • Do not know the internals of MathJax's at all
  • Do not know much about MathML
  • Am a casual user of siunitx
  • Do not know the internals of siunitx
  • Am somewhat proficient in LaTeX, but reading package internals is tough anyway

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:

  • How do I pack MathJax?
  • What is the proper element in MathML/Jax to describe a unit?

burnpanck avatar Sep 14 '14 14:09 burnpanck

On 14 September 2014 15:23, Yves Delley [email protected] 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/

davidcarlisle avatar Sep 14 '14 17:09 davidcarlisle

Thanks for the pointer!

burnpanck avatar Sep 15 '14 17:09 burnpanck

@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 avatar Sep 15 '14 19:09 pkra

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

pkra avatar Sep 15 '14 20:09 pkra

On 15 September 2014 21:00, Peter Krautzberger [email protected] 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/

davidcarlisle avatar Sep 18 '14 20:09 davidcarlisle

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 avatar Sep 18 '14 22:09 burnpanck

@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?

burnpanck avatar Sep 18 '14 22:09 burnpanck

@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

pkra avatar Sep 20 '14 12:09 pkra

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

  • lists of physical quantities (unit is not properly repeated)
  • rendering of angles
  • literal unit input is sometimes parsed incorrectly.
  • the \sisetup{...} command
  • maybe a few other small issues

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

burnpanck avatar Aug 10 '15 09:08 burnpanck

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?

pkra avatar Aug 10 '15 11:08 pkra

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 avatar Aug 10 '15 12:08 burnpanck

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.

burnpanck avatar Aug 10 '15 16:08 burnpanck

@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 [email protected].

pkra avatar Aug 10 '15 19:08 pkra

+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 :-)

hpvd avatar Oct 23 '15 14:10 hpvd

@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.

pkra avatar Oct 23 '15 19:10 pkra

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.

RafiKueng avatar Oct 27 '15 14:10 RafiKueng

@RafiKueng many thanks for detailed description!

hpvd avatar Oct 27 '15 15:10 hpvd

@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.

pkra avatar Oct 27 '15 16:10 pkra

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!

burnpanck avatar Oct 27 '15 16:10 burnpanck

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 avatar Oct 28 '15 08:10 pkra

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.

pkra avatar Oct 28 '15 16:10 pkra

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?

hpvd avatar Oct 28 '15 17:10 hpvd

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.

pkra avatar Oct 28 '15 17:10 pkra

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

hpvd avatar Oct 28 '15 18:10 hpvd

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.

burnpanck avatar Oct 29 '15 07:10 burnpanck

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

hpvd avatar Oct 29 '15 07:10 hpvd

@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?

hpvd avatar Oct 29 '15 07:10 hpvd

@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.

pkra avatar Oct 29 '15 08:10 pkra