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.

Tags: , , , , , ,

Related Posts:

  • Convert PNG to EPS
  • LaTex Annoyances
  • Wordpress Mangler
  • Latex: Numbered Subsubsections
  • Latex: Rotate Inserted Images
  • LaTex: Fixing Wrong Figure Numbers
  • Latex Conditionals
  • Latex: Citations in Figures
  • Homeworks From Hell
  • Installing LaTex on Windows

  • Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <pre lang=""> <em> <i> <strike> <strong>

    [Quote selected]