Mathjax: Extension for siunitx

Created on 23 Apr 2013  Â·  36Comments  Â·  Source: mathjax/MathJax

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)

Feature Request

Most helpful comment

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

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

All 36 comments

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

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?

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/

Thanks for the pointer!

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

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

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/

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

@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

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

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

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?

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.

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

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

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
many thanks for detailed description!

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

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!

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.

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.

This demo is awesome - even complicate things like
$$\SI[per-mode=symbol]{123,44e-3}{\kilogram\metre\perampere\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?

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.

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

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 Thanks for getting back and enabling issues. Just opened the first one ;-)

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

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.

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.

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

%md
$n_{out} = 60\mathrm{~min^{-1}}$

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.

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

memakura picture memakura  Â·  5Comments

DibasDauliya picture DibasDauliya  Â·  6Comments

mt4c picture mt4c  Â·  3Comments

dpvc picture dpvc  Â·  3Comments

lk-geimfari picture lk-geimfari  Â·  5Comments