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.)
fancyvrb
documentation you can BTW find this remark: “using tabs is in fact a rather old-fashioned style of coding”). Infancyvrb
there’s an optiongobble
, with that you can suppress a certain amount of spaces or even tabs (max. 9 chars). Note also the optionsobeytabs
andtabsize
. I am surprised, too, that you didn’t get an error message while compiling your MWE. Normally you should have to definecommandchars
first. – Speravir Mar 21 '12 at 3:27