# Danish character encoding broken with nested lstlisting

In order to help TexStudio with its intellisense, I wrapped a \lstnewenvironment inside a \newenvironment. This allowed TeXStudio to properly highlight the newly defined environment.

However, when I do that and procede to write a danish character (æøå) then it will fail, saying the inputenc package cannot handle the character.

\documentclass{article}
\usepackage{listings}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\lstnewenvironment{XJavaCode}[2]
{\lstset{language=Java, caption=#1, label=#2}}
{}

\newenvironment{JavaCode}[2]
{\begin{XJavaCode}{#1}{#2}}
{\end{XJavaCode}}

\begin{document}
\begin{JavaCode}{caption}{label}
ASD
\end{JavaCode}
æøå
\end{document}

• It doesn't compile even if you remove the Danish characters. – Tiuri Aug 28 '17 at 20:15
• See e.g. here for an explanation. In short: lstlisting doesn't work properly within an user-defined environment, that's why \lstnewenvironment exists and why you should not wrap it inside another environment definition. – Tiuri Aug 28 '17 at 20:19
• you can not include verbatim style environments in definitions in this way, that is precisely the reason why listings provides \lstnewenvironment as you can not use \newenvironment – David Carlisle Aug 28 '17 at 20:23
• Alright so there is no solution to this? Seems a shame, as TeXStudio doesn't handle the \lstnewenvironment very well, but that's on them I guess. – LukasPJ Aug 28 '17 at 20:55