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 can't manage to add linenumbers left of the boxes. Can anybody help me?

\documentclass{article}

\begin{document}

\fbox{\fbox{

\begin{minipage}{0.8\linewidth}

\textbf{def} mapper (key, value):

\hspace{7mm}\textbf{for} word \textbf{in} value.split():

\hspace{14mm}\textbf{yield} word, 1\\

\textbf{def} reducer (key , values):

\hspace{7mm}\textbf{yield} key, sum(values)\\


\textbf{if} name == "main":

\hspace{7mm}\textbf{import} dumbo

\hspace{7mm}dumbo.run (mapper, reducer, combiner=reducer )

\end{minipage}

}}

\end{document}

Thanks

share|improve this question
    
I think this should probably be retitled? Not sure to what, though... perhaps "how to do line-numbered code listings?" –  SamB Dec 25 '10 at 18:21
    
Btw, @user2678, I would suggest you fill in some sort of mnemonic in your profile -- whether it be some form of your name or just a pseudonym -- which make you look more like a particular person and less like some random luser. (Registering an account was a good start, though.) –  SamB Dec 25 '10 at 18:30
add comment

1 Answer

up vote 4 down vote accepted
\documentclass{article}
\usepackage{listings}

\lstset{numbers=left,numberstyle=\tiny,numbersep=1em,
  morekeywords={def,for,yield,if,import},
  keywordstyle=\bfseries,frame=TLBR}
\begin{document}


\begin{lstlisting}
def mapper (key, value):
  for word in value.split():
    yield word, 1
def reducer (key , values):
  yield key, sum(values)
  if name == "main":
    import dumbo
    dumbo.run (mapper, reducer, combiner=reducer )
\end{lstlisting}

\end{document}
share|improve this answer
    
Thanks a lot :D –  Drareeg Dec 25 '10 at 18:00
add comment

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.