# How to keep whitepaces between words in algorithm

I am new to LaTeX. When I tried to write an algorithm all spaces between words get removed after \gets. See the image.

\begin{algorithm}
\caption{Filtering lexicon file}
\label{algo1}
\begin{algorithmic}[1]
\State $Lex$ \gets read the whole lexicon file.$\end{algorithmic} \end{algorithm}  How to keep the spaces between words "read the whole lexicon file". Thank you. • You get errors from that input, because \gets is a math symbol. Adding a trailing $ is not the solution. Maybe $\mathit{Lex}\gets$ read the whole lexicon file. – egreg Mar 23 at 16:13
• @egreg post it as a answer. $\mathit{Lex}\gets$ read the whole lexicon file. is the correct answer. I will make it my answer. – Nahid Hossain Shihab Mar 23 at 16:20
• @NahidHossain I believe you should extend the example, so that it's possible to give advice also for other parts of the algorithm. – egreg Mar 23 at 16:21

I am not saying these are more correct but the simplest is to remove the $as per line 1 but that will change the font upright so see some alternatives with italics \documentclass[10pt]{report} \usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx \usepackage{algorithm} \usepackage[utf8x]{inputenc} \usepackage{amsmath,graphicx,subfigure} \begin{document} \begin{algorithm} \caption{Filtering lexicon file} \label{algo1} \begin{algorithmic}[1] \State$Lex \gets $read the whole lexicon file. \State$Lex \gets~read~the~whole~lexicon~file.$\State$Lex \gets \textit{read the whole lexicon file.}$\State$Lex \gets $\textit {read the whole lexicon file.} \State$Lex \gets ${\itshape read the whole lexicon file.} % as recommended by Barbara Beeton This switch should be bound \State$Lex \gets $read the whole lexicon file. % note none of the above have affected this line here is another line \end{algorithmic} and another \end{algorithm}  and another \end{document} • While it may work okay here, i.e., get turned off at the end of the line (I'm not sure, and can't test), an "ungrouped" \itshape will persist in other situations, and should be used with caution. – barbara beeton Mar 23 at 17:05 • @barbarabeeton I am no TeXnician so accept that all my suggestions could be wrong its just that in my editor(s) they worked as per their fonts, I accept they may likely behave badly in other engines/locales – KJO Mar 23 at 17:07 • If I were trying to test the persistence, I would repeat at the end the first instance of the test line (the one with no style change after the second $) to make sure it doesn't become italic. (Sorry for the noise; I would have tested if I could, but have no TeX installation available.) – barbara beeton Mar 23 at 17:19
• Given that you've determined that it persists, it would be best to add braces to that step -- {\itshape ... }. Font "switches" like \itshape are intended to be used in localized situations. (An environment like algorithmic is almost always defined as a local group.) – barbara beeton Mar 23 at 17:30