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

I would like to specify two different lstset settings in one latex file: one for java code, one for html. Is this somehow possible?

The solution of http://stackoverflow.com/questions/2654810/how-to-reset-lstset-settings-for-listings does not seem to be appropriate for my document because I have more than just one html listing.

share|improve this question

migrated from stackoverflow.com Aug 11 '11 at 15:13

This question came from our site for professional and enthusiast programmers.

high possible duplicate detected... – xport Aug 11 '11 at 18:51
up vote 12 down vote accepted

Every lstlistings block can have its own formatting commands. So:






If you want to use two distinct listings and resetting the listings like this manually is a hassle, just create some new environments with lstnewenvironment for example:


page 40 of the listings manual has the details

share|improve this answer

I use a style definition for every language, here is an example for makefiles:

    identifierstyle= %plain identifiers for make

To include this style, I use

    caption={[Makefile]Makefile, foobar},

Other styles have another value for language(and other settings for keywords, tabsizes etc.)

share|improve this answer





enter image description here

share|improve this answer
How can I combine the flexibility of your answer with \lstnewenvironment, such that I can keep my custom environment, yet switch the languages e.g. \begin{customenv}[language=bash] and have another one like \begin{customenv}[language=java] and have another one like \begin{customenv} that defaults to [language=java] or just plain without syntax highlighting? – macmadness86 Feb 10 '15 at 14:52

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.