Journal home page
General information
Submit an item
Download style files
Copyright
Contact us
logo for The PracTeX Journal TUG logo

Ask Nelly:
      How do I create European style spacing within numbers?

The Editors

Abstract


Ask Nelly is a question and answer column. Nelly is the quiet person who sits at the back corner desk, who knows a lot, and when asked any question is always ready with a patient answer. If Nelly doesn't know the answer, Nelly will know an expert who has the answer. Feel free to Ask Nelly about any aspect of LaTeX, TeX, Context, etc.


tpjlogo

Q: Dear Nelly: When I use US style separators for thousands or decimals in LaTeX math mode, everything looks fine. When I use European separators, however, the spacings are all wrong. How can I fix this?

A: This is indeed a problem, as can easily be seen by typing:

         \begin{eqnarray}
	   3,141,592.654
	   3.141.592,654
	 \end{eqnarray}
	
The first rendition, with US style spearators, gives correct spacing, but the second one, using European style, has too little space between the thousands, and too much at the decimal comma.

This difference is caused by the definition of the "." and "," in math mode. The symbol "." is defined as type "mathord" and the symbol "," as "mathpunct". This needs to be changed around for European style numbers. In case one has only a few such numbers in the document, use one of these two ad-hoc solutions:

         \begin{eqnarray}
	   3\mathpunct{.}141\mathpunct{.}592\mathord{,}654
	   3\mathpunct{.}141\mathpunct{.}592,654
	 \end{eqnarray}
	
A document-wide change can be achieved by using these definitions in the document preamble:
	 \DeclareMathSymbol{.}{\mathpunct}{letters}{"3A}
	 \DeclareMathSymbol{,}{\mathord}{letters}{"3B}
	
Which is the reverse of their usual, US-style, definitions.


The above question was answered by Yuri Robbers, a member of the editorial board of this journal. He can be reached at

tpjlogo

The answer given by Nelly (Yuri Robbers) to the problem of setting US or European style digit separators is correct as long as you don't care the correct typesetting of such entities. When I say "correct", I mean "according to the ISO regulations". I would be a blind man if I pretended everybody is following the ISO regulations, but I would assume that the requested searators may be tolerable in an informal handwritten letter, even in an invoice, but certainly not in a typeset book or a report (especially if typeset with our favourite software!).

Besides establishing the type of decimal separator (the decimal point for English texts and the decimal comma for text in other languages), the ISO regulation expressly forbid any other "inked" mark within the digit triplets; the only allowed separator is a thin space, therefore the example would be

	\begin{eqnarray*}
	3\,141\,592.654 \\
	3\,141\,592,654
	\end{eqnarray*}
	
The problem then is how to make the right spacing around the comma or around the point when they are used as decimal separators.

No problems for the point because the default settings in (La)TeX are correct.

In languages where the comma plays the role of a punctuation mark *and* of a decimal separator, it is necessary to exploit a specific package icomma, to be found at CTAN://macros/latex/contrib/was that defines the "intelligent comma". This same folder on CTAN contains several other little packages by Walter Schmidt, among which fixmath, which adjusts several settings for typesetting mathematics to comply with ISO standards.

Alternatively it is necessary to juggle with primitive definitions by declaring the comma an active mathcar with math code "8000 and then assigningg this active char a definition that tests if the next token is a space or something else; if it's a space then the punctuation mark is used, otherwise the ordinary math symbol is used. Not difficult to write down, but certainly this is one of those definitions that I put in all my personal macro files.

	\makeatletter
	\DeclareMathSymbol{\virgola}{\mathpunct}{letters}{"3B}
	\DeclareMathSymbol{\decimalcomma}{\mathord}{letters}{"3B}
	\AtBeginDocument{\mathcode\,="8000}
	{\catcode ,=\active \gdef,{\futurelet\let@token\m@thcomma}}
	\def\m@thcomma{\ifx\let@token\@sptoken\virgola\else\decimalcomma\fi}
	\makeatother
	
If you add these definitions then you'll notice the difference when you write fractional numbers as well as when you type
	\( f(x,y) \)
	
versus
	\( f(x, y) \)
	
This more extensive answer has been provided by Claudio Beccari, a long time LaTeX user. In 1991 hewrote a book in Italian with the title "LaTeX — Guida a un sistema di editoria elettronica". Since then he is considered one of the gurus of the Italian TeX Users, even if this fame is totally undeserved. He has contributed several papers to TUGboat; he produced the hyphenation patterns for Italian and Latin, still in use today; he designed the default Greek fonts for use with Babel and supplied the Greek hyphenation patterns (luckily enough the Greek Users produced better patterns and these replaced Claudio's). Presently the Italian language definition file of the Babel package, although under the full control of Johannes Braams, is regularly updated and enriched by Claudio. He has participated in various TeX conferences and is a memeber of TUG GuIT, the official Group of the Italian TeX Users. He can be reached at

tpjlogo


Page generated June 9, 2010 ;

TUG home page; webmaster; facebook; twitter; mastodon;   (via DuckDuckGo)