[Tex/LaTex] How to stop verbatim from converting tabs to spaces

sourcecodeverbatim

I am using verbatim to put some sample code in my document:

\begin{verbatim}  
[start]        printf{"Start command received"};
[stop]         printf{"Stop command received"};
\end{verbatim}

I would like latex to preserve the tabs but instead what I am getting as output is this:

[start] printf{"Start command received"};
[stop] printf{"Stop command received"};

As you can see the tab is converted to a space. Is it not defeating the entire purpose of writing something inside verbatim? Is this normal behaviour for the verbatim environment?

P.S. I am using TexLive 2014 and TexStudio 2.8.8

Best Answer

Use fancyvrb:

\documentclass{article}

\usepackage{fancyvrb}

\begin{document}

Some text to surround the verbatim
\begin{Verbatim}[obeytabs]
[start]         printf{"Start command received"};
[stop]          printf{"Stop command received"};
\end{Verbatim}
Some text to surround the verbatim
\begin{Verbatim}[obeytabs,tabsize=4]
[start]         printf{"Start command received"};
[stop]          printf{"Stop command received"};
\end{Verbatim}
Some text to surround the verbatim

\end{document}

enter image description here

(Note: the real input file has tabs, but StackExchange seems to convert them to spaces.)