# Adding arrows to each term of an equation

\documentclass{beamer}
\usepackage[all]{xy}
\begin{document}
\section{Introduction}
\xymatrix{
&*+{\sum_{i=n}^m {i^2}} &*+{+}&*+{p} \\
& {\bullet} & D \ar[ul] && f \ar[ul]
}
\end{document}


i want to reduce the spacing between terms and different colors for arrows.i'm using kile under ubuntu.is it necessary to include tiKZ ,if so explain me

-
Terms where? arrows where? Please add a minimal working example (MWE) that illustrates your problem. – Matthew Leingang Apr 13 '11 at 14:10
Thanks for making that much more clear. You're more likely to get an answer now! – Matthew Leingang Apr 13 '11 at 14:27

I would recommend using tikz rather than xy. Here's how I would think of implementing this. (The following was adapted from this TeXample.net example, with an eye towards code abstraction; the picture in the original is also fancier.)

Preamble:

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows}

% Define how TiKZ will draw the nodes
\tikzset{mathterm/.style={draw=black,fill=white,rectangle,anchor=base}}
\tikzstyle{every picture}+=[remember picture]
\everymath{\displaystyle}

\makeatletter

% Designate a term in a math environment to point to
% Syntax: \mathterm[node label]{some math}
\newcommand\mathterm[2][]{%
\tikz [baseline] { \node [mathterm] (#1) {$#2$}; }}

% A command to draw an arrow from the current position to a labelled math term
% Default color=black, default arrow head=stealth
% Syntax: \indicate[color]{term to point to}[path options]
\newcommand\indicate[2][black]{%
\tikz [baseline] \node [inner sep=0pt,anchor=base] (i#2) {\vphantom|};
\@ifnextchar[{\@indicateopts{#1}{#2}}{\@indicatenoopts{#1}{#2}}}
\def\@indicatenoopts#1#2{%
{\color{#1} \tikz[overlay] \path[line width=1pt,draw=#1,-stealth] (i#2) edge (#2);}}
\def\@indicateopts#1#2[#3]{%
{\color{#1} \tikz[overlay] \path[line width=1pt,draw=#1,-stealth] (i#2) [#3] edge (#2);}}

\makeatother


Document body:

\begin{gather}
\mathterm[t1]{   \sum_{i=n}^m {i^2}   }   +
\mathterm[t2]{   \int_0^t \mathrm d\:\!\tau   }   +
\Gamma\bigl(n + \tfrac{1}{2}\bigr)   +
\mathterm[t3]{   \tfrac{1}{2}m\|\mathbf v\|^2   }
\end{gather}

\begin{itemize}
\item  Power series \indicate[red]{t1}[out=0,in=-75]
\item  Definite integral \indicate[blue]{t2}[out=0,in=-90]
\item  Non-relativistic kinetic energy \indicate{t3}[out=0,in=-90]
\end{itemize}


Result:

-
environment gather undefined – user4852 Apr 13 '11 at 16:23
Ah, sorry, you must also \usepackage{amsmath}. I'll add that to the pre-amble above. Note that gather is just one of my preferred choices of math environments; any other displayed math environment would do here, although the AMS ones are better as a rule. – Niel de Beaudrap Apr 13 '11 at 16:25
oh..again problem.arrows are not visible.i'm using kile under ubuntu – user4852 Apr 13 '11 at 16:37
@Niel: if instead of using the <pre> tag, you use the code environment provided by markdown (indent all your code by 4 extra spaces, or select them and hit the "code symbol" in the editor), you can benefit from syntax highlighting for your code example. – Willie Wong Apr 13 '11 at 18:32
@user4852: if you say so — the editor really shouldn't make any difference. – Niel de Beaudrap Apr 14 '11 at 7:38

An example with overlays

\documentclass{beamer}
\usepackage{amsmath}
\usepackage{pst-node}
\psset{arrowscale=2,arrows=->}
\def\VPh{\vphantom{\displaystyle\sum_{i=n}^m {i^2}}}
\def\psBox#1#2{\psframebox[fillcolor=#1,fillstyle=solid]{\VPh\displaystyle#2}}

\begin{document}

\begin{frame}{Foo}{bar}
$\only<1->{\rnode{t1}{\psBox{green!30}{\sum_{i=n}^m {i^2}}} +} \only<2->{\rnode{t2}{\psBox{blue!30}{\int_0^t \mathrm d\:\!\tau}} + \Gamma\bigl(n +\frac{1}{2}\bigr)+ } \only<3->{\rnode{t3}{\psBox{red!30}{\frac{1}{2}m\|\mathbf v\|^2}}}$

\begin{itemize}[<+->]
\item  Power \rnode[rc]{T1}{series} \nccurve[angleB=-75]{T1}{t1}
\item  Definite \rnode[rc]{T2}{integral}\nccurve[angleB=-90]{T2}{t2}
\item  Non-relativistic kinetic \rnode[rc]{T3}{energy}\nccurve[angleB=-90]{T3}{t3}
\end{itemize}
\end{frame}

\end{document}


-

If you like to use Xy-pic, simply omit the "+" :

\documentclass{beamer}
\usepackage[all]{xy}
\begin{document}
\section{Introduction}
\xymatrix{
& *{\sum_{i=n}^m {i^2}} & + & *{p} \\
& {\bullet} & D \ar@[red][ul] && f \ar@[blue][ul]
}
\end{document}


Indeed, the construction *{object} put the object without margin, the "+" add the margin. In fact, *+{object} is equivalent to {object} and even (if the object doesn't start with a macro) simply object .

For the color, simply use the @[color] modifier, for more about color, see xyref p.30.

Another solution is to define directly "longarrow", for example :

\documentclass{beamer}
\usepackage[all]{xy}
\newdir{l}{!/1.5ex/@{-}*:(1,0)@^{>}*:(1,0)@_{>}}
\newdir{m}{!/0.5ex/@{-}*@{-}}
\def\longar@[#1][#2]{\ar@[#1]@{-l}[#2] \ar@[#1]@{m-m}[#2]}
\begin{document}
\section{Introduction}
\xymatrix{
&{\sum_{i=n}^m {i^2}} &+&p \\
& {\bullet} & D \longar@[red][ul] && f \longar@[blue][ul]
}
\end{document}

-
color is not changing – user4852 Apr 14 '11 at 1:25
@user4852 short way : normally it does. Long way, if you want color you have to use the package color but the beamer class (at least in recent version) automatically load this package. – Matsaya Apr 14 '11 at 15:58