4

I want to use \num (from the package siunitx) for all the numbers in my document, tables included. (I have a lot and it would take a lot of time to do it manually.)

Is there a way to do that?

Thanks!

  • 4
    Welcome to TeX.SX! I'm afraid this is not possible. – egreg Nov 12 '17 at 23:44
  • 1
    Maybe using regular expressions? – Bernard Nov 13 '17 at 0:02
  • 2
    The S column type is pretty close to applying \num. – Mico Nov 13 '17 at 0:02
  • How are the numbers in your document formatted at present? – Mico Nov 13 '17 at 0:32
  • i'm using \usepackage[group-separator={\ }]{siunitx} – Felipe Lancheros Nov 13 '17 at 1:04
4

Applying a macro to all numbers in a document globally is so far I know not possible.

What you can do is using an advanced feature of many text editors called regular expressions to search and replace all numbers in your document files to add the \num this way.

Just get an text editor which has this feature, like the free Notpad++, and try the following text as regular expression:

([+-]? *\d+(?:\.\d*)?)

and as replacement text:

\\num{\1}

Screenshot

This regular expression searches for all numbers with or without + or -, maybe followed by spaces, and with or without a fractional part. It then adds the found number into \num{..}.

Make sure that you make a backup of your files first!

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.