2

I am stuck trying to format numbers particularly currency. I assume I need to define something so that I can say \mynum{$234234} and this is then typeset as $ 234 234.00 for instance. From what I could find out LaTeX has \numprint etc. I can't seem to find a ConTeXt module or I have no idea how to begin defining my own mynum. Could someone give me directions to define my own function/macro (not sure what they are called).

2

ConTeXt has a unit mechanism which can format numbers. However, this method requires you to manually specify the thousand separator, it is not formatted automatically. Example:

\setupunit [method=4]
\asciimode
\starttext
  $ \unit{234,234.00}
\stoptext

The input is always a comma as thousands separator and a period as decimal separator, regardless of the method chosen.

To have a small space (more precisely: \thinmuskip) as thousands delimiter and a period as decimal separator, use method four using \setupunit. The digit modes are:

mode  thousands separator  decimal separator
--------------------------------------------
1     periods              comma
2     commas               period
3     thinmuskips          comma
4     thinmuskips          period
5     thickmuskips         comma
6     thickmuskips         period
  • It would be a nice feature, though, if the \unit command could figure out the thousands separator on it's own if desired. – Marco Sep 30 '13 at 22:54
  • Just a quick follow up. If I \define[1]\u{\unit{#1}} how do I know that I am not overriding an existing definition for \u. I did do a compile before defining and no errors showed up, but so did no output. – YoungGrandpa Oct 1 '13 at 1:12
  • @YoungGrandpa \define warns you that it's overwriting an existing command. See the log file: system > command '\u' is already defined. You can use \let\u\unit, but I do not recommend this. First it overwrites an existing command. Second it makes the document less readable. Use the features your editor provides to do the expansion if you want to save some key strokes. – Marco Oct 1 '13 at 6:13
  • I see I should be reading the log even if compile shows no errors. I noticed a couple of other issues wrong with my document. Now I wonder what \u does :) – YoungGrandpa Oct 1 '13 at 10:01
  • The log file contains lots of noise as well as valuable information (especially with some tracing enabled). There are several ways to find out what \u does: The most strightforward way is to just try to use it, e.g. \u A B C. Another option is \meaning\u. – Marco Oct 1 '13 at 10:26

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.