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




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

  • 4
    $\begingroup$ 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. $\endgroup$ – David Z Feb 8 '17 at 23:37
  • $\begingroup$ This is great. In my opinion this would make it worth installing mhchem on this site. $\endgroup$ – Nathaniel Feb 9 '17 at 0:28
  • 2
    $\begingroup$ 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. $\endgroup$ – Emilio Pisanty Feb 9 '17 at 14:11
  • $\begingroup$ 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 :-) $\endgroup$ – mhchem Feb 9 '17 at 16:01
  • 1
    $\begingroup$ @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. $\endgroup$ – mhchem Feb 9 '17 at 19:54
  • 1
    $\begingroup$ @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. $\endgroup$ – Emilio Pisanty Feb 9 '17 at 20:21
  • $\begingroup$ @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). $\endgroup$ – mhchem Feb 9 '17 at 22:39
  • $\begingroup$ 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? $\endgroup$ – Emilio Pisanty Feb 9 '17 at 22:48
  • $\begingroup$ @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. $\endgroup$ – mhchem Feb 9 '17 at 23:20
  • 2
    $\begingroup$ @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. $\endgroup$ – 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

  • $\begingroup$ 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.) $\endgroup$ – Nathaniel Apr 23 '13 at 7:47
  • $\begingroup$ @Nathaniel: I edited a link in (stackapps.com/tags/script/info). There's a workaround :) $\endgroup$ – Manishearth Apr 23 '13 at 7:51
  • $\begingroup$ Awesome, thanks! $\endgroup$ – Nathaniel Apr 23 '13 at 7:58
  • $\begingroup$ 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. $\endgroup$ – 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.

  • 1
    $\begingroup$ 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...? $\endgroup$ – Nathaniel Apr 23 '13 at 7:13
  • $\begingroup$ @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? $\endgroup$ – Brandon Enright Apr 23 '13 at 7:20
  • 1
    $\begingroup$ 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. $\endgroup$ – Nathaniel Apr 23 '13 at 7:29

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

  • 1
    $\begingroup$ 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. $\endgroup$ – Nathaniel Feb 9 '17 at 1:49
  • 1
    $\begingroup$ Ah, that would be a problem then. $\endgroup$ – David Z Feb 9 '17 at 1:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .