# lstnewenvironment and include

I have several environments for listings such as:

\lstnewenvironment{JavaScript}[1][]
{
\renewcommand*{\lstlistingname}{Code (JavaScript)}
\lstset{#1,language=Java}
}
{
}


This works perfect but I would like to be able to include the code instead of inserting like the snippet below:

\lstinputlisting[language=Java, label=myLabel,caption=myCaption]{includes/myFile.js}


Edit:

Currently I use:

\begin{JavaScript}[caption=example, label=code:Example, style=numbers]
\end{JavaScript}


I would like to have an external file such as example.js and show it in my PDF. I can do that with:

\lstinputlisting[language=Java, label=code:Example,caption=example]{includes/example.js}


but the \begin{JavaScript} will show "Code (JavaScript) 1.1: Example" instead of "Code 1.1: Example". I want to be able to use the first but link an external file as done in the second :)

• Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. – Marco Daniel Jun 10 '13 at 8:54
• Sorry but I can't read any question/issue? – Marco Daniel Jun 10 '13 at 8:55
• Welcome to TeX.SX! Do you mean you want to write the Javascript code in your TeX file? – mafp Jun 10 '13 at 9:07
• I edited the post to make it more clear... – Alban_T Jun 10 '13 at 9:42

For your environment you changed \lstlistingname If you want to do the same for your input you can define an own input command:

\newcommand\javainput[2][]{%
\bgroup%
\renewcommand*{\lstlistingname}{Code (JavaScript)}
\lstinputlisting[language=Java,#1]{#2}
\egroup}