I'd like to manipulate the arguments in \newcommand. More explicitly, I'd like something like that:
\newcommand{\X}[1]{
#1+1
}
And if I call \X{0}, I want it to return 1 and not 0+1.
Thank you :-)
I'd like to manipulate the arguments in \newcommand. More explicitly, I'd like something like that:
\newcommand{\X}[1]{
#1+1
}
And if I call \X{0}, I want it to return 1 and not 0+1.
Thank you :-)
This is the first time I tried \numexpr as suggested by percuße in comment. I have added \pgfmathparse as another possibility.
\documentclass[10pt]{article}
\usepackage{tikz}
\newcommand{\X}[1]{%
\pgfmathparse{int(#1+1)}\pgfmathresult%
}
\newcommand{\XX}[1]{%
\number\numexpr#1+1\relax%
}
\begin{document}
\X{0}
\begin{enumerate}
\foreach \x in {0,...,5}
{\item \X{\x}}
\end{enumerate}
\XX{0}
\begin{enumerate}
\foreach \x in {0,...,5}
{\item \XX{\x}}
\end{enumerate}
\end{document}
Note that you can also change \pgfmathparse{#1+1}\pgfmathresult into \pgfmathparse{int(#1+1)}\pgfmathresult if you want to remove the decimals.
% at end of lines and warn about spurious spaces in the output
– egreg
Jan 28 '13 at 10:08
{}). Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. – Claudio Fiandrino Jan 28 '13 at 08:54#1argument always integer or decimal? You can also search for\numexpron this site. – percusse Jan 28 '13 at 08:54:-)– hpesoj626 Jan 28 '13 at 09:29