I am trying to use the literate option to replace the prompt (>>>) and continuations (...) in python input with symbols that "hang" in the margin. I can almost do this with something like literate=*{>>>}{\llap{$\ggg$\hspace{5pt}}}{0} etc. but am running into a few problems: If I use a length of 0 as above I get errors and, extra space is inserted before the listing creating an undesired indent (though as demonstrated below, I think setting the length to 0 will not help, even if I can prevent the errors).
I would appreciate any suggestions. Here is a minimal example that almost almost works:
\documentclass{article}
\usepackage{MnSymbol}
\usepackage{listings}
\lstset{%
language=python,
columns=flexible,
frame=leftline,
framexleftmargin=0pt,
framesep=4pt,
xleftmargin=5pt,
literate=*{>>>}{\llap{\footnotesize$\ggg$\hspace{8pt}}}{1}
{...}{\llap{$\cdots$\hspace{8pt}}}{1}}
\begin{document}
\noindent
Here is some python code:
\begin{lstlisting}
def f():
"""This is a function."""
return 1
f()
\end{lstlisting}
This uses the doctest format, but has extra indentation:
\begin{lstlisting}
>>> def f():
... """This is a function."""
... return 1
>>> f()
1
\end{lstlisting}
This is even a problem without any output:
\lstset{%
literate=*{>>>}{}{0}
{...}{}{0}}
\begin{lstlisting}
>>> def f():
... """This is a function."""
... return 1
>>> f()
1
\end{lstlisting}
\end{document}
