[Tex/LaTex] How to build a macro that return the absolute value of an argument of another macro

macros

How can I build a macro that return the absolute value of an argument of another macro? I would like that the \abs macro return the absolute value of the its argument.

\RequirePackage{tikz}
\newcommand{\abs}[1]{<implementation>}
\newcommand{\command}[2]{\raisebox{\numexpr\abs{#1}*#1\relax\baselineskip}[0pt][0pt]{}{}}

So whether I use a positive or negative number as argument, the expression \abs{#1} will always be positive.

Best Answer

--1 is legal in \numexpr, equivalent to 1. So

\newcommand{\absval}[1]{\ifnum#1<0 -\fi#1}

is what you're looking for. Then

\newcommand{\command}[2]{%
  \raisebox{\numexpr\absval{#1}\relax\baselineskip}[0pt][0pt]{}{}}

will do.

Related Question