TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my document I have used:


to rename my lstlistings titles.

The problem is that now I want to add a different kind of code,with lstinputlisting but I want it to have another caption below. Is there any way somehow to define a new listings environment and apply again the commands above to it?

For example ideally using two new commands \c_lstinputlisting{testc.c}, and \cpp_lstinputlisting{testc.cpp} would give two different caption names like

C Code 1.x


C++ Code 1.x

In case I am not clear, I am not talking about the caption itself, but what goes before the caption that is the general name of the caption name. Without editing it is the default

Listing 1.x

share|improve this question
Can you please expand a little on the way this is supposed to look like? It sounds as if you are mistaking the listing name for a caption but maybe I get you wrong. – Max Jan 5 '13 at 11:20
Hi Max, yes sorry this was a mistake I meant the caption. Changed it, and also added some more stuff to make the question clearer. – entropiece Jan 5 '13 at 11:48
@Vassilis Do you also need to produce distinct "List of C code", "List of C++ code" and so on? This would be more difficult. – egreg Jan 5 '13 at 11:56
@egreg I don't care much for that now, I mainly want to have two different listing environments with two different caption names. Of course it would be great if they could be two different lists in the toc but this is not my main priority. – entropiece Jan 5 '13 at 11:58
up vote 3 down vote accepted

You can define the commands so that they change locally the meanings of the involved control sequences:


  \renewcommand\lstlistingname{C file}%
    % <other specific options>

  \renewcommand\lstlistingname{C++ file}%
    % <other specific options>



share|improve this answer
That works fine. Thanks! – entropiece Jan 5 '13 at 13:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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