I'm trying to define a new environment for my own needs, and I'm trying to use the lstlisting environment from the listings package in the definition of my new environment, but whenever I try to compile my document with this definition nothing happens. I don't get any errors, but the document also doesn't recompile. When I remove the lstlisting environment from my definition however the document compiles without any issues.
In more detail:
\documentclass{article}
\usepackage{listings}
\newenvironment{java}
{
\ttfamily
\begin{lstlisting}[language=java]
}
{
\end{lstlisting}
\sffamily
}
\begin{document}
\begin{java}
for (int i = 0; i < 100; i++){
System.out.println("This is a Test!");
}
\end{java}
\end{document}
When I try to compile this nothing happens.
\documentclass{article}
\usepackage{listings}
\newenvironment{java}
{
\ttfamily
\begin{center}
}
{
\end{center}
\sffamily
}
\begin{document}
\begin{java}
for (int i = 0; i < 100; i++){
System.out.println("This is a Test!");
}
\end{java}
\end{document}
This works perfectly fine and compiles without issues, though it (obviously) doesn't do what I want it to do.
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=java]
for (int i = 0; i < 100; i++){
System.out.println("This is a Test!");
}
\end{listing}
\end{document}
This works fine too, except it also doesn't do what I need.
texdoc listings– David Carlisle Oct 16 '23 at 15:09\lstnewenvironmentworked! – Daaaaaaaavid Oct 16 '23 at 15:15