Problem with creating a newenvironment in LaTeX

Posted by Andreas Grech on Stack Overflow See other posts from Stack Overflow or by Andreas Grech
Published on 2010-04-09T10:56:05Z Indexed on 2010/04/09 12:03 UTC
Read the original article Hit count: 504

Filed under:
|

I am trying to implement this new environment in LaTeX:

\newenvironment{javacode}[2]
{\begin{lstlisting}[language=java, label=#1, caption=#2]}
{\end{lstlisting}}

And then use it like such:

\begin{javacode}{c}{some code}
int x = 5;
\end{javacode}

But I am getting the following error:

Overfull \hbox (6.0pt too wide) in paragraph at lines 6--6
[][][][][][][] 
[1] [2]) [3])
*

Can anyone help as regards fixing this problem?

[Update]

I tried it doing it like Red-nosed unicorn instructed, and it worked correctly.

But now I tried adding a \begin{singlespace} like such:

\lstnewenvironment{javacode}[2]
{
\begin{singlespace}
\lstset{language=java, label=#1, caption=#2}}
{
\end{singlespace}
}

And I got the same error:

Overfull \hbox (6.0pt too wide) in paragraph at lines 6--6
[][][][][][][] 
[1]) [2] [3])
*

© Stack Overflow or respective owner

Related posts about latex

Related posts about newenvironment