12

I am well aware of the siunitx package, but as far as I can tell, it comes short for this task.

In decimal notation, there are many conventions such as using . or , for the decimal mark, as well as using a space, . or , for group delimiters. The package handles them well, and also makes them configurable too, which is a great help. But...

It does not allow defining a group size different than the most-conventional one: three. Seems fine at first, but when looked at this table at Wikipedia, one can see that people may actually need some flexibility there.

On top of that, it keeps using that magical number three for the digits after the decimal mark, too. This is the part where I am personally concerned of, the three on the first part is actually fine by me (for the time being), which I have brought up only due to its close relevance.

According to this question/answer, the prevailing convention is even to make groups of 5 when it comes to digits after decimal mark.

So, is there a siunitx option to change this three to something else, even to different things on both sides of the decimal mark? If there isn't, what could be done to have groups of three on the left side and of five on the right side?

Is there perhaps a way for me to manually mention the group limits for siunitx to see and consider (maybe through enabling a switch), just like I mention the decimal mark? In an example:

\num[flick]{123 456.12345 67890}

to produce:

enter image description here

Here, supposedly space characters were to be interpreted as places where I'd like to see each one of my group-delimiters, which are left as the default thin-space (?), thanks to that option flick I had been looking for.

Sorry for a suggestion-like question.

  • That table includes the SI ones. Hence does siunitx too. The rest is not SI – percusse Feb 3 '15 at 22:02
  • @percusse Then again siunitx also shows some flexibility, too. And then again, that table doesn't show much about the grouping of digits after decimal mark for any, including SI. – ThoAppelsin Feb 3 '15 at 22:04
  • what are the constraints? does the macro have to be expandable? will it be supposed to expand its argument, possibly doing computations onit? will it have to accept numbers in scientific notation too? ... if you just need something accepting explicit decimal numbers ABC...YZ.abc...yz and grouping the digits before and after the mark in a specified repetitive manner, this can be done quite easily. – user4686 Mar 6 '15 at 12:13
1

Found some code in siunitx.sty

\cs_new_protected:Npn \__siunitx_number_format_group_decimal_aux:NNNN
  #1#2#3#4 {
  \tl_if_empty:nTF {#2}
    { \tl_put_right:Nn \l__siunitx_tmpb_tl {#1} }
    {
      \tl_if_empty:nTF {#3}
        { \tl_put_right:Nn \l__siunitx_tmpb_tl { #1 #2 } }
        {
          \tl_put_right:Nn \l__siunitx_tmpb_tl { #1 #2 #3 }
          \tl_if_empty:nF {#4}
            {
              \tl_put_right:NV \l__siunitx_tmpb_tl \l__siunitx_group_sep_tl
              \__siunitx_number_format_group_decimal_aux:NNNN #4
            }
        }
    }
}

Now you can see how it works: every time siunitx encounter a decimal part, say, 3.14159265, it tries to read four arguments. In this case,

  • it will get 1, 4, 1, and 59265. So it inserts an \l__siunitx_group_sep_tl and saves 141, into \l__siunitx_tmpb_tl.
  • Next 59265 becomes 5, 9, 2, and 65; and \l__siunitx_tmpb_tl becomes 141,592,.
  • Finally 65 becomes 6, 5, empty, and empty. So it stops here and return with \l__siunitx_tmpb_tl being 141,592,65.

So?

It seems like even with expl3 this kind of processing is hard to be replaced by a loop. If you want a different grouping size, try to do something like

\cs_new_protected:Npn \__siunitx_number_format_group_decimal_aux:NNNNNNN
 #1#2#3#4#5#6#7 {
  {}
  {
    {}
    {
      {}
      { 
        {}
        {
          {}
          {
            {
            }
          }
        }
      }
    }
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.