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?

| improve this question | | | | |

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.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.