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 have this basic question. How can use arguments with listings? I tried this and it doesn't work:

\lstnewenvironment{cor}[2][] 
{\linerange{#1-#2},\lstset{language=[Sharp]C,,basicstyle=\scriptsize, 
 showspaces=false,showtabs=false,,breaklines=true,showstringspaces=false,
breakatwhitespace=true  }}
{}

and then I used it in the following way:

\begin{cor}{2}{3}
\end{cor}
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted
\documentclass{minimal}
\usepackage{listings}    
\lstnewenvironment{X}[2]{%
    \lstset{language=[Sharp]C,linerange=#1-#2}}{}
\begin{document}
\begin{X}{1}{1}
 class A{static void Main(){}}
\end{X}
\end{document}
share|improve this answer
    
@voodoomsr, please try this minimal code. If you are not satisfied with it, let me know. I will modify until it suits your need. :-) –  xport Jan 6 '11 at 7:14
    
thank you, that looks nice, and suit my needs perfectly –  mjsr Jan 6 '11 at 8:04
    
@voodoomsr, don't forget to give a green check mark plus upvote :-) –  xport Jan 6 '11 at 8:05
    
one more question i'm having serious problem understanding well the syntax of latex, i now a lot of programming languages but latex still it see for me a little cryptic, do you know what is the key to fully understand it? –  mjsr Jan 6 '11 at 8:08
    
@voodoomsr, you should create a new question in a new topic and not in this topic. This is the rule to avoid cluttering this site. :-) –  xport Jan 6 '11 at 8:13
show 7 more comments

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.