# Define an environment that by default load some options

Is there a way to define a new listings environment with some listings options by default?

For example, I am hoping to define a new environment, say myenv, such that

\begin{myenv}
\end{myenv}


and

\begin{lstlisting}[language = Java , frame = trBL , escapeinside={(*@}{@*)}, escapechar=\%]
\end{lstlisting}


are the same

Is there a way to achieve this?

## 1 Answer

Defining new verbatim environments is different from defining normal environment. listings already provides \lstnewenvironment for that

\documentclass{article}
\usepackage{listings}
\lstnewenvironment{myenv}
{\lstset{language = Java , frame = trBL , escapeinside={(*@}{@*)}, escapechar=\%}}
{}
\begin{document}
\begin{myenv}

/* HelloWorld.java
*/

public class HelloWorld
{
public static void main(String[] args) {
System.out.println("Hello World!");
}
}


\end{myenv}
\end{document}


Hello world Java code taken from here.