I am writing a book on Python and IPython. I want to insert in this book code listings of Python and IPython.
For the code itself I have no problem customizing listings for my intents.
Including code from IPython is a bit more tricky. I would like to make the In [x]:
and Out [x]:
of IPython in bold. For that I used so far the package fancyvrb
, like that:
\begin{ipython}
\textbf{In [20]:} FirstQ*2
\textbf{Out[20]:} ['Jan', 'Feb', 'Mar', 'Jan', 'Feb', 'Mar']
\textbf{In [21]:} SomeList=[0]*6
\textbf{In [22]:} SomeList
\textbf{Out[22]:} [0, 0, 0, 0, 0, 0]
\end{ipython}
However it's a bit annoying to type the \textbf
everytime for all the In
's and Out
's.
Can some one point a way in which I can define that first X columns in a verbatim environment are made in bold ?
I also tried with listings that:
\lstset{classoffset=0,
morekeywords={In, Out,27},keywordstyle=\textbf,
classoffset=1
}
\begin{lstlisting}
In [27]: x=2
\end{lstlisting}
but only the words In and Out are made in Bold not the number and the brackets …
Maybe I am asking the wrong question also ?
Any insights on that will be welcomed …
Best Answer
Whoof, I found a solution myself - I share it with you guys, since I see many people are giving positive feedback to my question: