I'm looking for an environment similar to Verbatim which will allow me to say something like the following code (which uses indentation instead of spaces):
\documentclass{article}
\usepackage{fancyvrb}
\usepackage[margin=1in]{geometry}
\begin{document}
\begin{enumerate}
\item We first set \texttt{x} to infinity if it is positive:
\begin{Verbatim}
if x > 0:
x = \infty
\end{Verbatim}
\end{enumerate}
\end{document}
and get back exactly the following, in terms of the indentation, the escaping of all symbols (like \infty), etc.
The problem with Verbatim is that it requires me to un-indent the body with respect to the rest of the code, which makes my source code ugly. (I also can't use verbatim because it forces me to use spaces.) Furthermore, I can't figure out how to embed special symbols in it, either.
Is there some environment that fixes these problems with a not-too-difficult syntax for inserting special symbols and math into the code? (Ideally, I would want \ and $ to be the escape characters, but anything that isn't too difficult to type will do.)




fancyvrbdocumentation you can BTW find this remark: “using tabs is in fact a rather old-fashioned style of coding”). Infancyvrbthere’s an optiongobble, with that you can suppress a certain amount of spaces or even tabs (max. 9 chars). Note also the optionsobeytabsandtabsize. I am surprised, too, that you didn’t get an error message while compiling your MWE. Normally you should have to definecommandcharsfirst. – Speravir Mar 21 '12 at 03:27