# How to stop verbatim from converting tabs to spaces?

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

\begin{verbatim}
\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"};


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

• Depends on your point of view: the usual TeX position is that tabs are not a good plan as they are visually the same as spaces. I note that StackExchange agree: your 'literal' text here contains spaces :-) – Joseph Wright Mar 3 '15 at 10:25
• so this means if I have a long code section I have to convert all the tabs to spaces? – Saprativa Bhattacharjee Mar 3 '15 at 10:27
• No: there are fixes, don't worry (hence that being a comment not an answer!) – Joseph Wright Mar 3 '15 at 10:30

Use fancyvrb:

\documentclass{article}

\usepackage{fancyvrb}

\begin{document}

Some text to surround the verbatim
\begin{Verbatim}[obeytabs]
\end{Verbatim}
Some text to surround the verbatim
\begin{Verbatim}[obeytabs,tabsize=4]

• Drat: was just writing much the same but with listings as well :-) – Joseph Wright Mar 3 '15 at 10:33
• @SaprativaBhattacharjee I certainly wouldn't undertake the task. What's wrong in loading very stable packages like fancyvrb? – egreg Mar 3 '15 at 10:40
• @SaprativaBhattacharjee As the standard verbatim environment does not do any parsing of the its content, it would be a major undertaking (relatively) to extend it to deal with the variable length requirement for tabs. The fancyvrb package has already done the work: what's the issue? – Joseph Wright Mar 3 '15 at 11:02
• @SaprativaBhattacharjee -- the standard verbatim environment, as already noted, does not do any parsing. a trivial change, to only recognize a tab and "space over" a fixed distance, could leave the texts that you intend to be aligned, not aligned, since it would be additive. not satisfactory at all. – barbara beeton Mar 3 '15 at 16:01