1

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}
Werner
  • 603,163
mjsr
  • 3,425

1 Answers1

5
\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}
Display Name
  • 46,933
  • 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 06 '11 at 08: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. :-) – Display Name Jan 06 '11 at 08:13
  • @xport, ok im gonna creating right away – mjsr Jan 06 '11 at 08:31
  • @xport: It's great that you asked voodoomsr to ask a new question. It worked! However, please do try and post minimal examples and short screenshots. Moreover, usually one should wait a day before accepting an answer, so you should wait with such comments. (Upvoting can of couse be done immediately.) – Hendrik Vogt Jan 06 '11 at 10:20
  • @Hendrik, the answer has been normalized. :-) – Display Name Jan 06 '11 at 11:18
  • @voodoomsr If this really helped you, you should not forget to upvote: It's alway a good way to thank the answerer. – chl Jan 06 '11 at 14:16
  • @xport: Please try and find a good intermediate length. Omitting linebreaks only makes the code obscure. – Hendrik Vogt Jan 06 '11 at 14:18
  • @xport: As I said, don't overdo making thinks short. MyListing was a much better name for the new environment than X. – Hendrik Vogt Jan 07 '11 at 14:15