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{lstlisting}[language = Java , frame = trBL , escapeinside={(*@}{@*)}, escapechar=\%]

are the same

Is there a way to achieve this?


1 Answer 1


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

    {\lstset{language = Java , frame = trBL , escapeinside={(*@}{@*)}, escapechar=\%}}
/* HelloWorld.java

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


enter image description here

Hello world Java code taken from here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .