\RequirePackage{pgf}
\RequirePackage{xparse}

\def\NumberLineSetupSaved{}

\ExplSyntaxOn
\keys_define:nn {NumberLine} {
  xmin .code:n = \def\XMIN{#1},
  xmax .code:n = \def\XMAX{#1}
}
\DeclareDocumentCommand\NumberLineSetup{m}{
\keys_set_known:nn{NumberLine}{#1}
\def\NumberLineSetupSaved{#1}
}
\ExplSyntaxOff

\DeclareDocumentCommand\NumberLine { O{} m } {
\NumberLineSetup{#1}%
\pgfmathsetmacro\STEP{(\XMAX-\XMIN)/10}%
\pgfmathsetmacro\NINF{\XMIN-0.5*\STEP}%
\pgfmathsetmacro\PINF{\XMAX+0.5*\STEP}%
\pgfmathsetmacro\NEXT{\XMIN+\STEP}%
\pgfmathifisint{\NEXT}{\def\NEXT{\pgfretval}}{}%
\typeout{NumberLine: XMIN=\XMIN,XMAX=\XMAX,STEP=\STEP,NINF=\NINF,PINF=\PINF}%
%
\def\ClosedDot##1{ \filldraw[ultra thick,fill=black,draw=black] (##1,0) circle ({0.15*\STEP}); }%
\def\OpenDot##1{   \filldraw[ultra thick,fill=white,draw=black] (##1,0) circle ({0.15*\STEP}); }%
\def\LeftRay##1{   \draw[line width=2pt,<- ] (\NINF,0) -- (##1,  0); }%
\def\RightRay##1{  \draw[line width=2pt, ->] (##1,  0) -- (\PINF,0); }%
\def\FullLine{     \draw[line width=2pt,<->] (\NINF,0) -- (\PINF,0); }%
\def\LineSeg##1##2{\draw[line width=2pt    ] (##1,  0) -- (##2,  0); }%
%
\def\IntervalNegInfToClosed##1{    \LeftRay{##1}      \ClosedDot{##1} }%
\def\IntervalNegInfToOpen##1{      \LeftRay{##1}      \OpenDot{##1}   }%
\def\IntervalClosedToPosInf##1{    \RightRay{##1}     \ClosedDot{##1} }%
\def\IntervalOpenToPosInf##1{      \RightRay{##1}     \OpenDot{##1}   }%
\def\IntervalOpenToOpen##1##2{     \LineSeg{##1}{##2} \OpenDot{##1}   \OpenDot{##2}   }%
\def\IntervalOpenToClosed##1##2{   \LineSeg{##1}{##2} \OpenDot{##1}   \ClosedDot{##2} }%
\def\IntervalClosedToOpen##1##2{   \LineSeg{##1}{##2} \ClosedDot{##1} \OpenDot{##2}   }%
\def\IntervalClosedToClosed##1##2{ \LineSeg{##1}{##2} \ClosedDot{##1} \ClosedDot{##2} }%
%
\begin{tikzpicture}[scale={1/\STEP},baseline=0]
	\draw[<->] (\NINF,0) -- (\PINF,0);
	\foreach \x in { \XMIN,\NEXT,...,\XMAX } {
	        \draw (\x,{0.15*\STEP}) -- (\x,{-0.15*\STEP}) node[below] { \tiny \x };
	}
	#2
\end{tikzpicture}%
}
