3

The Real Academia de la Lengua Española (Royal Academy of Spanish Language) prohibits the use of commas as separators within numbers for every factor of 1000, since the comma is used as decimal separator. For example, what in English is written as 1,000,000.54, we write it as 1000000,54.

However, it is also required that a small space be used as separator (something like $1\,000\,000.54$). I would like to know how to do this automatically in LaTeX (possibly with babel). I could do it manually, but I have already written too many numbers, and some come from software that don't take into account these rules.

Thanks in advance for your answers!

  • 3
    Most people probably use siunitx's \num and friends for jobs like this [citation needed], but that requires you to put a macro around the number. If you don't want to do that, you'll probably have to resort to LuaLaTeX and Lua patterns to do some pre-processing for you. – moewe Jun 27 at 20:10
  • Hello, @siracusa. I think siunitx is a good option. I was thinking about using Python in parallel with LaTex, similarly to your suggestion of using Lua, but I gave up soon. There should a PyTeX and PyLaTeX systems. How awesome that would be! – Diego Sejas Jun 28 at 19:19
6

This can be easily done using the siunitx package. As can be seen from the following MWE, one can input numbers with different decimal markers and get the same output. The decimal marker can be changed by output-decimal-marker white the group separator can be changed with group-separator.

\documentclass[spanish]{scrartcl}
\usepackage{babel}
\usepackage{siunitx}
\sisetup{output-decimal-marker = {,}}

\begin{document}
\num{1000000,54}

\num{1000000.54}

\num{100 00 00.54}
\end{document}

enter image description here

  • Thank you very much, @leandriis. This is exactly what I was looking for. – Diego Sejas Jun 28 at 19:16

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.