# How to write sentences in an algorithm in latex?

Hi I am trying to write an algorithm which looks something like the image below:

I was wondering how to write the "Step 1 (Update)" and also the rest of the line which says "When an edge e...." should all that be inside the math symbols i.e..  ??

I am kinda new to latex. Thanks for the help!

Also I was wondering what is the difference between algorithm and algorithmic?

-
Welcome to TeX.SX! – Heiko Oberdiek Apr 19 '14 at 19:48
See section 1 of the algorithms bundle documentation: algorithm is to algorithmic as table is to tabular. – Ian Thompson Apr 19 '14 at 20:34
Awesome! Thanks @IanThompson – Yathi Apr 19 '14 at 21:05

Here you go:

\documentclass{article}
\usepackage{graphicx}
\newcommand\smallarrowover[1]{\scalebox{.5}{$\overrightarrow{#1}$}}

\begin{document}

\noindent
\underline{\sf Step 1 (Update):} When an edge $e=\{u,v\}\in E[G]$ arrives, update each $Z_{\smallarrowover{ab}}$ w.r.t.
$$Z_{\smallarrowover{ab}}(G)\leftarrow Z_{\smallarrowover{ab}}+\mathcal M_{\smallarrowover{ab}}(u,v)+\mathcal M_{\smallarrowover{ab}}(v,u).$$

\end{document}


This is the result:

Initially I used \vec{ab} for the arrow over ab, but that did not stretch, and putting \overrightarrow{ab} in the subscripts did not make it smaller, as you want. So I defined a new command, which needs the \graphicx package. Also, you might not need the \noindent I have at the beginning, depending on what you have before it. I put it there so the whole thing would fit on one line.

P.S. I have no experience with the algorithm or algorithmic environments.

-
I think the OP was probably asking about the difference between the algorithm and algorithmic environments. – Ian Thompson Apr 19 '14 at 20:12
Yes, I meant the \begin{algorithm} and \begin{algorithmic} commands – Yathi Apr 19 '14 at 20:15
Also when I try the above code I am getting: 'Missing $inserted. <inserted text>$ l.109 ...ives, update each $Z_{\smallarrowover{ab} }$ w.r.t. ' – Yathi Apr 19 '14 at 20:16
@Yathi what document class are you using, and which packages do you have loaded? – jlv Apr 19 '14 at 20:19
Hi.. This is the start of my report: \documentclass{acm_proc_article-sp} \usepackage{amsmath} \usepackage{algorithm} \usepackage{graphicx} \newcommand\smallarrowover[1]{\scalebox{.5}{\overrightarrow{#1}}} \usepackage[noend]{algpseudocode} \begin{document} – Yathi Apr 19 '14 at 20:22