Removing white space from one side of a binary operator

expl3siunitx

Following up this answer, I would like to create a \num-based command that nullifies the white space from the left side of a binary operator and keeps the space on its right side.

In other words, I need to keep the minus sign, in the first line of the example below, aligned with the page margin while having a white space between it and number 3 as that surrounding the minus sign of the second line.

enter image description here

\documentclass{article}

\usepackage{siunitx}
\usepackage[showframe]{geometry}

\ExplSyntaxOn

\NewExpandableDocumentCommand{\snum}{O{}m}
{
    \mathbin
    {
        \fp_compare:nTF { #2 >= 0 }
        { + }
        { - }
    }
    \num[#1]{ \fp_eval:n { abs(#2) } }
}

\ExplSyntaxOff

\parindent=0pt

\begin{document}
    \def\numb{-3}
    
    $\snum{\numb}$\\
    ${}\snum{\numb}$
\end{document}

Best Answer

The macro \mynum, defined in this answer, may be of interest to you.

enter image description here

\documentclass{article}
\usepackage{showframe} % draw framelines around text block
\setlength\parindent{0pt}
\usepackage{siunitx} % for '\num' macro
\usepackage{amsmath} % for '\ensuremath' macro

\newcommand\mynum[1]{\ensuremath{\mskip-\medmuskip{}\num[retain-explicit-plus]{#1}}}

\begin{document}
\obeylines % just for this example
\num{-3}
\num[retain-explicit-plus]{+8}
$\mskip-\medmuskip{}-3$
\mynum{-3}
\mynum{+8}
\end{document}
Related Question