I have several environments for listings such as:

 \renewcommand*{\lstlistingname}{Code (JavaScript)}  

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}  


Currently I use:

\begin{JavaScript}[caption=example, label=code:Example, style=numbers]  
  alert("hello world");  

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:

   \renewcommand*{\lstlistingname}{Code (JavaScript)}   

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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