3

The default suggestion for keeping leading zeros is to set parse-numbers=false.

However, I have a lot of examples where the decimal markers varies between , and . Thus, I need the parser to change the to correct output-decimal-marker which I sometimes set to "," for Norwegian documents and sometimes to "." for English documents.

Is it possible to retain leading zeros for typesetting e.g.

\num{0000.0001} to produce 0000.0001 rather than 0.0001

and

\num{01.0001} to produce 01.0001 rather than 1.0001 without turning off the parser?

My setup currently is

\sisetup{
    propagate-math-font=true,
    group-digits=false,
    table-figures-decimal=0,
    table-number-alignment=center,
    input-digits={0123456789ABCDEF},
    %parse-numbers = false,
    detect-all=true,
    input-exponent-markers={},
    output-decimal-marker={,}
}

Update! Answer is accepted although it is not a solution. I got my wish for the author to consider adding this to the siunitx-package.

2 Answers 2

5

You want minimum-integer-digits:

\documentclass{article}
\usepackage{siunitx}
\sisetup{minimum-integer-digits = 4}
\begin{document}
\num{000.0001}
\end{document}
9
  • For my initial example that is ok. But I have updated my question. The number of decimal-digits may vary... I have created a \dnum[]{} where I can specify the number of integer-digits, but is quite daunting when you are trying to typeset several hundred numbers in a similar manner.
    – DrJay
    Nov 29, 2023 at 15:11
  • 1
    @DrJay Non-significant digits are dropped during parsing, which is why the option is about minimum digits. Retaining non-significant digits would be a feature request: I'd need a clear justification and link to the published literature.
    – Joseph Wright
    Nov 29, 2023 at 15:14
  • Sure! Didn't cross my mind. This is used when typesetting binary numbers. The number of digits are important. I am a text-book author and have started on a new example-book in Digital Design/Boolean algebra/Digital Electronics. M. Morris Mano's book "Digital Design" is a classic example where this is used.
    – DrJay
    Nov 29, 2023 at 15:20
  • pearson.com/en-gb/subject-catalog/p/…
    – DrJay
    Nov 29, 2023 at 15:25
  • 2
    @DrJay No, I meant the bit where you said you were writing something; I'd perhaps still be cautious, as books might be typeset by the authors themselves - journals tend to be a better bet as they are typeset by specialists.
    – Joseph Wright
    Nov 29, 2023 at 16:08
2

As a stop gap, you could define a custom macro that automatically adds minimum-integer-digits based on your input number:

\documentclass{article}
\usepackage{siunitx}

\sisetup{
    propagate-math-font=true,
    group-digits=none,
    input-digits={0123456789ABCDEF},
    detect-all=true,
    input-exponent-markers={},
    output-decimal-marker={,}
}

\ExplSyntaxOn
\cs_new:Npn \drjay_gobble_decimals:w #1 . #2 \q_stop {#1}
\cs_new:Npn \drjay_integer_digits:n #1
  { \tl_count:o { \drjay_gobble_decimals:w #1 .\q_stop } }
\NewDocumentCommand\numretained{O{} m}
  {%
    \use:e
      {
        \exp_not:N \num
          [
            minimum-integer-digits =  \drjay_integer_digits:n {#2},
            \exp_not:n {#1}
          ]
      }
      {#2}
  }
\ExplSyntaxOff

\begin{document}
\numretained{000.0001}

\numretained{01.0001}
\end{document}
2
  • Thanx! I actually went on doing just that. Even made separate ones for hex, oct, bin and deci numbers with optional arguments. However, your syntax is so much better than mine. I'll adapt it. And I gotta love the use of my username ;-)
    – DrJay
    Dec 17, 2023 at 18:14
  • @DrJay that's because in the used coding layer (L3, or expl3) one should always use a module name, and since that's an adhoc module it is quite customary (around here) to use the user name of the OP (you could as well replace every drjay with my).
    – Skillmon
    Dec 17, 2023 at 18:47

You must log in to answer this question.

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