0

I have written a document with some data that I must update at last minute. So I have created some newcommand:

%--------------------------------
% Insert data here
\newcommand{\srskm}{12,253~}
\newcommand{\srspercent}{1.53\%~}
\newcommand{\srssamples}{2,777,059~}
\newcommand{\srssamplesml}{2.8~}
\newcommand{\srsacc}{833~}

It is all right, but if I omit the tilde, the number will be insert without spacing.

Question: There is a way to declare this data and obtain a spacing when after there is a word, and no spacing when after there is a punctuation?

1 Answers1

2

This doesn't really answer your question, but will maybe solve your problem.

Use {} after calling the macros. You could/should also use siunitx for handling units or numerics. Maybe something like this?

\documentclass{article}

\usepackage{siunitx}

\newcommand{\srskm}{\num{12253}}
\newcommand{\srspercent}{\SI{1.53}{\percent}}
\newcommand{\srssamples}{\num{2777059}}
\newcommand{\srssamplesml}{\num{2.8}}
\newcommand{\srsacc}{\num{833}}

\begin{document}
  Example sentence: \srskm{} without and with punctuation \srskm{}. Works with \srspercent{} as well \srspercent{}.
\end{document}

enter image description here

Holene
  • 6,920
  • I have read the documentation of siunitx: very interesting. Thank you. You have solved partially my problem (I would like do not use the curly braces). – Giacomo Alessandroni Jun 06 '15 at 08:47
  • +1 I like your solution, e.g. \newcommand{\srskm}{\SI{12253}{\km}}. I extract the data from (http://smartroadsense.it/open-data.html)[SmartRoadSense] web site, where I have only two data (the first is the second per 300). And \srspercent is \srskm/800000*100. I try to define two variable and obtain the other data. – Giacomo Alessandroni Jun 06 '15 at 10:13