I am trying to replicate the idea of sum and difference of real numbers on the number line and have been successful in some way. For example, the code:
\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
%\usepackage{array,multicol}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=0.75cm,>=stealth]
\draw[<->] (-5,0)--(5,0);
\foreach \x in {-4,...,4}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\node[below] at (-5,-5pt) {$\ldots$};
\node[below] at (5,-5pt) {$\ldots$};
\fill (3,0) circle (2pt);
\fill (-4,0) circle (2pt);
\draw[<-,out=45,in=135,color=blue] (-4,0) to (-3,0) to (-2,0) to (-1,0) to (0,0) to (1,0) to (2,0) to (3,0);
\node[color=OrangeRed] at (3,-0.75) {\small Start};
\node[color=Cerulean] at (-4,-0.75) {\small End};
\node at (-0.5,0.5) {\small Move 7 units to the \emph{left}};
%\draw[->,shorten >=5pt,shorten <=5pt,out=45,in=135,distance=0.5cm] (0,0) to (1,0);
\end{tikzpicture}
\end{document}
yeilds:

What I tried to do now was to create a \newcommand in which one can indicate a moving arrow to the right as a sum and left as a difference. This is what I have so far:
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\newcommand{\addsubnumline}[3]{%
\begin{tikzpicture}[out=45,in=135,relative,>=stealth]
\draw[<->] (-5,0)--(5,0);
\foreach \x in {-4,...,4}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\fill (#1,0) circle (2pt);
\fill (#2,0) circle (2pt);
\foreach \i in {#1,...,#2}% Thinking on using [remember=\i as \lasti (initially #1)]
{
\draw[#3] (\i,0) to (\i+1,0);% Try a \breakforeach but don't know
}
\end{tikzpicture}}
\begin{document}
\addsubnumline{-4}{2}{->,color=MidnightBlue}
\end{document}
Which yields:

What I am trying to achieve is the first image but within one command. I know that my error in the code above would be where \draw[#3] (\i,0) to (\i+1,0); is found as the \i+1 gives the extra jump. The other problem would be to determine the text in the middle of the counting and that it automatically determines to the right or left. This can be probably done with a \if and \else statement probably. Note also that in the first example, the arrows are not shown for every jump and in the second yes. I like the first one better. Any assistance it the matter will be highly appreciated.


\draw[<->] (-5,0)--(5,0);look something like\draw[<->] (#1-1.5,0)--(#2+1.5,0);> Would that be feasible? I guess if the diagram is too large then a scale mechanism can be put into place automatically for aesthetics only. Then why would the expression be wrong if you use only + or - numbers. – azetina May 23 '12 at 19:10\addsubnumlinetoright{-3}{-1}{->,color=MidnightBlue}the text doesn't seem to be centered relative to the units moved from -3 to -1. Why? – azetina May 23 '12 at 19:41\numexpr. It's more easy to use\pgfmath. see update 3 – Alain Matthes May 23 '12 at 20:03\number\numexpr .....\relaxso that I can use it in other cases where I need calculations. Much appreciated. Merci beaucoup. Theshorten >=2ptcreates the effect of the arrow about reaching the point right? – azetina May 24 '12 at 14:43shorten >=2pt, now about\numexprI forgot that it's only possible to use integers and for example5/3 =1. It's why the result was wrong when I wrote #1/2 etc. – Alain Matthes May 24 '12 at 16:14