Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 does not seem to be appropriate for my document because I have more than just one html listing.

share|improve this question

migrated from 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

3 Answers 3

up vote 11 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 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.