Code Segments in Latex

Whenever I copy and paste some code segments into my Latex documents, the verbatim environment eats my tabs. Apparently it is a feature, so I usually make my text editor convert tabs to n spaces before I import or copy the code into Kile. But that’s annoying as hell!

The other day I found a simple and elegant solution. Use moreverb package. Somewhere at the beginning of the document do:

\usepackage{moreverb}

Then, instead of using normal verbatim environment do:

\begin{verbatimtab}
% code with tabs
\end{verbatimtab}

Easy as pie! The only downside – Kile does not consider verbatimtab to be a verbatim like environment so it does not highlight the text inside a different color like it does for standard verbatim blocks. But that’s a small price to pay for the added convenience.

This entry was posted in Uncategorized. Bookmark the permalink.



2 Responses to Code Segments in Latex

  1. Daniel Google Chrome Windows says:

    Was looking for exactly this. Thanks!

    Reply  |  Quote
  2. RB GERMANY Opera Windows says:

    Thank you so much! Saved me another hour wasted in figuring this thing out. :D

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *