Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
2  
This sounds like a job for the listings package, really. Could you post an example of your code? –  Joseph Wright Oct 6 '10 at 21:10
    
So, the problem is actually your editor (Kile) that for some reason messes with your tabs? –  Caramdir Oct 6 '10 at 21:44

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
Does this mean that latex ignores tab characters? –  ArtB Mar 22 at 22:05
    
@ArtB In normal text, TeX treats all whitespace (spaces, tabs, newlines) exactly the same. –  Caramdir Mar 27 at 22:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.