0

This question already has an answer here:

\documentclass{article}
\usepackage{listings}

\newenvironment{hello}{\begin{lstlisting}[language=sh]}{\end{lstlisting}}

\begin{document}

\begin{hello}
ls
\end{hello}

\end{document}

The code cannot be compiled by xelatex, the compiler is hung.

What's the root cause?

marked as duplicate by egreg environments Apr 5 '15 at 12:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

listings is essentially a verbatim environment that turns off normal latex processing, in particular \end{hello} does not end the environment.

The package has facilities for defining custom environments, see section 4.16 of the listings manual.

\documentclass{article}
\usepackage{listings}

\lstnewenvironment{hello}{\lstset{language=sh}}{}

\begin{document}

\begin{hello}
ls
\end{hello}

\end{document}

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