I want to show the text from a Python Interpreter in a Windows console. This should be plain text (like you see in a command line terminal). I also want to show Python code snippets with highlighting. To do this, I set my default listing style for coloring (\lstset) and then created a custom listing style for command line terminal output (\lstdefinestyle).
When I try to use a framed box to show the terminal output, I find that it tries to fully justify the lines and adds extra spaces between words. How do I globally set all framed boxes to be left justified so I don't have to justify each box? Here is what I did:
\documentclass[openright,12pt]{book}
%Include Packages
\usepackage{hyperref}
\usepackage{float}
\usepackage{longtable}
\usepackage{listings} %code snippets
\usepackage{color}
\usepackage{calc}
\usepackage{amsmath}
\usepackage{framed} %console output displays
\usepackage{graphicx}
\usepackage{tikz}
\pagestyle{headings}
%Syntax Coloring for code snippets
\lstset{
belowcaptionskip=1\baselineskip,
breaklines=true,
frame=l,
xleftmargin=\parindent,
language=Python,
showstringspaces=false,
basicstyle=\footnotesize\ttfamily,
keywordstyle=\bfseries\color{green!40!black},
commentstyle=\itshape\color{mygray},
identifierstyle=\color{blue},
stringstyle=\color{orange},
numbers=left,
numbersep=15pt,
numberstyle=\tiny\color{gray},
}
%Syntax coloring for inline code at the console
\lstdefinestyle{consolePy}{
breaklines=true,
language=Python,
showstringspaces=false,
xleftmargin=0pt,
frame=none,
numbers=none,
identifierstyle=\ttfamily\color{black},
basicstyle=\footnotesize\color{black},
commentstyle=\ttfamily\color{black},
stringstyle=\ttfamily\color{black},
keywordstyle=\ttfamily\color{black}
}
\begin{document}
\begin{framed}
\begin{lstlisting}[style=consolePy]
>>> MyName = “Jason”
>>> print MyName
Jason
>>> MyAge = 30
>>> print 'My name is', MyName, 'and I'm', MyAge, 'years old.'
My name is Jason and I’m 30 years old.
\end{lstlisting}
\end{framed}
\end{document}
I would show a screen capture of the result but I'm new so I can't post images. Just know that the result is my text showing large white spaces in the framed listing. Thank you for any guidance you can provide!
\documentclass{...}and ending with\end{document}. – Marco Daniel Mar 8 at 16:52frameddoesn't influence the justification. – Marco Daniel Mar 8 at 20:25!that's added in front of the link; a user with enough rep will add it back. Does addingcolumns=fullflexibleto your\lstsethelp? – egreg Mar 9 at 11:12