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

Is it possible to unindent the code inserted using \lstinputlisting? In particular I'd like to be able to unindent by a fixed amount of whitespace.

I have to write a relation on a OS scripting course and I'd like to include the sources of some bash scripts. I noticed that gobble is ignored by \lstinputlisting but I'd like to avoid to copy-paste the code and unindent it by hand. Is there any solution for this?

share|improve this question
Well, as the documentation states, gobble has no effect when using lstinputlisting. Is it impractical to unindent by hand? Do you have a large code section, or lots of files to be unindented? In any event, you may want to give a try to the minted package. – guillem Nov 19 '12 at 15:11
@guillem No, I could unindent by hand but they are about 600 lines of code and I'd like to avoid unindenting too many blocks by hand. I'll give a try to the minted package. – Bakuriu Nov 19 '12 at 15:48
Just to add some information here, the gobble option of minted package works well on \inputminted[gobble=n,...]{language}{file}. It eliminates the first n characters, even if they are not whitespaces. – guillem Nov 20 '12 at 14:07
@guillem Yes, I saw already. If you add that as an answer I'd accept it. – Bakuriu Nov 20 '12 at 14:08
@Bakuriu: if you do not need sytax highliting you can use \VerbatimInput from package fancyvrb It takes gobble into account – Herbert Nov 21 '12 at 7:05
up vote 3 down vote accepted

According to listings documentation, this is not possible:

Could I use ‘gobble’ together with ‘\lstinputlisting’ ? Yes, but it has no effect.

The minted package, on the other hand, will gobble files that are inserted to a document using


Be warned that, in this case, the minted package will remove the first n characters of each line of the input file, whether these characters are whitespaces or not.

share|improve this answer

package fancyvrb can handle the gobble option


share|improve this answer

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.