TransWikia.com

Mixed decimal input with siunitx

TeX - LaTeX Asked by hobbicon on December 4, 2020

Does siunitx take mixed decimal inputs like 0,004319689898685966 and 0.004319689898685966?
It looks like it, but is it intended to work like this?

I am using Python for my calculations with a "." decimal symbol and manually type with a "," decimal symbol.

Image:
enter image description here

MWE:

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{siunitx}
sisetup{range-phrase=-,
            detect-all,
            decimalsymbol=comma,
            round-mode=places,
            round-precision=4,
            range-units=single,
            per-mode=fraction,}

begin{document}

begin{itemize}
item SI{0,004319689898685966}{meter squared}
item SI{0.004319689898685966}{meter squared}
end{itemize}
end{document}

2 Answers

Since input data for SI might come from various sources, one can use various styles for it; in particular a decimal period or a decimal comma in the input is converted to use a marker that's set with output-decimal-marker.

The key decimalcomma is still allowed for it, but it issues a warning

Package siunitx Warning: Version 1 option 'decimalsymbol' detected.

There are various options to comply with different input styles, but at the end the output is always normalized according to the chosen options regarding the decimal marker, the group separations and so on.

Options can be set globally (but respecting TeX groups) with sisetup or locally with an optional argument to SI.

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{siunitx}
sisetup{
  range-phrase=-,
  detect-all,
  output-decimal-marker={,},
  round-mode=places,
  round-precision=4,
  range-units=single,
  per-mode=fraction,
}

begin{document}

begin{itemize}
item SI{0,004319689898685966}{meter squared}
item SI{0.004319689898685966}{meter squared}
item SI[output-decimal-marker=.]{0.004319689898685966}{meter squared}
sisetup{output-decimal-marker=ensuremath{{cdot}}}
item SI{0.004319689898685966}{meter squared}
end{itemize}
end{document}

enter image description here

Correct answer by egreg on December 4, 2020

The siunitx package distinguishes between

  • input-decimal-markers, with default ,., i.e., both comma and period (aka "full stop") are interpreted as decimal marker, and

  • output-decimal-marker, which defaults to . (period).

A compilable example:

documentclass{article}
usepackage{siunitx}
begin{document}
num{0.333} and num{0,333}

sisetup{output-decimal-marker={,}} % change the default

num{0.333} and num{0,333}
end{document}

Answered by Mico on December 4, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP