[Tex/LaTex] LaTeX ignoring tabs in verbatim

kileverbatim

I need to write a whole bunch of pseudo code and I got annoyed using all the "\ >\=" with the \begin{tabbing} command, so I decided to use \begin{verbatim} instead. This was working fine for me until I got to a point in which I had to indent 4 times in a row. When I get to 4 tabs in a row it puts the "character" >> at the beginning of my line and then when I generate the pdf it is not indented at all. How do I get latex to stop reformatting my lines when I use verbatim?

\begin{verbatim}

makeClusters(nodes[n], k)
{
distances [n][n]
clusters[k]
seeds[k]
numseeds=0
maxd=0
node1
node2

if(k=0)
  return

if(k=1)
  Put all nodes in one cluster and return

for i=0 to  n-1
  for j=0 to n-1
    distances[i][j] = d(nodes[i],nodes[j])
    if(distances[i][j]>maxd)
      maxd=distances[i][j]
      node1=i
      node2=j

seeds[0]=node1
seeds[1]=node2
numseeds +=2

while(numseeds < k)
  minNode
  maxmin=0

  for i=0 to n-1
    for j=0 to numseeds-1
      mindis=maxd
      if(distances[i][seeds[j]]<mindis)
    mindis=distances[i][seeds[j]]

    if(mindis>maxmin)
      maxmin=mindis
      minNode=i

  seeds[numseeds]=minNode
  numseeds++

for i=0 to n-1
  mindis=maxd
  clust
  if(not inCluster(node[i]))
    for j=0 to n-1
      if(inCluster(node[j]) and distances[i][j]<mindis)
    mindis=distances[i][j]
    clust=cluster(node[j])
    add2cluster(clusters[clust],node[i]


}
\end{verbatim}

As you can see in this unnecessarily large example after 2 of my if statements the lines have been unindented, these are the locations where I used 4 tabs and have copy pasted this
section directly out of Kile.

Best Answer

The problem is some rather strange (to me) behavior of Kile: When you press the [Tab] key, it inserts two spaces into the document instead of a tab. But it also replaces any 8 consecutive spaces by a tab character. This obviously completely messes up any formatting.

To fix this problem either use an editor with sane default settings or go to "Settings" > "Editing" > "General" and check "Insert spaces instead of tabulators" (or fiddle around with the settings under "Indentation").

NB: As Joseph mentioned, the listings package will give you much nicer code listings.

Related Question