# Luacode in NewDocumentEnvironment problem

I want to put some systematic code at beginning and at the end of a luacode environment.

Why this doesn't work.

\documentclass{article}

\usepackage{xparse,luacode}

\NewDocumentEnvironment{LTG}{%
\begin{luacode}
}{%
\end{luacode}
}

\begin{document}

essai

\end{document}


\NewDocumentEnvironment needs at least an empty {} argument specifier -- this is missing in the OP.

The classical \newenvironment does not require the classical argument specifier brackets [] at all, it can be omitted then.

The error here would occur with basically any code following the environment name bracket, i.e. {LTG}, making xparse believe, that \begin{luacode} is the argument specifier, which must fail here of course.

\documentclass{article}

\usepackage{xparse,luacode}

\NewDocumentEnvironment{LTG}{}{%
\begin{luacode}
}{%
\end{luacode}
}

\begin{document}

essai

\end{document}

• Please don't ask whether the luacode inside such an environment is useful at all ;-) – user31729 May 16 '16 at 18:09