# Unindent code inserted with \lstinputlisting

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?

-
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

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

\inputminted[gobble=n,...]{language}{file}


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.

-

package fancyvrb can handle the gobble option

\documentclass{article}
\usepackage{fancyvrb}

\begin{document}
\VerbatimInput[gobble=4]{\jobname.tex}
\end{document}

-