# siunitx LaTeX package?

It's a drag having to type things like

$1.38 \times 10^{-23} \, \mathrm{JK^{-1}}$

all the time. Would it be possible to have the siunitx package installed on this site? Then we could get the same effect with just

$\SI{1.38e-23}{J.K^{-1}}$

or

$\SI{1.38e-23}{\joule\per\kelvin}$

instead, which is more readable, easier to type, and gets all the spacing right first time.

If you convince your administrator to enable mhchem here – chemistry.SE does have it – then you could make use of MathJax/mhchem's \pu command.

$1.38 \times 10^{-23} \, \mathrm{J\,K^{-1}}$


could then be written as

\pu{1.38E-23 J K^-1}


See how it renders at chemistry.SE.

Background information: MathJax is a LaTeX implementation, written in JavaScript. It is not a complete TeX engine, it just does a very similar job when looked at fromt he outside. Because it is completely different at the inside, one cannot simply load LaTeX packages. Instead, one has to create a completely new package in JavaScript. That's the reason, one cannot simply load siunitx with MathJax. You would need somebody to rewrite the whole behavior for a completely different framework. With mhchem, I did such an reimplementation. Because TeX and JavaScript are so different, the two packages look very different inside. They even behave slightly differently (with MathJax/mhchem having more features than the original LaTeX/mhchem).

• This is a nice workaround, though this is the only thing from mhchem we'd be using on a regular basis, and I would prefer to have an extension that only handles the units. Personally, I also prefer the way siunitx handles units, for whatever that's worth. Though this does definitely seem better than typing out unit sequences manually. – David Z Feb 8 '17 at 23:37
• This is great. In my opinion this would make it worth installing mhchem on this site. – Nathaniel Feb 9 '17 at 0:28
• I tend to agree with David - I would rather wait to have siunitx installed than be faced with a fragmented corpus which depends on some other syntax from some package which makes the page heavier but cannot later be dropped. Having \pu and siunitx is somewhat of an either/or, since we can't later on easily drop the former. – Emilio Pisanty Feb 9 '17 at 14:11
• You are right, allowing \pu now is nothing you can undo now. BTW: I don't really understand the value of siunitx for here. In LaTeX, you have the possibility to flip a switch and all units will be rendered differently. I don't see the advantage of this style-switching possibility for any SE site. On the contrary, I consider \joule\per\Kelvin more difficult to type than J/K or J K-1. But then, I am biased :-) – mhchem Feb 9 '17 at 16:01
• @EmilioPisanty It is not an "either/or". While you cannot easily drop an extension that received some usage, it is possible to add another one side-by-side. – mhchem Feb 9 '17 at 19:54
• @mhchem It's a social problem, not a technical one. Of course you can in principle have the two side by side, but that just leads to a fragmented corpus of posts, which is not really desirable, and dropping an extension that's relied on by existing posts is problematic. Loading the two extensions side by side also increases the page size and load times, which is nontrivial for users on mobile connections and slower devices, so this needs to be thought about with more care. – Emilio Pisanty Feb 9 '17 at 20:21
• @EmilioPisanty Yes, of course, you have to think it through thoroughly. I just wanted to make an offer. If you ask for it, I might even create a \pu-only version of mhchem, if page size is an issue (although – as a fun fact – Davids avatar image adds more bytes to this page than mhchem would). – mhchem Feb 9 '17 at 22:39
• I just wanted to point out pros and cons is all. Creating a \pu-only version of mchem sounds nice enough, but how do you get that into MathJax? And, if it's that easy, why can't you do that with siunitx? – Emilio Pisanty Feb 9 '17 at 22:48
• @EmilioPisanty Why not siunitx? I added a "Background information" paragraph to my post above. In short: One cannot reuse LaTeX packages, but has to completely rewrite everything for another framework in another language. For mhchem, such a rewrite exists (and is being used at SE) and I would even consider creating a stripped-down version of it. (As the author of MathJax/mhchem, I know what to do and can estimate the effort). As for siunitx, an early version for MathJax exists, but expanding that it is not my calling. – mhchem Feb 9 '17 at 23:20
• @mhchem Thanks for that background info, I didn't know packages were quite that different. That does change the game, and makes mhchem a much more attractive option. – Emilio Pisanty Feb 10 '17 at 10:18

Mathjax doesn't seem to allow the siunitx extension (there are a couple of pachages like mhchem which can be enabled)'

However, for SI units, I use this userscript. It lets me enclose stuff with the dollar signs via Alt-M, and Alt-S does \:\mathrm{<selected text here>} for SI units. (there also are options for vector fields and double-dollarifying)

I've also put a feature-request here

• Thanks, that looks very handy - but it seems Chrome has recently been changed to disallow installing extensions from sites other than Chrome Web Store - see here. (That page is ambiguous about whether there's a way to manually override this feature. I looked but couldn't find one.) – Nathaniel Apr 23 '13 at 7:47
• @Nathaniel: I edited a link in (stackapps.com/tags/script/info). There's a workaround :) – Manishearth Apr 23 '13 at 7:51
• Awesome, thanks! – Nathaniel Apr 23 '13 at 7:58
• The reason siunitx isn't available for MathJax is that it's a massively complicated package, which uses a lot of core LaTeX functionality that just doesn't exist in MathJax (as far as I know). Of course, it would be possible to implement, it would just be a huge project. But a simplified version that just does the \SI macro for proper spacing and formatting might not be too hard. – David Z Apr 23 '13 at 16:12

The site is using MathJax which is LaTeX in JavaScript. This question has been asked several times on several different StackExchange sites. It just isn't an option right now.

• Some SE sites do have specific packages installed, though. For example, chemistry.SE has the mchem package. If it wasn't for that I would just have assumed that installing packages would be impossible. Is it just that some packages are compatible with MathJax and some aren't, or...? – Nathaniel Apr 23 '13 at 7:13
• @Nathaniel I don't know the ins and outs of MathJax. Others have asked and said siunitx is a no-go. Perhaps it's time to revisit that and see if it's still true? – Brandon Enright Apr 23 '13 at 7:20
• Hmm, from looking here it appears that a small number of LaTeX packages have been re-implemented in MathJax - mhchem is one of them but siunitx isn't, unfortunately. So I guess it's just a case of hoping the MathJax people will implement it eventually. – Nathaniel Apr 23 '13 at 7:29

I've just noticed that there is an siunitx extension in the MathJax third party extensions repository.

• That looks great too, but I have a suspicion that it's incomplete and not being developed. On the example page at rawgit.com/burnpanck/MathJax-third-party-extensions/… all but the first few are not rendering for me, and there are no commits after the initial checkin. – Nathaniel Feb 9 '17 at 1:49
• Ah, that would be a problem then. – David Z Feb 9 '17 at 1:49