TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have implemented couple of macros that should remove commas from numbers. It's nasty dirty stuff, but it works when input is number:

\removecommas{12,34,56.7} % => 123456.7

But it stop working when the input is given by some command, such as:


Why is this happening? How can I force TeX to expand \mynumber before commas? I've tried:


but that didn't seem to help.

share|improve this question

migrated from stackoverflow.com Aug 28 '11 at 11:50

This question came from our site for professional and enthusiast programmers.

The cause here is very similar to tex.stackexchange.com/questions/26746/… – Joseph Wright Aug 28 '11 at 12:04

You are nearly there with


What is needed is a group:


To understand why, you have to remember that TeX grabs arguments as tokens. Taking the example input, in the first case, you expand \mynumber to 12,34,56.7. TeX then grabs 1 as the argument to \removecommas, and unsurprisingly nothing actually happens. On the other hand, with the group in place all of 12,34,56.7 is grabbed by \removecommas, and the processing takes place as you want.

(Notice that we need two \expandafter primitives. The second one is needed to expand past {.)

share|improve this answer

If you need only up to one level expansion, this works:

\def\removecommas{\begingroup\catcode`,=9 \doremove}
share|improve this answer

The other answers explain the macro expansion. However, if all you want to do is to remove the commas in numbers you could use the numprint package with the following setup:


\renewcommand*\nprt@dotlist{.}% only . for decimal separator in input
\renewcommand*\nprt@ignorelist{,}% ignore , in input
\npdecimalsign{\ensuremath{.}}% use . as decimal output

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.