Decimal comma on input
- To: mathgroup at smc.vnet.net
- Subject: [mg60531] Decimal comma on input
- From: Cca <cca at gregosetroianos.mat.br>
- Date: Mon, 19 Sep 2005 04:45:48 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Here in Brazil our decimal separator is a comma. (This is the favoured convention in most non English-speaking countries.) We also put dots between each group of three digits. As an example, the number whose numeral is
1234.56789
in USA is represented in Brazil as
NumberForm[1234.56789, DigitBlock->{3,3},
NumberPoint->",", NumberSeparator->"."]
or also (following the SI)
NumberForm[1234.56789, DigitBlock->{3,3},
NumberPoint->",", NumberSeparator->" "]
This said, it is natutal to ask: how to instruct Mathematica to recognize a decimal comma on input? My ad hoc
solution is shown below, but I would be very interested in knowing alternative approaches.
---------------------------------------------
Instead of a "true" comma, I use one with hidden information, namely
TagBox[",", Identity, Editable->False, SyntaxForm->"."] // DisplayForm
with the following rule (which will work, of course, only in the expected contexts):
MakeExpression[RowBox[{a_,
TagBox[",", Identity, Editable->False, SyntaxForm->"."], b_}], form_] := MakeExpression[StringJoin[a, ".", b], form]
Now we can try, for example, 2,3*3,5, 2,3+1,45, etc.
---------------------------------------------
Finally, to make it easy to insert the decimal comma above I provide four ways to the user:
(1) a button:
ButtonBox[",", ButtonData->
TagBox[",", Identity, Editable->False, SyntaxForm->"."]// DisplayForm
(2) a rule for InputAliases (which overrides \[InvisibleComma]);
(3) a keyboard shortcut, for which I add the following line to the file KeyEventTranslations.tr:
Item[KeyEvent["KeypadDecimal"], FrontEndExecute[
{FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
TagBox[",", Identity, Editable->False, SyntaxForm->"."], After]}]]
(4) a menu command (not well tested yet):
LinkWriteHeld[$ParentLink,
Hold@AddMenuCommands["New",
{Item["Decimal comma",
FrontEndExecute[{
FrontEnd`NotebookWrite[FrontEnd`InputNotebook[], TagBox[",", Identity, Editable->False, SyntaxForm->"."], After]}]]}]]
---------------------------------------------
Carlos César de Araújo
Gregos & Troianos Educacional
www.gregosetroianos.mat.br
Belo Horizonte, MG, Brazil
(31) 3283-1122