# Formatting numbers with smaller glyphs for decimals

I am currently writing up a coursebook in which I handle sets of decimal numbers. As the language of the coursebook is French, the decimal separator has to be a comma and the thousands separator a thin space. But then, it becomes difficult for the reader to distinguish between the set of four integers {0, 1, 2, 3} and the set of two decimal numbers {0.1, 2.3}. See the following code:

\documentclass{minimal}
\usepackage[french]{babel}
\usepackage[autolanguage]{numprint}
\begin{document}
\noindent $\{\numprint{0.1}, \numprint{2.3}\}$\\
$\{0, 1, 2, 3\}$
\end{document}


which is rendered by

which is not quite fine…

What I would like to do is to print the comma and the decimals in a smaller font than the digits before the decimal separator (this is a rather common usage in France, for instance to typeset prices), like in

\documentclass{minimal}
\usepackage{amsmath}
\usepackage{relsize}
\begin{document}
$\{\text{$0$\smaller$\mathord,1$}, \text{$2$\smaller$\mathord,3$}\}$\\
\end{document}


(yes, this is a quite ugly code :-S), which yields the much more easy-to-read

Now my question is: how to do that neatly with a simple command like \numprint from the numprint package? Changing the font for decimals does not seem to be a feature implemented in numprint, nor in siunitx; and I am not skilled enough in (La)TeX to build my own solution…

(Post-Scriptum: If possible, I would like to have a solution which also allows for inserting automatically the thousand separators, and rendering “1.2e3” with a power of ten…)

• With the constraints given, I'd use a semicolon instead of a comma for lists. Sep 19, 2018 at 22:03
• Or, considered that you already need to type \numprint everywhere, you could just insert manual space after each comma in the list $\{\numprint{0.1},\, \numprint{2.3}\}$. Sep 19, 2018 at 22:29
• @egreg Indeed, I already had that idea in mind, but I do not like it much… :-| Also, I would find it quite frustrating that numprint and siunitx do implement some very sharp features to display formatted numbers, but that there would be no reasonable way to specify different fonts for pre- and post-comma digits… :-( Sep 19, 2018 at 22:33
• @RuixiZhang This is an idea worth being considered :-) Sep 19, 2018 at 22:36
• It might be frustrating; but I'm inclined to think that your readers will be more frustrated by the unreadable mess. Sep 19, 2018 at 22:54

You might do like this:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{siunitx,relsize}

\sisetup{locale=FR}

\ExplSyntaxOn
\NewDocumentCommand{\hnum}{>{\SplitArgument{1}{.}}m}
{
\hnumA#1
}
\NewDocumentCommand{\hnumA}{mm}
{
\num{#1}
\IfValueT{#2}{\hnumB{#2}}
}
\NewDocumentCommand{\hnumB}{>{\SplitArgument{1}{e}}m}
{
\hnumC#1
}
\NewDocumentCommand{\hnumC}{mm}
{
\ensuremath
{
\IfValueT{#2}{{}\times\num{e#2}}
}
}
\ExplSyntaxOff

\begin{document}

$\{\hnum{0.1},\hnum{2.3},\hnum{4.5e10}\}$

\bigskip

$\{\num{0.1};\num{2.3};\num{4.5e10}\}$

\end{document}


However the result is really ugly and difficult to interpret. Much better to use a semicolon.

• I definitely like this solution; it is GREAT! :-D Plus, it is rather easy to customize :-) (For instance, I also wanted to print the comma smaller to improve readability; and I managed to edit your solution this way in no time!). Sep 20, 2018 at 5:44
• @RémiPeyre For a smaller comma, just remove {,} and the output-decimal-marker={} option. This doesn’t improve much the final result, though. Sep 20, 2018 at 8:20
• Actually what I was saying in my previous message was that I had found easily how to adapt your code, and that I enjoyed this feature of easy customization of your solution! ;-) (Another customization that I made was, before the comma, to go in text mode, use the text-mode \smaller command, and then go back to math mode: because \mathsmaller causes the smaller characters to be quite small, which text-mode \smaller does not ;-)). Sep 20, 2018 at 15:14

How is this for a start?

\documentclass{article}

\def\numX#1.#2\relax{\mbox{$#1$\small$\mathord,#2$}}
\newcommand{\num}[1]{\numX#1\relax}

\begin{document}
$\{\num{0.1}, \num{2.3}\}$
\end{document}

• I do like it! :-) I had forgotten about this \def\mycs#1.#2 TeX feature… Sep 19, 2018 at 22:35
• I'd consider \ensuremath{#1{,}\mathsmaller{#2}} exploiting relsize (but the result is ugly nonetheless). Sep 19, 2018 at 23:00
• @egreg Just a matter of taste! :-) Personally I much like this typographical rendering ;-) Sep 20, 2018 at 15:16