4

In small math classes, students are asked to respect the thousand separators, like this:

enter image description here

This forces me to use the \num{} command from the siunitx package in each argument of the \dfrac command.

How can I define a new \dfrac command so that I don't have to do this and write \newfrac{1}{10000000} instead of \dfrac{1}{\num{10000000}}?

enter image description here

\documentclass{article}
\usepackage{mathtools}
\usepackage{siunitx}
\sisetup{locale=FR}

\begin{document}

\begin{multline*}
\num{0.27609390226}=\dfrac{2}{10}+\dfrac{7}{100}+\dfrac{6}{1000}+\dfrac{9}{100000}+\dfrac{3}{1000000}+\dfrac{9}{10000000}\\
+\dfrac{2}{1000000000}+\dfrac{2}{10000000000}+\dfrac{6}{100000000000}
\end{multline*}


\begin{multline*}
\num{0.27609390226}=\dfrac{2}{10}+\dfrac{7}{100}+\dfrac{6}{\num{1000}}+\dfrac{9}{\num{100000}}+\dfrac{3}{\num{1000000}}+\dfrac{9}{\num{10000000}}\\
+\dfrac{2}{\num{1000000000}}+\dfrac{2}{\num{10000000000}}+\dfrac{6}{\num{100000000000}}
\end{multline*}

\end{document}
11
  • 2
    Something like \newcommand*{\numfrac}[2]{\dfrac{\num{#1}}{\num{#2}}}? Commented Jul 25, 2024 at 16:17
  • Yes, something like that. Commented Jul 25, 2024 at 16:20
  • 1
    @AndréC dfrac (which should be used sparingly) forces displaystyle fractions so will use the large form even in a superscript, frac chooses a suitable form depending on the context but the context here is displaystyle so it will use the same display as dfrac. Commented Jul 25, 2024 at 17:40
  • 1
    @AndréC Luciole at 20pt is good for visually impaired people but I don't know a matching math font and for example it has awful curly braces { and }. Commented Jul 25, 2024 at 18:13
  • 1
    @AndréC I don't think there is a packaging of the font for use with traditional TeX/LaTeX via pdftex/pdflatex. Indeed you have to use xelatex or lualatex. Commented Jul 25, 2024 at 19:00

1 Answer 1

5

You can define \newfrac in this way:

\NewDocumentCommand{\newfrac}{m m}{\dfrac{\num{#1}}{\num{#2}}}

This will set both the numerator and denominator using siunitx's \num.

Alternatively, if you want to keep using \dfrac, use

\RenewDocumentCommand{\dfrac}{m m}{\genfrac{}{}{}0{\num{#1}}{\num{#2}}}
5
  • Perfect, thank you. Unless I'm mistaken, is \RenewDocumentCommand in the xparse package? Is it now part of the LaTeX core? Commented Jul 25, 2024 at 16:29
  • 2
    @AndréC: It's part of the core, yes, so no need to explicitly include \usepackage{xparse}. Commented Jul 25, 2024 at 16:44
  • Does the space inm m hold any significance? It seems as spaces do matter usually in documents that mm would be more expected (even if completely equivalent), else it seems to encourage usage as \newfrac {A} {B} so it encourages to put spaces a bit everywhere, which yes do not have have any impact if macro fetches two arguments but perhaps not in general. I have always felt that what is completely lacking from all books serving as introduction to LaTeX is a frank and complete discussion of spaces, and that the style of LaTeX3 programming encourages people not to care about them. Commented Jul 25, 2024 at 18:09
  • @user691586: I split them out because there can be multicharacter argument specifications (like +m or !o or O{stuff} or d()). Even if I use single-character argument specifications, it's just a habit. It makes it more clear if these are separated with a space (\NewDocumentCommand{\cmd}{+m !o O{stuff} d()}{...}) rather than not (\NewDocumentCommand{\cmd}{+m!oO{stuff}d()}{...}). Commented Jul 25, 2024 at 18:25
  • @Werner thanks indeed it does make sense, I understand. Maybe I should have practiced myself these new functionalities prior to make my question/remark... Commented Jul 25, 2024 at 19:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.